Not logged in. Login

GDB Intro

Videos

Setup

To have the compiler or assembler output an object file with debugging information, add -g to the command line when compiling or assembling:

gcc -g ... somecode.c
as -g ... somecode.S

Then you can start gdbtui with your executable program:

gdbtui ./program

Generally Relevant

  • run: start the execution of the program.
  • break 123: set a breakpoint at line 123 of the source. i.e. if execution hits that line, pause before starting that line of code.
  • next: execute to the next line of code, moving into any function called.
  • step: execute to the next line of code, skipping execution of any function called.
  • cont: continue execution (until the next breakpoint/watchpoint or the end of the program).

Some non-command keypresses:

  • arrows: move around the source code in the upper pane.
  • enter: repeat the last step or next command, moving another line.
  • ctrl-P: scroll up to previous commands.
  • ctrl-L: redraw the screen.

Relevant to C Code

  • print x: print the current contents of the variable x.
  • watch x: "watch" the variable x. i.e. whenever x changes, pause execution and display the old/new value.
  • backtrace: display the current callback stack.
  • finish: execute until the current function returns (then pause).

Relevant to Assembly

  • break foo: set a breakpoint at a label in the source file.
  • print (int)x: print the current contents of the memory location x, treating it as the given type.
  • print $rdi: print a register value. (Note: it's a $ not a %.)
  • watch $rdi: watch a register value. (Note: it's a $ not a %.)
  • info registers rax: print register contents
  • info registers eflags: print status flags
Updated Wed May 15 2024, 12:14 by ggbaker.