Debugging a Program With dbx

Printing C++

In C++ an object pointer has two types, its static type, what is defined in the source code, and its dynamic type. dbx can sometimes provide you with the information about the dynamic type of an object.

In general, when an object has a virtual function table, a vtable, in it, dbx can use the information in the vtable to correctly figure out what an object's type is.

You can use the commands print or display with the --r (recursive) option. dbx displays all the data members directly defined by a class and those inherited from a base class.

These commands also take a -d or +d option that toggles the default behavior of the dbxenv output_derived_type.

Using the --d flag or setting the dbxenv output_dynamic_type to on when there is no process running generates a "program is not active" error message because it is not possible to access dynamic information when there is no process. An "illegal cast on class pointers" error message is generated if you try to find a dynamic type through a virtual inheritance (casting from a virtual baseclass to a derived class is not legal in C++).

Evaluating Unnamed Arguments in C++ Programs

C++ allows you to define functions with unnamed arguments. For example:


void tester(int)
{
};
main(int, char **)
{
   tester(1);
};

Though you cannot use unnamed arguments elsewhere in a program, dbx encodes unnamed arguments in a form that allows you to evaluate them. The form is:


_ARG_%n_

where dbx assigns an integer to %n.

To obtain an assigned argument name from dbx, issue the whatis command with the function name as its target:


(dbx) whatis tester
void tester(int _ARG_0_);
(dbx) whatis main
int main(int _ARG_1_, char **_ARG_2_);

To evaluate (or display) an unnamed function argument,


(dbx) print _ARG_1_
_ARG_1_ = 4