Debugging with GDB (September 2007)
Chapter 14: HP-UX Configuration-Specific Information 137
info corruption
Checks for corruption in the currently allocated heap blocks.
set heap-check min-leak-size num
Collects a stack trace only when the size of the leak exceeds the number of
bytes you specify for this value. Larger values improve run-time performance.
The default value is zero (0) bytes.
set heap-check frame-count num
Controls the depth of the call stack collected. Larger values increase run time.
The default value is four (4) stack frames.
14.10.4.2 Example for interactive debugging session
This example describes checking a program running on HP-UX 11.x using linker version
B.11.19 or later:
1. Link the program with /usr/lib/libc.sl instead of libc.a.
2. Run the debugger and load the program:
> gdb a.out
3. Turn on leak checking:
(gdb) set heap-check leaks on
4. Set one or more breakpoints in the code where you want to examine cumulative leaks:
(gdb) b myfunction
5. Run the program in the debugger:
(gdb) run
6. Use the info command to show list of memory leaks:
(gdb) info leaks
Scanning for memory leaks...done
2439 bytes leaked in 25 blocks
No. Total bytes Blocks Address Function
0 1234 1 0x40419710 foo()
1 333 1 0x40410bf8 main()
2 245 8 0x40410838 strdup()
[...]
The debugger assigns each leak a numeric identifier.
7. To display a stack trace for a specific leak, use the info leak command and spe cify
the numb e r from the list associate d with a leak:
(gdb) info leak 2
245 bytes leaked in 8 blocks (10.05% of all bytes leaked)