Debugging Core Files Using HP WDB (5900-1573; WDB 6.2; January 2011)
$ aCC -Ae -o mmap_test -g mmap.c
$ ./mmap_test
p 7aadc000 q 7aadb000 r 7aada000 s 7aad9000 t c1a91000 u c4406000 ABORT instruction (core dumped)
Now, debug the core file with gdb.
$ gdb mmap_test core
…
Core was generated by `mmap_test'.
Program terminated with signal 6, Aborted.
#0 0x60000000c035d750:0 in kill+0x30 () from /usr/lib/hpux32/libc.so.1
(gdb) frame 3
#3 0x4001400:0 in main () at mmap.c:55
55 abort();
(gdb) p p
$2 = 0x200000007aadc000 ""
(gdb) p q
$3 = 0x200000007aadb000 ""
(gdb) p r
$4 = 0x200000007aada000 <Address 0x200000007aada000 out of bounds>(gdb) p s
$5 = 0x200000007aad9000 "#include <stdlib.h>\n#include <stdio.h>\nint main(){\n foo();\n
bar();\n return 0;\n}\nint foo(){\n int * res = malloc(4);\n printf(\"*res %d\\n\", *res);\n
return 1;\n}\nint bar(){\n printf(\"Hel"...
(gdb) p t
$6 = 0x60000000c1a91000 <Address 0x60000000c1a91000 out of bounds>
(gdb) p u
$7 = 0x60000000c4406000 <Address 0x60000000c4406000 out of bounds>
The pointers r, s, t are from mmap-ed regions which are missing in corefile.
(gdb) help mmapfile
Add contents of memory mapped files missing from core dump.
Usage:
mmapfile <FILENAME> <MAP-ADDRESS> <FILE-OFFSET> <LENGTH>
This can be used if the core file does not contain mmap-ed regions from the live run. This can happen
for files mmap-ed with MAP_PRIVATE with RO permissions, or for files mmap-ed with MAP_SHARED. With
this command, the user can access data from the mmap-ed files, which are missing from the core file.
The ``info target'' command displays all the segments from the core file.
Now, add the region supposed to be pointed by "r".
(gdb) p r
$4 = 0x200000007aada000 <Address 0x200000007aada000 out of bounds>
(gdb) mmapfile testfile 0x200000007aada000 0 0xe1
(gdb) p r
$8 = 0x200000007aada000 "#include <stdlib.h>\n#include <stdio.h>\nint main(){\n foo();\n
bar();\n return 0;\n}\nint foo(){\n int * res = malloc(4);\n printf(\"*res %d\\n\", *res);\n
return 1;\n}\nint bar(){\n printf(\"Hel"...
(gdb) i target
...
0x200000007aada000 - 0x200000007aada0e1 is segment24 (Added with mmapfile) ...
Next, add regions pointed to by t and u.
38