Debugging C++ Applications Using HP WDB (766162-001, March 2014)

1 breakpoint keep y 0x0000000004001ae1 in main at exception.C:17
breakpoint already hit 1 time
2 catch throw keep y exception throw
catchpoint already hit 1 time
3 catch catch keep y exception catch
(gdb) c
Continuing.
Catchpoint 2 (exception thrown), throw location exception.C:11, catch location exception.C:19
0x200000007b3c3760:0 in _Unwind_RaiseExceptionHook(unsigned long long,unsigned long long,unsigned long long)+0
() from /usr/lib/hpux32/libunwind.so.1
(gdb) bt
#0 0x200000007b3c3760:0 in _Unwind_RaiseExceptionHook(unsigned long long,unsigned long long,unsigned long
long)+0 () from /usr/lib/hpux32/libunwind.so.1
#1 0x200000007b3bf980:0 in _Unwind_RaiseException+0x4c0 ()
from /usr/lib/hpux32/libunwind.so.1
#2 0x200000007b58c360:0 in __cxa_throw+0x120 ()
from /usr/lib/hpux32/libCsup.so.1
#3 0x40019d0:2 in inline E::E(char const*) ()
#4 0x4001970:0 in g () at exception.C:11
#5 0x4001b00:0 in main () at exception.C:17
(gdb) frame 4
#4 0x4001970:0 in g () at exception.C:11
11 throw E("Exception thrown in g()");
(gdb) l
6 const char* error;
7 E(const char* arg) : error(arg) { }
8 };
9
10 void g() {
11 throw E("Exception thrown in g()");
12 }
13
14 int main() {
15
(gdb) c
Continuing.
Catchpoint 3 (exception caught), throw location exception.C:11, catch location exception.C:19
0x200000007b58a320:0 in __cxa_begin_catch+0 ()
from /usr/lib/hpux32/libCsup.so.1
In this WDB command line output, WDB stops the execution of the program while it is in the some
library function call. To reach the exact problem that caused the exception, you can use the
backtrace command to display the function call stack. Then, select the user program function
frame using frame command. You may then analyze the local variables and arguments.
The tcatch command instead of catch can be used to set a temporary catchpoint that is enabled
only for one stop. Unlike the catch command the catchpoint set by tcatch automatically gets
deleted after the event (catch or throw) is caught for the first time.
Use the info breakpoints command to list the current catchpoints.
Following are some of the limitations for C++ exception handling (catch throw and catch catch)
in WDB:
If you call a function interactively, WDB normally returns control to you when the function has
finished executing. If the call raises an exception, however, the call may bypass the mechanism
that returns control to you and cause your program either to abort or to simply continue running
until it hits a breakpoint, catches a signal that WDB is listening for, or exits. This happens
even if you set a catchpoint for the exception; catchpoints on exceptions are disabled within
interactive calls.
You cannot raise an exception interactively.
Debugging C++ templates
Template in C++ is described as a set of related classes or functions in which a list of parameters
in the declaration describes how the members of the set vary. The compiler generates new classes
or functions when you supply arguments for these parameters; this process is called template
instantiation. HP WDB 5.0 and later versions allow you to set breakpoints on all instantiations of
the template class by specifying the template class name along with the member function name.
Setting a breakpoint on a template method with multiple instantiations displays a menu showing
all instantiations and you can choose to set breakpoints on all or any one or none.
Example 17 shows a sample program for debugging a template class.
28