Previous | Contents | Index |
You can debug C++ exception handlers in programs by setting breakpoints
in the exception handler or in the predefined C++ functions that are
used when exceptions occur. You can also examine and modify variables
that are used in exception handlers.
8.14.1 Setting Breakpoints in Exception Handlers
As shown in Example 8-30, you can set a breakpoint in an exception handler by setting a breakpoint at the line number where the code for the exception handler begins. You can then step through the exception handler, examine or modify variables, or continue executing the program.
Example 8-30 Setting Breakpoints in Exception Handlers |
---|
(Ladebug) list 24 24 try 25 { 26 foo(); 27 } 28 catch(char * str) { printf("Caught %s.\n",str); } 29 catch(...) { printf("Caught something.\n"); } 30 31 return 0; 32 } (Ladebug) stop at 24 [#1: stop at "except.C":26 ] (Ladebug) stop in unexpected [#2: stop in unexpected ] (Ladebug) run [1] stopped at [int main(void):26 0x400370] 26 foo(); (Ladebug) cont [2] stopped at [unexpected:631 0x4010a8] (Cannot find source file cxx_exc.c) (Ladebug) cont In my_unexpected(). Caught HELP. Thread has finished executing (Ladebug) |
As this example shows, you can also set breakpoints in C++ functions used to handle exceptions as follows:
terminate | Gains control when any unhandled exception occurs |
unexpected | Gains control when a function containing an exception specification tries to throw an exception that is not in the exception specification |
After you set a breakpoint to stop the execution in the exception
handler, you can access the variables used in the exception handler the
same way you would examine and modify other program variables.
8.15 Advanced Program Information: Verbose Mode
By default, the debugger gives no information on virtual base class pointers for the following:
By setting the $verbose debugger variable to 1, you can request that this information be printed in subsequent debugger responses. This section explains the normally suppressed information that the debugger provides if the $verbose debugger variable is set to 1.
When the $verbose debugger variable is set to 1 and you display the contents of a class using the whatis command, several of the class members listed are not in the source code of the original class definition. The following line shows sample output from the whatis command:
array [subrange 0 ... 0 of int] of vtable * _\|_vptr; |
The vtable variable contains the addresses of all virtual functions associated with the class. Several other class members are generated by the compiler for internal use. When the $verbose debugger variable is set to 1, you can see these members and reference them as you would reference any other member function.
The compiler generates additional parameters for nonstatic member functions. When the $verbose debugger variable is set to 1, these extra parameters are displayed as part of each member function's type signature. If you are specifying a version of an overloaded function by entering its type signature and the $verbose variable is set to 1, you must include these parameters. If the $verbose debugger variable is set to 0, you should not include the compiler-generated parameters in the type signature. When the $verbose variable is set to 1, the output of the dump command includes not only standard program variables but also compiler-generated temporary variables.
Example 8-31 prints class information using the whatis command when the $verbose variable is set to 1.
Example 8-31 Printing a Class Description in Verbose Mode |
---|
(Ladebug) print $verbose 0 (Ladebug) whatis S class S { int i; int j; S (void); ~S (void); int foo (void); virtual int bar (void); } S (Ladebug) set $verbose = 1 (Ladebug) print $verbose 1 (Ladebug) whatis S class S { int i; int j; array [subrange 0 ... 0 of int] of vtbl * _\|_vptr; S (S* const); S (S* const, const S&); ~S (S* const, int); int foo (S* const); S& operator = (S* const, const S&); virtual int bar (S* const); } S (Ladebug) |
When displaying information on virtual base classes, the debugger prints pointers to the table describing the base class for each virtual base class object member. This pointer is known as the base pointer bptr. The bptr pointer is printed after the class member information. Example 8-32 shows a print command that displays the bptr pointer information when the $verbose variable is set to 1.
Example 8-32 Printing Base Pointer Information |
---|
(Ladebug) stop at 66 [#1: stop at "c++multinher.C":66 ] (Ladebug) run 0 1 3 [1] stopped at [main(void):66 0x1200010b8] 66 printf("%d\n", dinst.f()); (Ladebug) whatis dinst class D : B, C { D (void); ~D (void); void g (void); } dinst (Ladebug) print dinst class { B = class { V = class { v = 1; x = 3; }; x = 2; ambig = 2; }; C = class { V = class { v = 1; x = 3; }; ambig = 3; }; } (Ladebug) set $verbose = 1 (Ladebug) print dinst class { B = class { V = class { v = 1; x = 3; }; x = 2; ambig = 2; _\|_bptr = 0x10001168; }; C = class { V = class { v = 1; x = 3; }; ambig = 3; _\|_bptr = 0x1000116c; }; _\|_bptr = 0x10001168; } (Ladebug) |
When a class appears on the stack and the $verbose debugger variable is set to 0, the class's members are represented with an ellipsis {...}. When the $verbose debugger variable is set to 1, the debugger prints all members of classes on the stack trace.
Example 8-33 shows that member functions on the stack trace are printed with their this pointer value explicitly when the $verbose variable is set to 1.
Example 8-33 Printing a Stack Trace in Verbose Mode |
---|
(Ladebug) where >0 0x120000789in ((S*)0x10000010)->bar(t={ ... }) c++exv.C:42 #1 0x1200008bc in main() c++exv.C:50 (Ladebug) set $verbose = 1 (Ladebug) where >0 0x120000789c in ((S*)0x10000010)->bar(this=0x10000010, t=class { i = 1; j = 2; _\|_vptr = 0x10000960; virtual T::tbar = (function [0x400290]); }) c++exv.C:42 #1 0x1200008bc in main() c++exv.C:50 (Ladebug) |
Index | Contents |