Debugging Dynamic Memory Usage Errors Using HP WDB
Table of Contents
Introduction..........................................................................................................................................11
Intended Audience................................................................................................................................11
Typographic Conventions.....................................................................................................................11
Related Information..............................................................................................................................12
Prerequisites..........................................................................................................................................13
Memory-Related Errors .......................................................................................................................13
Heap Corruption.............................................................................................................................13
Causes for Heap Corruption......................................................................................................13
Memory Leaks.................................................................................................................................14
When to Suspect a Memory Leak?.............................................................................................14
Types of Memory Leaks.............................................................................................................14
Access Errors...................................................................................................................................15
Using WDB to Debug Memory Problems............................................................................................15
HP aC++/ HP C Compiler Runtime Checking Options...................................................................15
Memory-Debugging Features of WDB.................................................................................................16
Heap Profiling.................................................................................................................................16
Snapshot Profile ........................................................................................................................17
Incremental Heap Profile...........................................................................................................20
Arena Profile..............................................................................................................................23
Analyzing the info heap process output...............................................................................23
Analyzing the info heap arenas output................................................................................24
Leak Profiling..................................................................................................................................28
Error Injection .................................................................................................................................30
Event Monitoring.............................................................................................................................37
Monitoring Heap Events ...........................................................................................................37
Monitoring a Specific Address.............................................................................................37
Monitoring Allocations Greater Than a Specified size.........................................................38
Monitoring the Program Heap Growth................................................................................41
Monitoring Changes in Data Segment Space Allocation (High Water Mark Feature) ........43
Monitoring De-allocations to Detect Double-Frees..............................................................46
Monitoring Heap Corruption ....................................................................................................46
Monitoring String Corruption..............................................................................................46
Detecting Out-of-Bounds Writes with the Bounds-Checking Feature.................................47
Detecting Heap Corruption..................................................................................................51
Scrambling a Heap Block......................................................................................................54
Settings to Manage Performance Degradation. ...................................................................................55
Supported Modes of Memory-debugging in WDB..............................................................................55
Debugging in the Interactive Mode.................................................................................................55
Debugging in Batch Mode...............................................................................................................56
Environment Variables for Batch Memory-Debugging ............................................................56
Enabling and Disabling Batch Mode Memory-Debugging .................................................56
Pre-loading the Appropriate Version of librtc.[sl.so] Along With the Application.............56
Overriding the Default Location for librtc.[sl.so].................................................................57
Overriding the Default Path for Searching the GDB Executable..........................................57
Configuration File for Batch Mode Debugging.........................................................................57
Location of the Configuration File for Batch Mode Debugging...........................................57
Supported Variables for Memory-Debugging in the Batch Mode Configuration File.........57
Overriding the Configuration File Settings................................................................................58
Debugging in Batch Mode.........................................................................................................59
Debugging Multiple Applications in Batch Mode ....................................................................63
Debugging in Attach Mode.............................................................................................................63
Summary of Memory Debugging Commands ....................................................................................64
Table of Contents 5