Thursday 7 June, 2007

Memory Related issues detection tool

Since last 3 to 4 days, I hadn't done even a single defect fix. Time was getting consumed in reviews, meetings and investigations. In the last 3 days, I was getting tired too much. Finally, found the reason for that - I was not hearing to Music last 3 days. Ok, this blog is to explain some tool that I learnt today in detecting memory issues like leaks, corruptions, heap usage etc....
It is MemoryScape. Its a good tool. This can be attached to the running process, or the core that got generated or the new program that to be started.
First, faced problems in attaching this to my binary file - as my binary file not generated using the libraries provided by this tool. Finally was able to do by using LD_PRELOAD environment variable.
But, leaks reporting is not happening. That tool provides some so's. At the time of linking, it makes any fork or malloc or free calls to its functions and then it tracks them. And, then, internally, they call the original functions.
Attached para is copied from its document:
Behind the Scenes

MemoryScape intercepts calls made by your program to heap library functions that allocate and deallocate memory by using the malloc() and free() functions and related functions such as calloc() and realloc(). The technique it uses is called interposition. Our interposition technology uses an agent routine to intercept calls to functions in this library.
Courtesy: www.totalviewtech.com

In the similar way, fork also gets intercepted. Just compiled my code with them and yet to test them. In the mean while compilation is going, thought of putting this here....

2 comments:

Puthali said...

he he...no music...huh? why...someone complained? ;)
neways this technique is not something new....the interposition technique is how our SSL VPN works also....'n on Mac, you can compile ur programs with debug malloc library which comes with it already...

Vishnu said...

too nice :))
no - no one complained :) my totem player was having some problem with sound driver (i guess). If it stops working, it won't work until I logout and login or I need to do some research to make it work. But, don't know for some reason I don't like to logout :(
regarding SSLVPN, you guyz are fundu. Yeah, I remember - once you are doing some changes to library so that your functions gets called before the library functions. You guyz rocks....