Alex Rivera | Logout

How do you use gdb?

Asked 2009-06-08T19:09:54.010
19

I decided to find out how our C/C+ *nix practitioners use the gdb debugger.

Here is what I typically use:

  1. b - break filename.c:line #, function, filename.cpp:function, className::Member
  2. n, c, s -- next continue step
  3. gdb program name => set breakpoints ==> run [parameter list] (I do this to set break points before the program starts)
  4. l - to list the surrounding source code.
  5. attach processID 6 break [location]
  6. gdb programName corefile.core (to examine why app crashed)
  7. I also sometimes set breakpoint at exit function (break exit) to examine program stacks
  8. info b to examine all the breakpoints
  9. clear [breakpoints list ]

How do you use it?

Edit
Report

1 Answer

11

Scripting is a nice GDB feature.

  1. First you set a breakpoint, like: b someFunction\n.
  2. Then you run command: commands\n. GDB will ask for commands for that breakpoint.
  3. Common scenario is to print some value and then continue, so you will enter: p someVar\n continue\n.
  4. To end the script press: Ctrl-D

After running program you will see your script executed occasionally when the breakpoint occurs.

answered 2009-06-08T20:28:06.317

Your Answer