Debugging a Program With dbx

Setting Breakpoints

There are three types of breakpoint action commands:

Setting a stop Breakpoint at a Line of Source Code

You can set a breakpoint at a line number, using the dbx stop at command:


(dbx) stop at filename:
 n

where n is a source code line number and filename is an optional program file name qualifier. For example


(dbx)stop at main.cc:3

:

If the line specified in a stop or when command is not an executable line of source code, dbx sets the breakpoint at the next executable line.

Setting a when Breakpoint at a Line

A when breakpoint command accepts other dbx commands like list, allowing you to write your own version of trace.

(dbx) when at 123 { list $lineno;}

when operates with an implied cont command. In the example above, after listing the source code at the current line, the program continues executing.

Setting a Breakpoint in a Dynamically Linked Library

dbx provides full debugging support for code that makes use of the programmatic interface to the run-time linker; code that calls dlopen(), dlclose() and their associated functions. The run-time linker binds and unbinds shared libraries during program execution. Debugging support for dlopen()/dlclose() allows you to step into a function or set a breakpoint in functions in a dynamically shared library just as you can in a library linked when the program is started.

There are three exceptions:

Setting Multiple Breaks in C++ Programs

You may want to check for problems related to calls to members of different classes, calls to any members of a given class, or calls to overloaded top-level functions. You can use a keyword--inmember, inclass, infunction, or inobject--with a stop, when, or trace command to set multiple breaks in C++ code.

Setting Breakpoints in Member Functions of Different Classes

To set a breakpoint in each of the object-specific variants of a particular member function (same member function name, different classes), use stop inmember.

To set a when breakpoint, use when inmember.

For example, if the function draw is defined in several different classes, then to place a breakpoint in each function :


(dbx) stop inmember draw

Setting Breakpoints in Member Functions of Same Class

To set a breakpoint in all member functions of a specific class, use the stop inclass command.

To set a when breakpoint, use when inclass.

To set a breakpoint in all member functions of the class draw:


(dbx) stop inclass draw

Breakpoints are inserted in only the class member functions defined in the class. It does not include those that it may inherit from base classes.

Due to the large number of breakpoints that may be inserted by stop inclass and other breakpoint selections, you should be sure to set your dbxenv step_events to on to speed up step and next.

Setting Multiple Breakpoints in Nonmember Functions

To set multiple breakpoints in nonmember functions with overloaded names (same name, different type or number of arguments), use the stop infunction command.

To set a when breakpoint, use when infunction.

For example, if a C++ program has defined two versions of a function named sort(), one which passes an int type argument, the other a float, then, to place a breakpoint in both functions:


(dbx) when infunction sort {cmd;}

Setting Breakpoints in Objects

Set an In Object breakpoint to check the operations applied to a specific object. An In Object breakpoint suspends program execution in all nonstatic member functions of the object's class when called from the object.

To set a breakpoint in object foo:


(dbx) stop inobject foo