2

I'm trying to debug a function in 3rd party shared library. I'm having a hard time setting a breakpoint in the function as the application dies shortly after loading the library. Does anyone know of a way to set a pending break-point in mdb so the breakpoint is set shortly after the library is loaded?

Mustafa

2 Answers 2

3

What you call pending breakpoint is called deferred breakpoint in mdb; the way it's being used is like this:

$ mdb /bin/ls
> ::bp libc.so.1`_init
> :r
mdb: stop at libc.so.1`_init
mdb: target stopped at:
libc.so.1`_init:save      %sp, -0x60, %sp

I.e. just turn the ::bp command around, <addr>::bp is direct (and requires the symbol / address to be present, already loaded), while ::bp <object`symbol> is deferred (and activated by the debugger when the specified object is first loaded). Using the object`symbol notation you can distinguish between identically-named functions in different libraries even:

> !ldd /bin/ls
        libsec.so.1 =>   /lib/libsec.so.1
        libc.so.1 =>     /lib/libc.so.1
        libavl.so.1 =>   /lib/libavl.so.1
        libm.so.2 =>     /lib/libm.so.2
> ::bp libsec.so.1`_init
> ::bp libc.so.1`_init
> ::bp libavl.so.1`_init
> ::bp libm.so.2`_init
> ::bp _init
> :r
mdb: stop at libc.so.1`_init
mdb: target stopped at:
libc.so.1`_init:save      %sp, -0x60, %sp
> :c
mdb: stop at libavl.so.1`_init
mdb: target stopped at:
libavl.so.1`_init:      save      %sp, -0x60, %sp
> :c
mdb: stop at libsec.so.1`_init
mdb: target stopped at:
libsec.so.1`_init:      save      %sp, -0x60, %sp
> :c
mdb: stop at _init
mdb: target stopped at:
_init:          save      %sp, -0x60, %sp

Enjoy debugging !

1
  • Thanks man! You helped save countless hours of wasted debugging time. Feb 13, 2012 at 20:30
0

I couldn't quite figure out how to do set a pending breakpoint but I found that getting the name of the last library loaded, helped. To do this I added a system breakpoint on the 'open' system call and I added a command to the breakpoint which prints the first argument to open (i.e. the name of the file) and continues.

> ::sysbp -c "<i0 /s; ::cont" open
> ::cont

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.