3

I wrote a little unit test framework that uses python to dynamically loaded shared libraries and invoke test methods on them. I am able to invoke unit tests through my build scripts by executing:

make test_library

Make then spawns python with a script that invokes my test methods. This works great but I am having trouble setting it up with GDB so that I can invoke the same make target but and have GDB break when my library test code is reached. Any suggestions on how to best go about it? This is all on linux.

Thanks

4
  • If you make the library sleep you can attach to an existing process using GDB. Commented Sep 3, 2011 at 21:05
  • 1
    To answer my own question, gdb works fine with dynamically loaded libraries. You can set a breakpoint before any symbols are loaded and gdb will do the right thing once a matching symbol is found in a shared library. The problem I was having is that I specified make as the executable and thats not right since its actually Python that loads my library. Once I rectified that it all just worked. Commented Sep 3, 2011 at 22:35
  • Yes, of COURSE gdb works find with shared libraries! The question is, HOW were you trying (and, presumably, failing) to set the desired breakpoints? You still haven't told us... Commented Sep 3, 2011 at 23:09
  • Oh, sorry, I thought it was clear from the comment, I was setting the BP's correctly, with br file:line, but since I instructed gdb to start make instead of python, the BP was never hit. Which in retrospect is not surprising. Commented Sep 4, 2011 at 3:36

1 Answer 1

1

There are several approaches.

You can

  • gdb myprog < myscript

  • gdb source myscript

  • etc

Here's a link on GDB commands:

Here's a good GDB cheat sheet:

Here's a specialized technique ("hooks") that might also be applicable:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.