Debugging Core Files Using HP WDB
Example 7 Debugging a Core File to View Information on a Global Variable in a C program
In this example, the address, &global_vars, of global_vars is required for debugging. If
the required structure is a pointer, the address of the structure is not required. The address of
the structure is cast to (char*) so that any increments to this address will be 1 byte.
The program in this example uses the global structure, global_vars.
Following is the global structure, global_vars:
struct gvals {
char *program; +0x0
int arg_count; +0x4
char *first_arg; +0x8
char *path; +0xC
int secret; +0x10
};
struct gvals global_vars;
Sample Debugging Session
1. To store the address of global_vars in the convenience variable, $glob, enter the following
command at the gdb prompt:
(gdb) set $glob= (char*)&global_vars
2. To display the string value pointed to by $glob+0x0, enter the following command at
the gdb prompt:
(gdb) x /s *($glob+0x4)
0x7f7e6000: "./example1"
3. To display the int value at $glob+0x4, enter the following command at the gdb prompt:
(gdb) x/x $glob+0x1
0x40001184 <global_vars+4>: 0x00000001
4. To display the string value pointed to by $glob+0x8, enter the following command at
the gdb prompt:
(gdb) x/s *($glob+0x8)
0x0: Error accessing memory address 0x0: Invalid argument.
This indicates that the variable is a null pointer.
5. To display the string value pointed to by $glob+0xC, enter the following command at the
gdb prompt:
(gdb) x/s *($glob+0xC)
0x7f7e62f9: "/opt/softbench/bin:/usr/bin:/opt/user/bin:
/opt/ansic/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/net/bin:
/opt/fc/bin:/opt/fcms/bin:/opt/upgrade/bin:/opt/pd/bin:/usr/bin/X11:
/usr/contrib/bin/X11:/o"...
6. To display the int value at $glob+0x10 in hexadecimal format, enter the following
command at the gdb prompt:
gdb) x/x $glob+0x10
0x40001190 <global_vars+16>: 0x0001b669
7. To display the int value at $glob+0x10 in decimal format, enter the following command:
((gdb) x/d $glob+0x10
0x40001190 <global_vars+16>: 112233
Examples Illustrating Core File Debugging 39