Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)
NOTE: To preload from a path that is different from the default paths, you must use the
LD_PRELOAD environment variable.
• Instead of automatically preloading librtc and mapping the shared libraries, you can
explicitly preload the required librtc library.
Set the environment variable, LD_PRELOAD as follows:
◦ For 32-bit applications running on Itanium,
LD_PRELOAD=/opt/langtools/lib/hpux32/librtc.so <executable> <arguments>
◦ For 64-bit applications running on Itanium,
LD_PRELOAD=/opt/langtools/lib/hpux64/librtc.so <executable> <arguments>
◦ For 32-bit applications running on PA-RISC,
LD_PRELOAD=/opt/langtools/lib/librtc.sl <executable> <arguments>
◦ For 64-bit applications running on PA-RISC,
LD_PRELOAD=/opt/langtools/lib/pa20_64/librtc.sl <executable> <arguments>
If LD_PRELOAD and chatr +rtc are used to preload the librtc.[sl|so] runtime
library, librtc[sl|so] is loaded from the path specified by LD_PRELOAD.
3. Identify the required process (using the ps command) and attach the debugger to the process
as follows.
gdb <executable-name> <process-id>
On Itanium, from HP WDB 6.4 version onwards, when a process is attached, all the rtc settings
in the process, if any, get updated to gdb and you can continue debugging the memory
without needing to do the heap checking settings again. However, if there is any heap check
settings done in gdb before/after attach, that is, through -leaks command line option or .gdbinit
or gdb prompt, the gdb settings override the process rtc settings. The latest settings in gdb get
synced up in the process rtc as well.
Use '-leaks' command line option when invoking gdb or set heap-check commands at gdb
prompt (before attaching to gdb) for older versions of HP WDB on Itanium and PA-RISC to
enable heap checking on attach.
4. Insert breakpoints at suitable probe-points. When the breakpoints trigger, use the info heap
and info leaks commands to display the heap and leak profile.
NOTE: To attach and find leaks for PA-32 applications from the startup, the environment variable
RTC_INIT must be set to on in addition to preloading the librtc.[sl|so] library before
starting the application, as follows:
$ LD_PRELOAD=/opt/langtools/lib/librtc.sl RTC_INIT=on <executable>
If RTC_INIT is enabled, librtc.[sl|so] starts recording heap information for PA32 process
by default. Hence, you must set this environment variable only when it is required. You must not
export the RTC_INIT environment variable for shell.
Debugging in RTC-API Mode
On HP Integrity systems, from WDB 6.4 onwards, HP WDB provides a list of memory debugging
APIs, which can be invoked within a HP C/C++ user application to obtain a report on memory
issues at the point of the API invocation. The report provides you the detail of the leaks, allocated
and the corrupted heap blocks, along with the corresponding stack traces in the application. These
APIs also allow you to query rtc running status and to enable or disable certain checks on the fly.
62