Skip to content

Latest commit

 

History

History
47 lines (39 loc) · 1.22 KB

gdb.md

File metadata and controls

47 lines (39 loc) · 1.22 KB

Debugging with GDB

Compile your program with -g flag and run your program using gdb: gdb yourprogname. From there, you can debug using GDB commands. Use help to list commands and their options.

Break

?inline Set a breakpoint to pause execution at a certain line or a function:

  • break main
  • b 42

Run

?inline Run your program inside gdb after setting breakpoints:

  • run
  • r

Print

?inline Print value of expression:

  • print my_var
  • p (char) ch

Walk & Step

?inline Execute next line of code, where next stays in the function and step enters functions:

  • n
  • s

Continue

?inline Continue execution until (Nth) next breakpoint

  • continue
  • c 3

Backtrace

?inline Print backtrace of all or N stack frames:

  • backtrace -full
  • bt 3

Learn More:

?creditFooter 847492919136354364