Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most tricky/useful commands for gdb debugger [closed]

People also ask

What command do you use in gdb to get help?

You can always ask GDB itself for information on its commands, using the command help . With a command name as help argument, GDB displays a short paragraph on how to use that command. If that command has one or more aliases, GDB will display a first line with the command name and all its aliases separated by commas.

Which command in gdb is used to find all breakpoints?

The rbreak command can be used to set breakpoints in all the functions in a program, like this: (gdb) rbreak . Print a table of all breakpoints, watchpoints, and catchpoints set and not deleted, with the following columns for each breakpoint: Breakpoint Numbers.

Can you go backwards in gdb?

If the target environment supports it, gdb can allow you to “rewind” the program by running it backward. A target environment that supports reverse execution should be able to “undo” the changes in machine state that have taken place as the program was executing normally.


  1. backtrace full: Complete backtrace with local variables
  2. up, down, frame: Move through frames
  3. watch: Suspend the process when a certain condition is met
  4. set print pretty on: Prints out prettily formatted C source code
  5. set logging on: Log debugging session to show to others for support
  6. set print array on: Pretty array printing
  7. finish: Continue till end of function
  8. enable and disable: Enable/disable breakpoints
  9. tbreak: Break once, and then remove the breakpoint
  10. where: Line number currently being executed
  11. info locals: View all local variables
  12. info args: View all function arguments
  13. list: view source
  14. rbreak: break on function matching regular expression

Start gdb with a textual user interface

gdb -tui

Starting in gdb 7.0, there is reversible debugging, so your new favourite commands are:

* reverse-continue ('rc') -- Continue program being debugged but run it in reverse
* reverse-finish -- Execute backward until just before the selected stack frame is called
* reverse-next ('rn') -- Step program backward, proceeding through subroutine calls.
* reverse-nexti ('rni') -- Step backward one instruction, but proceed through called subroutines.
* reverse-step ('rs') -- Step program backward until it reaches the beginning of a previous source line
* reverse-stepi -- Step backward exactly one instruction
* set exec-direction (forward/reverse) -- Set direction of execution.

Instead of launching GDB with "-tui" param you can also switch to text mode after a while using by typing "wh".