New York University Faculty of Arts and Science College of Arts and Science Graduate School of Arts and Science

Computing Resources

gdb (version 6.2.1)

The purpose of a debugger such as GDB is to allow you to see what is going on ``inside'' another program while it executes-or what another program was doing at the moment it crashed.

GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:

o Start your program, specifying anything that might affect its behavior.

o Make your program stop on specified conditions.

o Examine what has happened, when your program has stopped.

o Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.

You can use GDB to debug programs written in C, C++, and Modula-2. Fortran support will be added when a GNU Fortran compiler is ready.

GDB is invoked with the shell command gdb. Once started, it reads commands from the terminal until you tell it to exit with the GDB command quit. You can get online help from gdb itself by using the command help.

You can run gdb with no arguments or options; but the most usual way to start GDB is with one argument or two, specify- ing an executable program as the argument:

gdb program

You can also start with both an executable program and a core file specified:

gdb program core

You can, instead, specify a process ID as a second argument, if you want to debug a running process:

gdb program 1234

would attach GDB to process 1234 (unless you also have a file named `1234'; GDB does check for a core file first).

Docs

Related