Debugging shared libraries remotely with gdb/gdbserver

六眼飞鱼酱① 提交于 2020-01-11 05:31:08

问题


My question is about remote debugging an application on an embedded arm processor using gdb/gdbserver.

I can debug the application itself, but the application dynamically links to a shared library which implements an in house communications protocol. I want to be able to set breakpoints within the shared library functions so try to figure out some device discovery problems.

I have made sure that the library is compiled with debug symbols and is loaded by gdb on the host side, I can list functions within the library and even set the breakpoints but as soon as I try to run the application I get an error message to the effect of:

Cannot insert breakpoint X.
Error accessing memory address : Input/output error.

where X is the breakpoint number in gdb and is an address far to small to be valid.
I am using the new library on both the target and the host machine, but via mount -o bind newlib oldlib on the target from an nfs mount.
Does anyone have an idea about what could be wrong? Thanks in advance.


回答1:


Wild guess: you loaded the shared library into host GDB at incorrect address.

Instead of explicitly loading it into GDB, use "set stop-on-solib-event on", wait for the library to get loaded (info shared will tell you current list of loaded libraries), and then set the breakpoints.




回答2:


I see this question is from 2009, but the current answers are out-of-date, so here's an update:

@Employed Russian suggested that you must use stop-on-solib-event. This is no longer true; NDK r8d supports pending breakpoints in yet-to-be-loaded solibs.

@Brent Piddy says that stop-on-solib-event doesn't work with gdbserver. This is also no longer true since at least r8c. My company has a product that relies on this NDK behavior from GDB, we would be in big trouble without it.




回答3:


Use the following command to set pending breakpoints that will get resolved after the shared object library is loaded

set breakpoint pending on

Sadly you can not use "set stop-on-solib-event on" for gdbserver remote debugging since gdbserver does not recognize/send solib events. I have had to just issue a set solib-search-path or set sysroot command to get gdb to load all of the shared library symbols after hitting a breakpoint on main.




回答4:


Run up to main and then set solib-search-path .

Otherwise, gdbserver stops at the dynamic loader, before the libraries are loaded. At main, they should be ready for GDB.

More details: Debugging shared libraries with gdbserver



来源:https://stackoverflow.com/questions/1689602/debugging-shared-libraries-remotely-with-gdb-gdbserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!