GNU Debugger (GDB)

GDB allows you to see what is going on ‘inside’ another program while it executes.

Useful for debugging in C and C++.

Make sure to compile with -g flag.

How to Use

At least at Blackberry QNX, I’ve used it to debug Open Source Projects.

You download from the software centre. Thentodo

Commands

  • next: runs one line of the program n
  • print variable: allows you to see value of that variable at that time p
  • display var: prints the value of var after each next/step
  • continue: runs the program until the next breakpoint c
  • refresh: fix the layout src display
  • breakpoints

More Commands

  • watch var: breaks the program whenever var is changed
  • step: runs one instruction of the program
  • list: show surrounding lines of the program
  • backtrace: lists the sequence of function calls that got you to your current location
  • up/down: change the function in the call stack we are observing so as to inspect other variables
  • set var: allows us to set a variable at runtime
  • undipslay 1 : stops displaying first var set with display
  • delete breakpoint number: rename break point from use (watch and break)