开发者

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

开发者 https://www.devze.com 2023-03-25 19:11 出处:网络
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 u开发者_高级运维nder a particular directory when it

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 u开发者_高级运维nder 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.


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.


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.


The last time this happened to me, I ran in gdb

info sharedlibrary

only to realize that I had multiple versions of the library, one built with debug symbols and the other without debug symbols. gdb was picking up the one without.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号