The Science of Debugging
Chapter 6


6.2 Starting Gdb


Gdb is fairly simple to start. If we're running it on our CircleMUD, we simply type;

> gdb bin/circle




This loads the program into gdb and gives you a prompt, from which you can access all the commands of gdb. To run the program normally, at the prompt type 'run '. Example:

(gdb) run -q 4000




Which would be the same as typing 'bin/circle -q 4000'

A Warning About Debuggers
IMPORTANT

A debugger often initializes variables when they are defined, usually to NULL or some prefered value. Because of this, a program being debugged may alter it's behavior, causing or fixing errors that result from undefined variables like pointers!

If you're lucky enough to be running a properly configured *nix-variant (Unix, Solaris, HP-UX, Linux, to name a few), your program will provide core dumps when it crashes. You can run gdb off these core dumps - they're like an output of the entire frame stack at the time of the error! To do so, I'd type the following:

> gdb bin/circle lib/core




..from the base directory. By default, CircleMUD changes it's working directory to the lib directory - this is where the core file will be created if your program crashes . If you are having problems generating the core file on a *nix based machine, search the CircleMUD mailing list archives or contact your local administrator for instructions.



Index
6.1 Before You Start Using Gdb. 6.3 Stopping Gdb