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

Example 18 Sample Program for Debugging Template Member Function
1 #include<stdio.h>
2
3 class A {
4 public:
5 int i;
6 };
7
8 typedef class A clsA;
9
10 template <class T>
11 class B {
12 public:
13 int j;
14 void funB(T) {
15 printf("generic");
16 return;
17 }
18 };
19
20 template <>
21 class B <clsA> {
22 public:
23 int j;
24 void funB(clsA data) {
25 j=data.i;
26 }
27 };
28
29 int main() {
30 clsA objA;
31 class B<clsA> objB;
32
33 objA.i = 10;
34 objB.funB(objA);
35 printf("objB.j = %d",objB.j);
36 return(0);
37 }
The WDB output snippet for this program is as shown below:
(gdb) b main
Breakpoint 1 at 0x40009e0:1: file template_typedef.C, line 32 from /C++WhitePaper/templates/template_typedef.
(gdb) r
Starting program: /C++WhitePaper/templates/template_typedef
Breakpoint 1, main () at template_typedef.C:32
32 objA.i = 10;
(gdb) n
33 objB.funB(objA);
(gdb) b B<clsA>::funB // Setting breakpoint
Breakpoint 2 at 0x4000b40:1: file template_typedef.C, line 24 from /C++WhitePaper/templates/template_typedef.
(gdb) c
Continuing.
Breakpoint 2, B<A>::funB (this=0x7fffefb4, data={i = 10})
at template_typedef.C:24
24 j=data.i;
(gdb) p data.i
$1 = 10
(gdb) ptype B
type = class B<clsA> {
public:
int j;
void funB(A);
}
30