Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB does not break in dynamically-loaded .so file?

In my Linux system I'm writing a program that dynamically loads some .so libraries when running. It's like this: The executable program will search under a particular directory when it starts to run and then load all the .so files in that directory. Please note that the executable and the .so are built independently, and the build of the executable does NOT link to the .so files.

My problem is: After I run the program(thus all the .so libraries have been loaded) with GDB attached, I seem to be able to set a breakpoint on the code in the .so file(the GDB prompts me that this breakpoint is set in a shared library), but this breakpoint never actually breaks.

How should I make these breakpoints really work? During the debug session I have all the source code available at the right places, and the -g option is on. I also removed the -O2 optimization when compiling.

like image 391
yaobin Avatar asked Aug 02 '11 10:08

yaobin


2 Answers

Check that debugging information was properly loaded for .so file. Look at the output of command (gdb) info sharedlibrary. If your library appears with asterisk (*) symbol in loaded libraries table then debug symbols were not loaded and gdb unable to stop at breakpoints in this .so.

like image 77
ks1322 Avatar answered Sep 24 '22 16:09

ks1322


Perhaps your function is never called. Place a breakpoint at your shared library's entry point (a function that your main program fetches with dlsym). I have just verified that my gdb (7.1) does stop at such a breakpoint.

If you absolutely sure that your function is called (say, it produces some unique output that you can see) but the breakpoint you set on it is not fired, then it's a bug in gdb and it should be reported to the gdb maintainers.

like image 39
n. 1.8e9-where's-my-share m. Avatar answered Sep 23 '22 16:09

n. 1.8e9-where's-my-share m.