Using the gdb debugger

Debuggers are a great thing.  They save you a lot of time when things go wrong.


If you are at the command prompt:  gdb <programname>.  If your program has crashed, and dumped core, gdb core will do it.

But more likely you want to start gdb from within emacs.  If so, make yourself a window, and do Meta-x gdb.  It will ask you for the program name; give it.  Running it from emacs is cool because it shows you where you are in the program at any given time.

To quit, type quit.


Before you run the program (unless you're sure it will crash), you'll need to make it break somewhere, or it will just run and finish.  Here's how

break main  #breaks at the start of main

break myfunc #breaks at the start of myfunc

break    #breaks at current line

Then type run.  If your program uses command-line arguments, type run, followed by those arguments.

Other useful commands