Author Topic: use C::B to debug gdb under Windows  (Read 5393 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
use C::B to debug gdb under Windows
« on: December 02, 2011, 03:14:19 pm »
It is convient to use C::B to debug the gdb (I'm using WinXP)
Debugging gdb under C::B is much better than debugging gdb under command line.
See the screen shot below:

You can set breakpoint in gdb's source, step, and see the call stacks.

Here is the way I use:

First, you should have MSYS+mingw, and you have build gdb with -g, suppose that the build gdb was located in:
F:\build_gdb\gdb\gdbgit\buildNo\gdb\gdb.exe
This is the debugee.

Second, you open the C::B, and create a simple console project, than you have to change the setting.

I set the output file name to "a.exe", when you build the console project, a.exe will be put near your cbp file, this is the working directory, so the debugee gdb can find it. then you select the build target to "Debug", and build this "a.exe".

Third, I duplicate a new target named "debuggdb", and set the output file name as:
F:\build_gdb\gdb\gdbgit\buildNo\gdb\gdb.exe


Forth, check off this option in c::b's debugger setting dialog, so that debugee gdb will not be overwrited by the "debugggdb" target, when you start debugging.


Fifth, Select the build target to "debuggdb", and click on the "start debugging" button. Note, please don't click the "build" button, otherwise, the debugee gdb will be overwritten.


Now, the debugee gdb started, you can do every thing you want, the simple thing is you just enter:

Code
file a.exe

This will let the debugee load the "a.exe",

then you enter:

Code
r

Now, you "a.exe" is started under debugee gdb.

Have fun.

The advantage is:
1, if you debug gdb under windows cmd shell, you have both the log of "debugger gdb" and "debugee gdb" mixed in the same window, it was annoying. Using c::b can separate them.
2, you can easily set a breakpoint in c::b even the "debugee gdb" was running, but under cmd shell, you have no way to set a bp when debugee is running.
3, you can easily switch the call stack frame in C::B by just double click on the "call stack window".
 
« Last Edit: December 02, 2011, 03:18:57 pm by ollydbg »
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: use C::B to debug gdb under Windows
« Reply #1 on: December 02, 2011, 03:21:00 pm »
Why don't you use make file projects, then you can compile gdb, too?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: use C::B to debug gdb under Windows
« Reply #2 on: December 02, 2011, 03:28:16 pm »
Why don't you use make file projects, then you can compile gdb, too?
No, I can't use that, because gdb under windows need to be built from MSYS shell.
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: use C::B to debug gdb under Windows
« Reply #3 on: December 02, 2011, 03:33:32 pm »
BTW:
By some days work, I finally find a work-around patch to avoid the "print uninitiated local variable will crash gdb" problem.
See:
avoid the crash of gdb+pretty printer on initialized local varia
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.