Debugging a Program With dbx

Command Reference

You can invoke any of these exception handling commands when debugging a program.

Commands for C++ Templates

Use these commands on templates and template instantiations. Once you know the class or type definitions, you can print values, display source listings, or set breakpoints.

whereis name

Use whereis to print a list of all occurrences of function or class instantiations for a function or class template.

For a class template:


(dbx) whereis Array
class template instance: a.out`Array<int>
class template instance: a.out`Array<double>
class template:	a.out`template_doc_2.cc`Array

For a function template:


(dbx) whereis square
function template instance: a.out`square(double, double*)
function template instance: a.out`square(int, int*)
function template: a.out`square

whatis name

Use whatis to print the definitions of function and class templates and instantiated functions and classes

For a class template:


(dbx) whatis Array
template<class T> class Array
To get the full template declaration, try `whatis -t Array<int>';

For a function template:


(dbx) whatis square
More than one identifier `square'.
Select one of the following names:
 0) Cancel
 1) function template instance: `square(int, int*)
 2) function template instance: `square(double, double*)
 3) `a.out`square
> 3
template<class C> void square(C num, C *result);

For a class template instantiation:


(dbx) whatis -t Array<double> 
class Array<double>; {
public:
    int Array<double>::getlength()
    double &Array<double>::operator [](int i); 
    Array<double>::Array<double>(int l); 
    Array<double>::~Array<double>();
private:
    int length; 
    double *array;
};

For a function template instantiation:


(dbx) whatis square(int, int*)void square(int num, int *result);

stop inclass classname

To stop in all member functions of a template class:


(dbx)stop inclass Array
(2) stop inclass Array

Use stop inclass to set breakpoints at all member functions of a particular template class:


(dbx) stop inclass Array<int>
(2) stop inclass Array<int>

stop infunction name

Use stop infunction to set breakpoints at all instances of the specified function template:


(dbx) stop infunction square
(9) stop infunction square

stop in function

Use stop in to set a breakpoint at a member function of a template class or at a template function.

For a class template instantiation:


(dbx) stop in Array<int>::Array<int>(int l)
(2) stop in Array<int>::Array<int>(int)

For a function instantiation:


(dbx) stop in square(double, double*)
(6) stop in square(double, double*)

call function_name (parameters)

Use call to explicitly call a function instantiation or a member function of a class template, provided you are stopped in scope. If dbx is unable to choose the correct instance, a menu allows you to choose the correct instance.


(dbx) call square(j,&i)

print Expressions

Use print to evaluate a function instantiation or a member function of a class template:


(dbx) print iarray.getlength()
iarray.getlength() = 5

Use print to evaluate the this pointer:


(dbx) whatis this
class Array<int> *this;
(dbx) print *this
*this = { 
    length = 5 
    array   = 0x21608
}

list Expressions

Use list to print the source listing for the specified function instantiation:


(dbx) list square(int, int*)