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

$2 = {baseElementMember = 3}
Since the object of derived element is passed to the function foo, we can display the complete derived object
by using type casting.
(gdb) p *(DerivedElement*)p
No symbol "DerivedElement" in current context.
This did not work since DerivedElement is a defined in the scope of Manager structure and so is not available
outside.
(gdb) p *(Manager::DerivedElement*)p // Typecasting
$3 = {<Manager::BaseElement> = {baseElementMember = 3},
derivedElementMember = 4}
Displaying class and object information
Classes and objects are the basic building block of C++ language. HP WDB commands, such as
print, ptype, and whatis can be used to get the value and type information of objects.
You can use the print command to display the value of all or individual member elements of an
object. Individual object members can be referenced using the member access operators, period
(.) and right arrow (->). You can display the type of object using the whatis and ptype commands.
The ptype command also displays the type information of a class.
Example 4 shows a sample program for displaying class and object information.
Example 4 Sample Program for Displaying Class and Object Information
1 #include <stdio.h>
2
3 class Manager {
4 static int managerMember;
5 public:
6 struct Employee {
7 int employeeMember;
8 }e;
9 void print(void) {
10 printf("%d\n%d\n", managerMember, e.employeeMember);
11 }
12 };
13
14 typedef Manager * pManager;
15
16 int Manager::managerMember=2;
17
18 int main() {
19 Manager m;
20 pManager pm = &m
21 m.e.employeeMember = 3;
22
23 return 0;
24 }
The WDB output snippet for this program is as shown below:
(gdb) b main
Breakpoint 1 at 0x4000890:2: file classes.C, line 20 from /C++WhitePaper/classes.
(gdb) r
Starting program: /C++WhitePaper/classes
Breakpoint 1, main () at classes.C:20
20 pManager pm = &m
(gdb) n
21 m.e.employeeMember = 3;
(gdb) n
23 return 0;
You can use the print command as shown below:
Displaying class and object information 11