Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a DLL project using QtCreator?

I have written a non-Qt C DLL compiled with mingw using the QtCreator IDE.

When I inject the DLL into a process, the DLL causes that process to crash at a certain line of code. I found this line to be the culprit through the use of OutputDebugString. I know how to fix the line and the DLL works when that line is modified. However, for the purpose of learning how to use a debugger, I have left the line broken and unmodified.

How would I use the QtCreator debugger to find that same exact line is causing the problem? When QtCreator is set to compile in debug mode, pressing F5 results in the following dialog because there is no EXE:

enter image description here

like image 727
user2924308 Avatar asked Oct 27 '13 17:10

user2924308


People also ask

How do I debug a DLL project?

Debug from the DLL project Set breakpoints in the DLL project. Right-click the DLL project and choose Set as Startup Project. Make sure the Solutions Configuration field is set to Debug. Press F5, click the green Start arrow, or select Debug > Start Debugging.

How do I create a DLL in Qt?

Creating dll seems an easy task in Qt. In Qt creator, click File/New File or Project/Projects/Library/C++ Library, then simply choose a name, you will create a dll project. Click “build”, you will see the . dll generated in the debug or release directory.


1 Answers

The solution is to run the debugger attached to the executable before injecting the DLL. The DLL must be built in debug configuration and its project needs to be opened. Attach the debugger using instructions here and inject the DLL. If executable crashes you should see the stack trace and your DLL code when you click on selected stack frame. But be careful: if you corrupted the memory of the process the stack trace might be incomplete or incorrect.

like image 54
Nazar554 Avatar answered Oct 17 '22 06:10

Nazar554