Debugging Dynamic Memory Usage Errors Using HP WDB v6.3 (5900-2181, August 2012)
Contents
Introduction..............................................................................................................................5
Intended Audience....................................................................................................................5
Typographic Conventions...........................................................................................................5
Related Information...................................................................................................................6
Prerequisites.............................................................................................................................6
Memory-Related Errors .............................................................................................................7
Heap Corruption..................................................................................................................7
Causes for Heap Corruption.............................................................................................7
Memory Leaks.....................................................................................................................7
When to Suspect a Memory Leak?....................................................................................7
Types of Memory Leaks....................................................................................................8
Access Errors.......................................................................................................................8
Using WDB to Debug Memory Problems.....................................................................................9
HP aC++/ HP C Compiler Runtime Checking Options..............................................................9
Memory Checking Analysis for User Defined Memory Management Routines............................10
Memory-Debugging Features of WDB.......................................................................................10
Heap Profiling...................................................................................................................10
Snapshot Profile ...........................................................................................................11
Incremental Heap Profile................................................................................................13
Arena Profile................................................................................................................16
Analyzing the info heap process output.......................................................................16
Analyzing the info heap arenas output........................................................................17
Leak Profiling.....................................................................................................................21
Error Injection ...................................................................................................................23
Event Monitoring...............................................................................................................29
Monitoring Heap Events ................................................................................................29
Monitoring a Specific Address...................................................................................29
Monitoring Allocations Greater Than a Specified size....................................................30
Monitoring the Program Heap Growth........................................................................32
Monitoring Changes in Data Segment Space Allocation (High Water Mark Feature) ........33
Monitoring De-allocations to Detect Double-Frees..........................................................36
Monitoring Heap Corruption .........................................................................................36
Monitoring String Corruption......................................................................................37
Detecting Out-of-Bounds Writes with the Bounds-Checking Feature..................................38
Setting the amount of guard bytes for every block of allocated memory...........................41
Detecting Heap Corruption........................................................................................41
Detecting dangling pointer and dangling block ...........................................................43
Scrambling a Heap Block..........................................................................................44
Open-files reporting...........................................................................................................45
Settings to Manage Performance Degradation............................................................................48
Supported Modes of Memory-debugging in WDB......................................................................48
Debugging in the Interactive Mode......................................................................................48
Debugging in Batch Mode..................................................................................................49
Environment Variables for Batch Memory-Debugging ........................................................49
Enabling and Disabling Batch Mode Memory-Debugging .............................................49
Pre-loading the Appropriate Version of librtc.[sl|so] Along With the Application...............50
Overriding the Default Location for librtc.[sl|so]............................................................51
Overriding the Default Path for Searching the GDB Executable.......................................51
Enabling the Processing of the .gdbinit File..................................................................51
Configuration File for Batch Mode Debugging..................................................................52
Location of the Configuration File for Batch Mode Debugging........................................52
Supported Variables for Memory-Debugging in the Batch Mode Configuration File...........52
Contents 3