GDB
I wrote these notes when debugging my router for my networking course (CSC458)
Yashar Ganjali is a great prof
This was moved over from my notes repo because having it on my blog makes it more searchable
Get GDB to look like an IDE debugger¶
- GDB Text User Interface
- Ctrl-x-a
- or type
tui
How to refresh the display?¶
- ctrl l
Scroll through previous commands?¶
ctrl-p
: backctrl-n
: forwards- not arrow keys anymore!
Ctrl-b
: backCtrl-f
: forward
Python in GDB?¶
- type
python
- and then a new prompt will appear
- type end to end the python
Example of usefulness of Python in GDB?¶
python print (gdb.breakpoints()[0].location) -> cars.c:car_arrive
After a seg fault, what do you do to find more info?¶
bt
- stands for backtrace, looks at the stack trace
Run a command automatically at a given breakpoint¶
- command 1
- run
-
end
-
this will execute run on breakpoint 1
- (could have multiple commands!)
- Enable Reverse debugging ???????? command 2
- breakpoint for main record continue end
- command 3
- the run end
Create a watchpoint¶
- watch
- reverse-continue
Print all the local variable info¶
info locals
2 ways to add arguments to an executable¶
Option 1¶
- the args have to go in front of everything
Option 2¶
How to temporarily remove your breakpoints?¶
disable
How to print a char array as a string?¶
instead of print char_arr x/s char_arr
Last update:
2023-04-24