Using gdb to find memory leaks in HP Unix

Using gdb to find memory leaks in HP Unix
The following gdb commands are used to setup memory leak detection in C++ programs:
set heap-check leaks on
set heap-check free on
set heap-check bounds on
set heap-check scramble on
To show the leak the following command is used:
(gdb) info leaks
To view a particular leak from a list of leaks detected use the following:
(gdb) info leak  <leak number> ( leak number is the relevant number from the leak)
It is very important that program be linked with librt.sl shared library to use heap profiling.
The following example is using xscAppAdapter as a C++ program to demonstrate memory leak detection.

1) Set Heap Options
>>gdb xscAppAdapter.gdb
(gdb) set heap-check leaks on
(gdb) set heap-check free on
(gdb) set heap-check bounds on
(gdb) set heap-check scramble on
(gdb) b xscAppAdapter::processMessage
2) Set Breakpoint and Run Application and continue once past the breakpoint to process a message and then detect a leak
Breakpoint 1 at 0x202e4: file xscAppAdapter.C, line 383.
(gdb) run -s PFAppStation -c xsc_Config.8.0 -t xsc_StateManager -r dflt > /dev/null 2>&1 0</dev/null
Starting program: /perf/app/bin/xscAppAdapter.gdb -s PFAppStation -c xsc_Config.8.0 -t xsc_StateManager -r dflt > /dev/null 2>&1 0</dev/null
Breakpoint 1, xscAppAdapter::processMessage (this=0x4081edf8, msg=@0x407b19b0) at xscAppAdapter.C:383
(gdb) c 1
Will stop next time breakpoint 1 is reached.  Continuing.
Breakpoint 1, xscAppAdapter::processMessage (this=0x4081edf8, msg=@0x407b1a50) at xscAppAdapter.C:383
383     in xscOpedsAdapter.C
3) Find leak using info leaks.
(gdb) info leaks
Scanning for memory leaks...
338 bytes leaked in 13 blocks

No. Total bytes Blocks Address Function
0 88 1 0x40510768 operator new(unsigned long)()
1 64 1 0x405321b8 operator new(unsigned long)()
2 37 1 0x4053f1c8 operator new[](unsigned long)()
3 37 1 0x4053f208 operator new[](unsigned long)()
4 31 1 0x406790f0 strdup()
5 22 3 0x4074d548 operator new[](unsigned long)()
6 20 1 0x405f3078 pthread_atfork()
7 15 1 0x40733810 operator new[](unsigned long)()
8 12 1 0x40536510 operator new(unsigned long)()
9 8 1 0x4040e268 operator new(unsigned long)()
10 4 1 0x405efca8 operator new[](unsigned long)()
4) Lookup Individual leak info.
(gdb) info leak 4

Comments

Post a Comment

Popular posts from this blog

How to use a value between two different threads in Jmeter

Steps to Analyze AWR Report in Oracle

Correlation and checking in Results