Debugging Core Files Using HP WDB
Example 5 Debugging Core Files Created by Optimized Code, Stripped Binaries, and Code
Compiled Without the -g Option
Sample Program
1 // a.c
2 // Generates coredump with 3 deep stack trace.
3
4 #include <stdio.h>
5
6 void
7 generate_core_dump ()
8 {
9 int i = 0;
10 *(int*)i = 10;
11 printf ("Generated coredump\n");
12 *(int*)i = 10;
13 }
14
15 void
16 foo (int arg_i)
17 {
18 int local_j;
19 if (arg_i == 10)
20 {
21 local_j = 5;
22 printf ("Hello World! Arg_i is 10 and
local_j is %d\n",local_j);
23 }
24 else
25 {
26 local_j = 10;
27 printf ("Hello World! Arg_i is not 10 and
local_j is %d\n", local_j);
28 }
29 if (local_j == 5)
30 generate_core_dump();
31 printf ("Hello World\n");
32 }
33
34 int main()
35 {
36 int local_i = 10;
37 foo(local_i);
38 return 0;
39 }
Sample Debugging Session 1
Debugging a Core File Created by Optimized Code
$ aCC -g -O a.c
$ /opt/langtools/bin/gdb ./a.out core
HP gdb for HP Itanium (32 or 64 bit) and target HP-UX 11.2x.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for
warranty/support.
..
Core was generated by `a.out'.
Program terminated with signal 11, Segmentation fault.
SEGV_ACCERR - Invalid Permissions for object
#0 inline generate_core_dump () at a.c:11
11 printf ("Generated coredump\n");
(gdb) bt
#0 inline generate_core_dump () at a.c:11
Debugging Core Files Created by Optimized or Stripped Binaries 23