Progmar Marcin Załęczny


Linux gdb debugger useful commands

To have debuggable application you have to compile it with option -g.

Load application into debugger: gdb application

Run application from the beginning: (gdb) run

Continue running application after it has stopped on the breakpoint: (gdb) continue

Display call paths. Each one displays argument values: (gdb) backtrace , or (gdb) where

Display value at specified address: (gdb) x 0x7fffffffe204

Set breakpoint at specified line number in file file.c: (gdb) break file.c:8

Set breakpoint at entrance to specified function: (gdb) break LinkedList<int>::remove

Set conditional clause for specified breakpoint: (gdb) condition 1 item_to_remove==1

Set conditional breakpoint: (gdb) break file.c:8 if i >= ARRAYSIZE

Delete specified breakpoint: (gdb) delete breakpoint_number

Displays information about all breakpoints: (gdb) info breakpoints

Step into through the code: (gdb) step

Step over through the code: (gdb) next

Execute last command: (gdb) [ENTER]

Run the program until function return: (gdb) finish

Display variable value: (gdb) print my_var

Display variable value in hexadecimal format: (gdb) print/x my_var

Display object attribute value: (gdb) print object->field_name , lub (gdb) print (*object).field_name

Display entire object value: (gdb) print *object

Display iterational value of the list: (gdb) print list->next->next->next->data

Set watchpoint on the variable (program will stop at the instruction causing variable change): (gdb) watch my_var

Display 10 lines of code around the current instruction: (gdb) list

Quit the debugger: (gdb) quit

Print all functions that contain word myfunction in their names: info function myfunction

Create watch point which stops execution of the code after it attempts to modify specified variable: watch variable The watch point will not stop if the variable was updated with the same value (the value it already held).

Create watch point which stops execution of the code after it attempts to modify specified variable if the variable had value of 12: watch variable if variable == 12

Display watch points list: info watchpoints

Display break points list: info breakpoints

Display local variables in current stack frame: info locals

Display information about current threads being run: info threads

Set break point on function myfunction for thread of specified ID. In example below code execution stops when threrad of ID=3 will call the function: break myfunction thread 3

Causes that during stepping through the code all other threads will not be executed. Otherwise some other thread could reach the breakpoint and make the debugger to switch to it: set scheduler-lock on

Displays information about type of the specified symbol: whatis symbol

Disassembles ten following instructions starting at main function address: x/10i main