Author Topic: Debugging DLL for console app.  (Read 5988 times)

Offline Ariman

  • Single posting newcomer
  • *
  • Posts: 3
Debugging DLL for console app.
« on: January 23, 2009, 10:35:49 am »
I'm trying to debug a plugin for third-party console application. Plugin is written as a DLL. When I start debugger host process is created (I can see new process in process list) but there is no console window appears.
Codeblocks version: svn 5382 (nightly build)
OS: Windows
Compiler: mingw (gcc 3.4.5) + gdb 6.8
Should I make some additional adjustment in settings or my library or debugger options to actually make console appear?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Debugging DLL for console app.
« Reply #1 on: January 23, 2009, 10:49:36 am »
I'm sure the way below works, you can have a try.
Debug from the host application :D, then trace into your DLL.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Ariman

  • Single posting newcomer
  • *
  • Posts: 3
Re: Debugging DLL for console app.
« Reply #2 on: January 23, 2009, 11:23:09 am »
I'm sure the way below works, you can have a try.
Debug from the host application :D, then trace into your DLL.
I wish it was so simple. But host app has no debug symbols let alone source code. :(

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Debugging DLL for console app.
« Reply #3 on: January 23, 2009, 01:20:20 pm »
You can download the sample programming from :
http://forums.codeblocks.org/index.php?action=dlattach;topic=4896.0;attach=1707
And set DLL as main target, and set the exe has a host applications. It works fine. :D, see my screenshot below.


[attachment deleted by admin]
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Ariman

  • Single posting newcomer
  • *
  • Posts: 3
Re: Debugging DLL for console app.
« Reply #4 on: January 23, 2009, 02:53:48 pm »
Thanks for the sample. It works fine indeed.  :)

I did some more experiments and found interesting thing. I've found all stuff that should be printed on console in debugger log ("Debugger (debug)" window). Seems that stdout handle of the host app is redirected. But breakpoints in DLL are working properly.
Does anybody know how to change this behavior? I need console to be shown as usual.

I've attached sample projects (one for console app and one for DLL for more clean experiment  :D).

[attachment deleted by admin]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Debugging DLL for console app.
« Reply #5 on: January 23, 2009, 04:04:37 pm »
Yes, I tested it.
You are right, the APP.exe's output was redirect to gdb's log.
Sorry, I can't help you to solve the problem. :(

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.