2

I have an executable that dynamically loads a shared object library, let say foo.so. I do not build foo.so and it is given to me as a library to use in my code. foo.cpp compiles to give foo.so. I do not have access to foo.cpp but have foo.so. I want to set a breakpoint when my executable calls a function inside this shared library foo.so (that is when function inside foo.cpp is called). Is their a way in gdb to do so? I have tried

gdb funcname 

but it does not seem to work. Any pointers how to break gdb at that point?

6
  • Could you be more specific on the operating system and version of gdb you are using? Commented Aug 14, 2012 at 2:00
  • I am using CentOS 5.5 and gdb 7.2. Commented Aug 14, 2012 at 2:08
  • @DeeptiJain Was the shared object library compiled with the appropriate debug flags? Commented Aug 14, 2012 at 4:32
  • @Michael GDB does not need the library to be compiled with debug flags to set breakpoints in it. Commented Aug 14, 2012 at 5:52
  • @EmployedRussian It's my understanding that without the symbol table (no debug flags) that you can only do ASM level debugging. Commented Aug 15, 2012 at 1:26

1 Answer 1

3

Is their a way in gdb to do so?

Yes.

I have tried gdb funcname

That wouldn't work. You need to run gdb exename, then break funcname at the (gdb) prompt.

At that point, GDB will likely inform you that funcname does not yet exist (since you haven't yet dynamically loaded foo.so), and will ask you whether you want to create a deferred breakpoint. You should answer yes, and GDB will retry setting this breakpoint every time a new shared library is loaded. Eventually this will succeed, and you should get the breakpoint set (automatically and silently), and when you call the funcname later, that breakpoint will fire and GDB will stop (which is exactly what you want).

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.