Oracle® Solaris Studio 12.4: Debugging a Program With dbx

Exit Print View

Updated: January 2015
 
 

Setting Multiple Breakpoints in C++ Programs

You can 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 the keywords, 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 class-specific variants of a particular member function (same member function name, different classes), use stop inmember.

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

(dbx) stop inmember draw

For more information about specifying an inmember or inmethod event, see inmember Event Specification.

Setting Breakpoints in All Member Functions of a Class

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

By default, breakpoints are inserted only in the class member functions defined in the class, not those that it might inherit from its base classes. To insert breakpoints in the functions inherited from the base classes also, specify the -recurse option.

The following command sets a breakpoint in all member functions defined in the class shape:

(dbx) stop inclass shape

The following command sets a breakpoint in all member functions defined in the class, and also in functions inherited from the class:

(dbx) stop inclass shape -recurse

For more information on specifying an inclass event, see inclass Event Specification and stop Command.

Due to the large number of breakpoints that might be inserted by stop inclass and other breakpoint selections, be sure to set the dbxenv variable step_events to on to speed up the step and next commands. For more information,see Efficiency Considerations.

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.

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

(dbx) stop infunction sort 

For more information on specifying an infunction event, see infunction Event Specification.

Setting Breakpoints in Objects

Set an in-object breakpoint to check the operations applied to a specific object instance.

Use in-object breakpoints to stop program execution when any method is called on a specific object instance. For example, the following code will only cause a stop when f1->printit() is called:

Foo *f1 = new Foo();
Foo *f2 = new Foo();
 f1->printit();
 f2->printit();

(dbx) stop inobject f1

The address stored in f1 identifies the objects you put a breakpoint on. This implies that this breakpoint can only be created after the object in f1 has been instantiated.

By default, an in-object breakpoint suspends program execution in all nonstatic member functions of the object’s class, including inherited ones. To restrict breakpoints only to the objects class, specify the -norecurse option.

To set a breakpoint in all nonstatic member functions defined in the base class of object foo and in all nonstatic member functions defined in inherited classes of object foo:

(dbx) stop inobject &foo

To set a breakpoint in all nonstatic member functions defined in the class of object foo, but not those defined in inherited classes of object foo:

(dbx) stop inobject &foo -norecurse

For more information on specifying an inobject event, see inobject Event Specification and stop Command