Debugging C++ Applications Using HP WDB (766162-001, March 2014)
NOTE: A change in the setting of this subcommand will not take effect until the next time symbols
for a file are loaded.
Example 20 shows a sample program for debugging opaque type.
Example 20 Sample Program for Debugging Opaque Type
1. C:
1 typedef class Manager * pManager;
2 void func(pManager);
3 int main() {
4 pManager pm ;
5 func(pm);
6 return 0;
7 }
2. C:
1 #include <stdio.h>
2
3 class Manager {
4 static int managerMember;
5 public:
6 void print(void) {
7 printf("%d\n", managerMember);
8 }
9 };
10
11 int Manager::managerMember = 10;
12 void func(class Manager * pm) {
13 pm->print();
14 }
The WDB output snippet for this program is as shown below:
(gdb) show opaque-type-resolution
Resolution of opaque struct/class/union types (if set before loading symbols) is on.
(gdb) ptype pm
type = class Manager {
private:
static int managerMember;
public:
void print();
} *
...
(gdb) set opaque-type-resolution off
(gdb) ptype pm
type = class Manager {
<no data fields>
Debugging anonymous unions
In C++, you have the option to declare anonymous unions. When you declare a union without
any name, the union will be anonymous and you can access its members directly by their member
names. HP WDB enables you to debug C++ programs containing anonymous unions. You can
use print command to get or set the value of union members. Also commands, such as ptype,
and whatis provides you the type information.
Example 21 shows a sample program for debugging anonymous unions.
32