Debugging C++ Applications Using HP WDB (766162-001, March 2014)
(gdb) q
Example 19 shows a sample program for debugging a function template:
Example 19 Sample Program for Debugging a Function Template
1 #include <iostream>
2 using namespace std;
3
4 template <class T>
5 T GetMax (T a, T b) {
6 T result;
7 result = (a >b)? a : b;
8 return (result);
9 }
10
11 int main () {
12 int i=5, j=6, k;
13 long l=10, m=5, n;
14 k=GetMax<int>(i,j);
15 n=GetMax<long>(l,m);
16 cout << k << endl;
17 cout << n << endl;
18 return 0;
19 }
The WDB output snippet for this program is as shown below:
(gdb) b main
Breakpoint 1 at 0x4001860:1: file function_template.C, line 12 from /C++WhitePaper/templates/function_template.
(gdb) r
Starting program: /C++WhitePaper/templates/function_template
Breakpoint 1, main () at function_template.C:12
12 int i=5, j=6, k;
(gdb) n
13 long l=10, m=5, n;
(gdb) b GetMax
[0] cancel
[1] all
[2] GetMax<int>(int,int) at function_template.C:7
[3] GetMax<long>(long,long) at function_template.C:7
> 0
Cancelled
(gdb) b GetMax<long> // Setting breakpoint
Breakpoint 2 at 0x4001c30:0: file function_template.C, line 7 from /C++WhitePaper/templates/function_template.
(gdb) call GetMax(i, j) // Template function call
$1 = 6
Debugging opaque type
An opaque type is a type declared as a pointer to a struct, class, or union. For example, struct
MyType* that is used in one source file although the full declaration of struct MyType is in
another source file. HP WDB’s behavior for debugging opaque types can be changed using the
following commands:
DescriptionCommand
Enable or disable WDB to resolve opaque types. The default is on.set
opaque-type-resolution
[on | off]
Show current status of opaque types.show
opaque-type-resolution
Debugging opaque type 31