Debugging Dynamic Memory Usage Errors Using NonStop Native Inspect White Paper

NOTE: Alternatively, you can use the set heap-check on command to automatically
enable the detection of leaks by toggling the set heap-check leaks on command. This
command enables the detection of leaks, heap profiles, bounds checking, and checking for
double frees.
3. Set breakpoints in the code at probe-points where you want to examine cumulative leaks by
entering the following command:
(eInspect 0,105): b <probe-points>
4. Continue the program in the debugger by entering the following command:
(eInspect 0,105): c
5. When the breakpoint triggers, enter the following info leaks command to display the list of
memory leaks:
(eInspect 0,105): info leaks
The following output is displayed:
Scanning for memory leaks...done
2439 bytes leaked in 25 blocks
No. Total bytes Blocks Address Function
0 1234 1 0x08434ac0 func1()
1 333 1 0x08434cb0 main()
2 245 8 0x08434da0 strdup()
[...]
The debugger assigns a numeric identifier for each leak. To view a stack trace for a specific
leak, specify the leak number from the list of leaks, as follows:
(eInspect 0,105): info leak 2
245 bytes leaked in 8 blocks (10.05% of all bytes leaked)
These range in size from 26 to 36 bytes and are allocated in strdup ()
in link_the_list () at testc:55
in main () at testc:13
in _MAIN ()
Event Monitoring
The event monitoring commands in Native Inspect enable you to monitor specific heap events and
heap-corruption problems in an application.
Monitoring Heap Events
Native Inspect enables you to monitor specific events such as the size of memory allocations.
Table 4 Monitoring Heap Events
Column HeadCommand
Suspends program execution when a program tries to
allocate a block larger than num-bytes in size.
set heap-check block-size <num-bytes>
Suspends program execution when the program tries to
increase the program-heap by at least num-bytes.
set heap-check heap-size <num-bytes>
Toggles the detection of double-frees and frees with
improper arguments.
set heap-check free <on/off>
Monitoring Allocations Greater Than a Specified size
The set heap-check block-size command instructs Native Inspect to stop the program and
transfer the execution control to the user when the program allocates a heap block whose size is
greater than or equal to <num-bytes>. Following is the syntax for the set heap-check
block-size command:
12