top
products_top_active company_top_inactive right_margin_top
zero_bugs_logo

Prepare Your Program for Debugging


The debugger supports the GNU C/C++ compilers, version 2.95 and up. To enable debugging your programs, the compiler needs to include debugging information in the executables that it builds.

To this end, you can specify one of the following command line options when compiling your programs:

  • -g to generate debug information in the default format
  • -gstabs+ to generate debug information in the extended STABS format. Please note that even though the -gstabs option is also supported, it will generate lesser information than the -gstabs+ options; namely, member function information for C++ classes will not be emitted. For C++ programs, use the -gstabs+ option, or
  • -gdwarf-2 for debug information in the DWARF2 format. This is the default for GCC 3.2 and above, and it is the recommended format for large C++ programs. The DWARF format is superior to STABS. The former allows for accelerated (or indexed) queries, while the latter imposes a linear complexity on accessing symbol and type information.
  • It is highly recommended that you turn off code optimizations (with the gcc -O0 command line flag).

    Note: Although the debugger should theoretically work with any compilers that emit debug information in either the STABS or DWARF format (such as Intel Compiler 8 and above), this is not widely tested.

    There are three ways you can debug a program:

  • attach to a running process
  • execute a process from the debugger
  • load a core file that was dumped to disc when a program crashed

  • Executing Programs

    To execute a program from under the debugger, go to the File menu, then select Execute. The dialog box that pops up lets you select the executable file. If the name of the executable file contains white spaces, make sure to surround the filename with double quotes.

    Note: In text (console) mode, use the exec command.

    By default, the program inherits the current environment, but you can add, remove, or edit the environment variables that are passed to the new process. To do so, in the Execute dialog, press the Environment button.


    Attaching to Running Programs

    To attach to a running process, select File, then Attach. This brings up a dialog that lets you select from a tree of running processes (processes with higher privileges than your account are not shown).


    Loading a Core Dump

    Core files, or core dumps, are produced by the operating system when an application crashes (typically because it has received a signal that was not handled internally). This debugger can load core files so that applications can be debugged "post-mortem".

    Note: Some shells may disable the generation of core dumps by default. To learn more about how to enable core dumps, please consult your shell's manual pages. For example, the Bourne Again Shell command for turning on core dumps is:
    ulimit -c unlimited

    To load a core file, select File, Open, Core File. The dialog that pops up lets you browse through core files and select the one that you wish to look at.


    Notes:
  • When you execute the debugged process from the debugger, when you detach, or quit the debugger, the spawned process and all of its threads will be killed.
  • When you attach to an already running process, detaching will not kill it.
  • When you load a core file, certain functions such as setting a breakpoint are not available (since they require a live process to work).

  • In text mode, you can use the following commands:

  • attach
  • exec
  • loadcore
  • In text mode, type:
    help <command>
    (where <command> is one of the above) for more details.



    Home | Top | Up | Next | Community