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

samwise
  • 347
  • 1
  • 4
  • 15
  • If you make the library sleep you can `attach` to an existing process using GDB. – Flexo Sep 03 '11 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. – samwise Sep 03 '11 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... – paulsm4 Sep 03 '11 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. – samwise Sep 04 '11 at 03:36

1 Answers1

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:

paulsm4
  • 114,292
  • 17
  • 138
  • 190