Debugging C++ |
17 |
![]() |
This chapter is organized into the following sections:
Using dbx with C++
Although this chapter concentrates on two specific aspects of debugging C++, dbx does allow you full functionality when debugging your C++ programs. You can:
While debugging a program, dbx enables you to:
This example demonstrates how exception handling is done in dbx using a sample program containing exceptions. An exception of type int is thrown in the function bar and is caught in the following catch block.
1 #include <stdio.h> 9 } |
10 }; 12 void bar() { |
The following transcript from the example program shows the exception handling features in dbx.
Debugging With C++ Templates
dbx supports C++ templates. You can load programs containing class and function templates into dbx and invoke any of the dbx commands on a template that you would use on a class or function, such as:
In the following example:
For example, to intercept all types except int, you could enter:
(dbx) intercept -a (dbx) intercept -x int |
The line number, function name, and frame number of the catch clause that would catch typename is displayed.
For a class template:
(dbx) whereis Array |
(dbx) whereis square |
whatis name
Use whatis to print the definitions of function and class templates and instantiated functions and classes
(dbx) whatis Array |
For a class template instantiation:
For a function template instantiation:
(dbx) whatis square(int, int*) |
stop inclass classname
To stop in all member functions of a template class:
(dbx)stop inclass Array |
Use stop inclass to set breakpoints at all member functions of a particular template class:
(dbx) 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 |
stop in function
Use stop in to set a breakpoint at a member function of a template class or at a template function.
(dbx) stop in Array<int>::Array<int>(int l) |
(dbx) stop in square(double, double*) |
call process [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. print Expressions
Use print to evaluate a function instantiation or a member function of a class template:
(dbx) print iarray.getlength() |
Use print to evaluate the this pointer:
(dbx) whatis this |
list expressions
Use list to print the source listing for the specified function instantiation:
(dbx) list square(int, int*) |