Showing posts with label GDB. Show all posts
Showing posts with label GDB. Show all posts

2008/03/06

Using GDB

GDB (project, documentation) is a simple debugging tool for GNU command line systems.

You can Google around for lots of information about it. A short tutorial, a longer tutorial, and a reference card are pretty easy to find.

For GDB to be most effective, you should compile your code with the -g flag to leave debugging symbols in your executable. This will do things like leave variable names and line numbers in the executable so that GDB can show you what/were things are.

The commands that you will use the most are:

help
r arguments (run)
r 5
file executable
bt (backtrace)
p expression (print)
p argv[1]
b file:symbol (breakpoint)
b main.c:5
b main.c:parseArgs
d (delete breakpoints)
s (step) [step-into]
n (next) [step-over]
c (continue)
up
q (quit)