Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)

Table 15 The config_strings Options for RTC_MALLOC_CONFIG (continued)
Descriptionconfig_string Options
RTC_NO_ABORT must not be set.abort_on_nomem=[01]
If abort_on_nomem is set to 1, the batch mode aborts
execution when an out-of-memory condition is detected.
The appropriate logfiles for the heap, leak, and corruption
detection are displayed on stderr. The logfiles are
mem_logfile=stderr[+]filename
heap_logfile=stderr[+]filename
directed to the specified file <filename>. Output is
appended to the file if the + option is used.
leak_logfile=stderr[+]filename
Printing Hexadecimal Address of Functions in Allocating Stack Traces Produced in Batch Mode
Heap or Leak Report
From librtc 6.1 onwards, export the environment variable RTC_PRINT_ADDR to 1 to enable
printing of hexadecimal address of functions in allocating stack traces. By default, the batch mode
heap or leak report does not show the hexadecimal address for allocating stack traces.
An example output without the hexadecimal address for allocating stack traces is as shown below:
20 bytes leaked at 0x40070410 (0.12% of all bytes leaked) #0 allocateMemory() at memLeak.c:11
#1 createHeader() at memLeak.c:24
#2 createString() at memLeak.c:38
#3 compareStrings() at memLeak.c:83
An example output with the hexadecimal address for allocating stack traces, after exporting
RTC_PRINT_ADDR to 1 and running the application in batch mode again to collect the heap or
leak report is as shown below:
20 bytes leaked at 0x40070440 (0.12% of all bytes leaked) #0 0x4000e62 in allocateMemory() at memLeak.c:11
#1 0x4000f62 in createHeader() at memLeak.c:24
#2 0x4001032 in createString() at memLeak.c:38
#3 0x40014a2 in compareStrings() at memLeak.c:83
To enable printing of hexadecimal address in interactive mode, use set print address on
command in the debugger before issuing the info heap or info leak command.
Debugging in Batch Mode
To debug an application in the batch mode, complete the following steps:
1. Compile the source files.
NOTE: On HP 9000 systems, you must map the shared libraries as private, by using the
chatr command if you are using LD_PRELOAD to preload the librtc.[sl|so] instead
of the +rtc <enable|disable> option for the chatr command .
chatr +dbg enable ./<executable>
On HP-UX 11i v3 Integrity systems, WDB enables automatic debugging of shared libraries
without them being mapped private while attaching to a running program. For enabling
automatic debugging of shared libraries, you must install the kernel patches PHKL_38651
and PHKL_38778.
2. Set the required variables in the rtcconfig configuration file, as follows:
$ cat rtcconfig
"rtcconfig" 5 lines, 76 characters
set heap-check on
set heap-check free on
files=executable_name
output_dir= ./
3. Set the required environment variables as follows:
export BATCH_RTC=on
54