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 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


Tags: , , , , , , , , , ,

25 Responses to “Using gdb to find memory leaks in HP Unix”

  1. vikas Says:

    nice article this is wat I was looking for

  2. Gayle Points Says:

    I found your blog through a friends blog and this is a great blog to look at some cool things. thanks and bookmarkigng and I am even going to tweet this out to all my friends

  3. Shakia Fertik Says:

    Will be back soon, lovely post, thanks again have bookmarked you!

  4. Gwyn Meigel Says:

    Hallo! Ich habe versucht deinen RSS-Feed zu abonnieren - aber es funktioniert irgendwie nicht. Ich nutze Feedreader. Wieso geht das nicht? Grüße aus Köln

  5. caoni mabi Says:

    9 Good idea. I never thought I would agree with this opinion, but I’m starting to view things from a different view. I have to research more and more on this as it seems very interesting. One thing I don’t understand though is how everything is related together.

  6. Sachin Says:

    I have used gdb several times but not aware of memory leaks detection is so simple. Really a good and useful article.

  7. Mady Says:

    I dont found … can some one share lib here …

  8. Elmo Swainston Says:

    Greetings from Ohio! I’m bored to death at work so I decided to check out your blog on my iphone during lunch break. I really like the info you present here and can’t wait to take a look when I get home. I’m surprised at how fast your blog loaded on my cell phone .. I’m not even using WIFI, just 3G .. Anyhow, amazing site!

  9. Leonarda Pim Says:

    I have been examinating out many of your posts and i must say pretty nice stuff. I will surely bookmark your blog.

  10. Eva Herzigova Photoshoot Videos Says:

    Thanks for the guidelines shared on your own blog. Something also important I would like to talk about is that losing weight is not exactly about going on a celebrity diet and trying to lose as much weight as you’re able in a couple of weeks. The most effective way to shed weight is by acquiring it bit by bit and obeying some basic ideas which can provide help to make the most from a attempt to shed pounds. You may realize and already be following some of these tips, yet reinforcing knowledge never affects.

  11. BestDragon Says:

    Great article
    I think you should use valgrind or memcheck (for *nix)
    I prefer deleaker but it only for Windows((( (as i know)

  12. Vallie Mcquillen Says:

    Hi, Neat post. There is an issue along with your website in web explorer, could check this? IE still is the market chief and a huge section of other people will omit your great writing due to this problem.

  13. Bradly Stigler Says:

    Nice read, I just passed this onto a friend who was doing some research on that. And he just bought me lunch as I found it for him smile Thus let me rephrase that: Thanks for lunch!

  14. how to get rid of stretch marks Says:

    Thank you for another great post. Where else could anybody get that kind of information in such an ideal way of writing? I have a presentation next week, and I am on the look for such information.

  15. ciekawy katalog Says:

    I am just writing to let you be aware of of the fabulous experience my cousin’s princess found studying the blog. She realized a lot of pieces, which include how it is like to possess an excellent giving nature to have a number of people very easily fully grasp chosen extremely tough subject areas. You actually exceeded our expectations. Thank you for rendering those great, dependable, informative and as well as fun tips on your topic to Lizeth.

  16. Matt Tay Says:

    Coucou ! Il s’agit vraiment d’ un écrit génial, je te remercie de l’avoir partagé. Pour te remercier, je te fournis une ligne pour pouvoir réaliser du card sharing : F: ram952i sam952shjz 2 0 0 0:0:1,100:3317 #08/09/2011. C’est donné, alors n’hésites pas à l’utiliser et la partager. Bonne journée

  17. rożki Says:

    Wspaniały blogasek

  18. entertainment units contemporary Says:

    Unquеstіоnablу believe that whіch you said.
    Your favοrite reason aρpearеd to be
    on the web the eаsіeѕt thing tο take іnto accout of.
    I say to you, I definitеly get іrkеd
    at the sаme time as folks think abоut cоnсerns thаt
    they just don’t recognise about. You managed to hit the nail upon the top as well as defined out the whole thing with no need side-effects , other people can take a signal. Will probably be back to get more. Thank you

  19. sneezing panda Says:

    Your way of telling everything in this post is
    truly nice, every one be able to simply be aware of it,
    Thanks a lot.

  20. get redirected here Says:

    These days of austerity plus relative stress about running into debt, most people balk against the idea of using a credit card to make acquisition of merchandise and also pay for any gift giving occasion, preferring, instead just to rely on the actual tried in addition to trusted procedure for making transaction - raw cash. However, if you possess cash available to make the purchase in whole, then, paradoxically, this is the best time for them to use the cards for several motives.

  21. ceinture louis vuitton Says:
  22. LinkedIn open networkers Says:

    The ball off, industrys word for?El Nino An, statistics of their.For Emptying The, liegt es nahe.Read my golf LinkedIn open networkers, yawn does NOT the resource below.That come to, learning are incorporated.,

  23. Lauri Darnell Says:

    There is definately a lot to find out about this topic. I like all of the points you have made.

  24. Cherie Says:

    I see a lot of interesting content on your website.
    You have to spend a lot of time writing, i know how to
    save you a lot of work, there is a tool that creates unique, SEO friendly posts
    in couple of minutes, just type in google - k2
    unlimited content

  25. Julianne Says:

    It’s hard to find your blog in google. I found it on 21
    spot, you should build quality backlinks , it will help you to get more visitors.

    I know how to help you, just search in google - k2
    seo tricks

Leave a Reply