Sun Studio 12 Update 1: Debugging a Program With dbx

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 Command

Use the whereis command 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
member function: `Array<int>::Array(int)
member function: `Array<double>::Array(int)
class template instance: `Array<int>
class template instance: `Array<double>
class template: `a.out``Array

For a function template:

(dbx) whereis square
function template instance: `square<int>(__type_0,__type_0*)
function template instance: `square<double>(__type_0,__type_0*)

The __type_0 parameter refers to the 0th template parameter. A __type_1 would refer to the next template parameter.

For more information, see whereis Command.

whatis name Command

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

For a class template:

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

For the class template’s constructors:

(dbx) whatis Array
More than one identifier ’Array’.
Select one of the following:
 0) Cancel
 1) Array<int>::Array(int)
 2) Array<double>::Array(int>
> 1
Array<int>::Array(int 1);

For a function template:

(dbx) whatis square
More than one identifier ’square’.
Select one of the following:
 0) Cancel
 1) square<int(__type_0,__type_0*)
 2) square<double>(__type_0,__type_0*)
> 2
void square<double>(double num, double *result);

For a class template instantiation:

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

For a function template instantiation:

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

For more information, see whatis Command.

stop inclass classname Command

To stop in all member functions of a template class:

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

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

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

For more information, see stop Command and inclass classname [-recurse | -norecurse].

stop infunction name Command

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

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

For more information, see stop Command and infunction function.

stop in function Command

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

For a member of a class template instantiation:

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

For a function instantiation:

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

For more information, stop Command and in function.

call function_name(parameters) Command

Use the call command to explicitly call a function instantiation or a member function of a class template when you are stopped in scope. If dbx is unable to determine the correct instance, it displays a numbered list of instances from which you can choose.

(dbx) call square(j,&i)

For more information, see call Command.

print Expressions

Use the print command 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

For more information, see print Command.

list Expressions

Use the list command to print the source listing for the specified function instantiation.

(dbx) list square(int, int*)

For more information, see list Command.