Hello everyone,
Im today going to share about how to use Solaris express Module Debugger to find stack trace when an application crashes and also how to find memory leaks using it.
First make sure mdb is installed,
# pkg list | grep mdb
developer/debug/mdb 0.5.11-0.151.0.1 i--
If not try installing it. (pkg install mdb)
Now you are all set to go ! IF you are using gcc/g++ instead of C/C++ IDE's then you would've wondered how to find a cause to a certain types of run time errors,
eg:- segmentation fault, buss error, aborted...etc
Well mdb can help you with it ! in above mentioned cases, the core ( a snapshot of memory content when error occurred) gets dumped. mdb can be used to analyze this core file.
# mdb core
Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ]
> ::stack
you can now view the stack when program crashed by issuiing command 'stack' prefixed with double colons ,
# mdb core
Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ]
> ::stack
libc.so.1`_lwp_kill+8(6, ff0c8ca8, fe85ca10, 0, 0, fe85c000)
libumem.so.1`umem_do_abort+0x1c(fe848354, 14, 5, fe85c000, fec7b990, 6)
libumem.so.1`umem_err_recoverable+0x78(fe849584, fe85c000, 1, fe85f0dc, a, a)
libumem.so.1`process_free+0xf8(79e1c, 1, deadbc00, 3e3a1000, 79ccb, 3b7cc)
_Z16houseKeepingExitPcS_iPPhPP8IMSI_VLRPiPSt3mapIiS2_St4lessIiESaISt4pairIKiS2_EEES5_P14_pthread_mutexPS5_+0x118(28088, 79e2c, 6, fec7bf88, fec7bd68, fec7bd7c)
_Z12handleClientP18client_thread_args+0x954(ffbffa80, 0, 0, fefb1240, 246fc, 0)
libc.so.1`_lwp_start(0, 0, 0, 0, 0, 0)
>
as you can see 'houseKeepingExit' function has called 'process_free' which is actually called when you call free() to release dynamically allocated memory.
for a complete list of dcmds commands type,
::dcmds
When you are finished you can exit by typing '::quit'.
To find prevaling memory leaks, we have to use '::findleaks' dcmds command. But prior to using it we have to set enviroment variables,
LD_PRELOAD=libumem.so and UMEM_DEBUG=default
(don't set LD_PRELOAD with the entire path of libumem as it would give wrong ELF class errors)
When compiling our application we have to link with libumem.so (-lumem) as follows,
eg:
#g++ test.cpp -lnsl -lumem
Finally we can run the application. If it encounters a memory leak app will exit with a abort dumping the core file or else After running app, we note down the pid of the app using pgrep and issue gcore to dump a core file,
eg:-
#pgrep test
123
#gcore 123
gcore: core.123 dumped
now use mdb,
# mdb core
Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ]
> ::findleaks
findleaks: no memory leaks detected
>
You can read the following articale from Oracle site, which provides more details about troublshooting memory issues with mdb,
http://developers.sun.com/solaris/articles/libumem_library.html
No comments:
Post a Comment