Skip to content


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: back
  • ctrl-n: forwards
  • not arrow keys anymore!
  • Ctrl-b: back
  • Ctrl-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

  1. command 1
  2. run
  3. end

  4. this will execute run on breakpoint 1

    • (could have multiple commands!)
  5. Enable Reverse debugging ???????? command 2
  6. breakpoint for main record continue end
  7. command 3
  8. the run end

Create a watchpoint

  • watch
  • reverse-continue

info locals

2 ways to add arguments to an executable

Option 1

gdb --args ./traffic schedule.txt
gdb --args ./executable -arg1 -arg2
  • the args have to go in front of everything

Option 2

gdb ./file
in GDB: run arg1 arg2 ...

How to temporarily remove your breakpoints?


How to print a char array as a string?

instead of print char_arr x/s char_arr

Last update: 2023-04-24