Leonard Li's Weblog
Runtime Memory Checking
Your app has gone through the development cycle, gotten tested, and finally it gets deployed. Everything goes well, but one day a customer calls you, "Hey, your binary is taking up 60Gig of memory, and there is nothing left!". Instead of mumbling "then how do you remember my number?", you send a field application engineer to track down the problem at the customer site.
There is no debug information available and you cannot recompile your binary in the customer site. How to find the leaks? Here is where dbx's runtime memory checking (RTC) comes in handy. RTC interposes and instruments the binaries on the fly and therefore it does not require recompiling, relinking or even debug information - just load your application into dbx and run. For example,
(dbx) check -all
access checking - ON
memuse checking - ON
(dbx) run
You can also enable runtime memory checking on a running process
using the link auditor.
/opt/ss12/opt/SUNWspro/bin/dbx
% setenv LD_AUDIT_64 /opt/ss12/opt/SUNWspro/prod/lib/amd64/dbxruntime/rtcaudit.so
% a.out &
[1] 6759
% unsetenv LD_AUDIT_64
% dbx - 6759
(dbx) check -all
access checking - ON
memuse checking - ON
(dbx) cont
When access checking is turned on, RTC detects and reports the following kinds of errors:
baf # Bad freeduf # Duplicate free
maf # Misaligned free
mar # Misaligned read
maw # Misaligned write
oom # Out of memory
rua # Read from unallocated memory
rui # Read from uninitialized memory
wro # Write to read-only memory
wua # Write to unallocated memory
With leaks checking, RTC will report the following kinds of errors:
aib # Possible memory leak - only pointer points in the middle of the block
air # Possible memory leak - pointer to the block exists only in register
mel # Memory leak - no pointers to the block
RTC reports memory errors with context information that includes
details about allocation of a heap block. Here is a memory access error
reported on an AMD64 box:
Attempting to read 1 byte at address 0x412de0
which is just past heap block of size 1000 bytes at 0x4129f8
This block was allocated from:
[1] rua() at line 37 in "access.c"
[2] access() at line 7 in "access.c"
[3] main() at line 7 in "main.c"
stopped in rua at line 38 in file "access.c"
38 c = s[1000];
Memory errors can be suppressed. The following command suppress read from uninitialized (rui) in all functions in a.out
RTC instruments memory access assembly instructions for access checking. You can exclude load objects, object files and functions from being instrumented. The following command
excludes the function main from being instrumented.
Runtime memory access checking and leaks checking are available on
Solaris Sparc and Intel x86/x64. AMD64 access checking is a new feature
in Sun Studio 12.
This advanced feature is fully supported by the debugger IDE.
Posted at 12:40PM Jun 01, 2007 by janitor in Sun | Comments[6]
Posted by DP on June 02, 2007 at 03:56 AM PDT #
Posted by wpan on June 02, 2007 at 04:14 PM PDT #
Posted by yydzero on June 02, 2007 at 07:04 PM PDT #
Posted by wpan on June 03, 2007 at 11:52 AM PDT #
A very help peice of information, it did help a lot as I do not normally use dbx.
Thanks
Rick
Posted by Rick Sivernell on November 21, 2007 at 07:55 AM PST #
It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.
~
Posted by links of london jewellery on November 21, 2009 at 08:41 PM PST #