The dbx and gdb Debuggers

One use for dbx or gdb is to analyze a core file from a program that has crashed.

A second use is to trace execution of a program.

The compiler you use determines which debugger you should use. If you use the GNU C compiler (gcc) then you should use the gdb debugger. Generally the dbx debugger is used for all other compilers and most notably the Sun C compiler. (On the AIX machines, only dbx is available, however on Thetis and Valdes gdb is available.)

CORE FILES



USING DBX OR GDB TO ANALYZE A CORE FILE




TRACING PROGRAM EXECUTION WITH DBX



MACHINE-LANGUAGE TRACING

For those who are interested, dbx can display information at the machine instruction level. Here are some examples of the special dbx subcommands.


Using GDB for Debugging

gdb has the same functionality as dbx, however it is more popular since it works for a better compiler (gcc) and its commands are less verbose. For any command you can just enter the start of the command name to remove any ambiguity and the debugger will figure out what you mean. Example p will mean print. Some basic equivalent commands in gdb are:

  • break file:line

    add a breakpoint at a given file and line number.

    break func

    add a breakpoint at the start of function func.

    next

    Execute the next statement. If it is a function call then stop after executing the function.

    step

    Execute the next statement. If it is a function call then enter the function and stop.

    backtrace

    List the program stack. A synonym for this command is bt.

    frame num

    Go to the stack frame number num.

    print var

    Print the value of variable var.

    list

    display current lines of code.

  • For either gdb or dbx you can get additional information by using the command help. This will show all commands available and you can get additional information on a command by running help command.