Most tricky/useful commands for gdb debugger
39,875
Solution 1
- backtrace full: Complete backtrace with local variables
- up, down, frame: Move through frames
- watch: Suspend the process when a certain condition is met
- set print pretty on: Prints out prettily formatted C source code
- set logging on: Log debugging session to show to others for support
- set print array on: Pretty array printing
- finish: Continue till end of function
- enable and disable: Enable/disable breakpoints
- tbreak: Break once, and then remove the breakpoint
- where: Line number currently being executed
- info locals: View all local variables
- info args: View all function arguments
- list: view source
- rbreak: break on function matching regular expression
Solution 2
Start gdb with a textual user interface
gdb -tui
Solution 3
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.
Solution 4
Instead of launching GDB with "-tui" param you can also switch to text mode after a while using by typing "wh".
Solution 5
thread apply all bt
or thread apply all print $pc
: For finding out quickly what all threads are doing.
Comments
-
Vijay almost 2 years
Can you post your most tricky and useful commands while you run a debugger like gdb or dbx.
-
Paul Biggar almost 15 years
info locals
-- View all local variables; list -- view source; rbreak -- break on function matching regular expression. -
DevSolar over 14 yearsI cannot believe this feature escaped me for all these years. Thank you, thank you, thank you!
-
Sudhanshu over 14 yearssource /path/to/macro/file And all of my nifty macros are there to help me debug in seconds.
-
deft_code about 14 yearsHow do you set scheduler locking?
-
Ben about 14 years
set scheduler-locking on
inside gdb -
Kevin over 13 yearsCtrl-a a to switch back to 'normal' command line view !
-
tothphu about 11 yearsThat was the command I was looking for a long-long time! It is really nasty to check all 30 threads one by one!
-
sujin about 10 yearsThanks You saved lot of my time.. Wonderfull....
-
Kiril Kirov almost 10 years
set print object on
for polymorphic elements andset print elements 0
are two commands I use very often. Pretty useful. -
Kiril Kirov almost 10 yearsAlso,
t a a bt
(meaningthread apply all backtrace
). Could be used with (almost) all other commands. Especially useful withbt full
. -
Nathan Fellman almost 10 yearsyou can change the focus to the command window using
focus cmd
so that the up/down arrows work. You switch back usingfocus src
. -
Omry Yadan over 9 yearshow do you make this the default? I tried it .gdbinit but gdb prints /home/omry/.gdbinit:1: Error in sourced command file: Target 'None' cannot support this command.
-
raj_gt1 about 9 years"-' can be used instaed of 'wh'. shorter the better..:)
-
x-yuri over 8 years
-
SullX over 8 yearsAnd another: <minus> RET
-
Patryk about 8 yearsor use cgdb
-
doug65536 about 7 yearsYou can also use the
-iex
option to add individual commands on the gdb command line. -
PraveenMax about 7 yearsvery nice features. Missed this so far...
-
Sam over 6 yearsIt's actually
C-x a
. You can also switch views withC-x 1
andC-x 2
when in tui mode to see assembly as well (if need be). -
user28186 about 2 yearsVery useful information received in this thread , thank you all.
-
user28186 about 2 yearsVery useful reply