Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

tracing calls to a library

Say you have a complicated library whose functionality you're trying to use, but while you can run their sample apps, your implementation based on those apps fails. How can you diagnose it?

Here's a trick: first, build the library in debug mode (Debian of course will have you covered: apt-get install libgnutls13-dbg) so that you can get all its symbols. Then run gdb on the working binary. Set a breakpoint on main: b main; run it: r; and then when the breakpoint hits (and your target shared library symbols are loaded), tell gdb to break on all calls to the library, via the new-to-me rbreak command, which is documented like this: "Set a breakpoint for all functions matching REGEXP."

So rbreak ^gnutls_ and then c to continue, and from then on each time you hit enter it'll show the next gnutls function being called along with the exact arguments it's receiving. You can even do the same thing to your own program in another gdb session to watch them run side by side.

PS: There's gotta be some way to tell gdb to load all the shared library symbols without this breakpoint hack, but for all my digging I couldn't find it. gdb is pretty mysterious to me -- rbreak often prints out "Junk at end of arguments." for opaque reasons.
Tags: howto
Subscribe

  • your vcs sucks

    I've been hacking on some Haskell stuff lately that's all managed in darcs and it's reminded me of an observation I made over two years ago now (see…

  • ghc llvm

    I read this thesis on an LLVM backend for GHC, primarily because I was curious to learn more about GHC internals. The thesis serves well as an…

  • found my bug!

    Not too interesting, but this has been bugging me for a week. Been working on a toy program that proxies a TCP connection. It was working fine for…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 13 comments

  • your vcs sucks

    I've been hacking on some Haskell stuff lately that's all managed in darcs and it's reminded me of an observation I made over two years ago now (see…

  • ghc llvm

    I read this thesis on an LLVM backend for GHC, primarily because I was curious to learn more about GHC internals. The thesis serves well as an…

  • found my bug!

    Not too interesting, but this has been bugging me for a week. Been working on a toy program that proxies a TCP connection. It was working fine for…