Linux 使用 gdbserver 调试共享库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8611194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debugging shared libraries with gdbserver
提问by Seth
I am using gdbserver on target and CodeSourcery IDE. My hardware is a gumstix with a omap3530.
我在目标和 CodeSourcery IDE 上使用 gdbserver。我的硬件是带有 omap3530 的gumstix。
I can step through code in my main application but if I attempt to step into a function in a shared library I get memory address and a debugger terminates.
我可以单步执行主应用程序中的代码,但是如果我尝试单步执行共享库中的函数,我将获得内存地址并且调试器终止。
This is my library that is compiled and copied to the /lib folder on the target system.(it does have debug symbols) I have attempted to use the .gbdinit file to set solib-absolute-prefix /lib
这是我的库,它被编译并复制到目标系统上的 /lib 文件夹。(它确实有调试符号)我试图使用 .gbdinit 文件来设置 solib-absolute-prefix /lib
Here are the warnings from the gdb trace:
以下是来自 gdb 跟踪的警告:
903,056 13-gdb-set sysroot-on-target /lib
903,065 13^done
903,065 (gdb)
903,065 14-target-select remote 192.168.1.101:2345
903,114 =thread-group-started,id="i1",pid="42000"
903,114 =thread-created,id="1",group-id="i1"
903,115 15-list-thread-groups --available
903,120 16-list-thread-groups
903,128 &"warning: Unable to find dynamic linker breakpoint function.\nGDB will be unable to debug shared library initializers\nand track explicitly loaded dynamic code."
903,128 &"\n"
Which leads to
这导致
903,395 &"Error while mapping shared library sections:\n"
903,397 &"/lib/libCoreLib.so: Invalid argument.\n"
903,399 =library-loaded,id="/lib/libCoreLib.so",target-name="/lib/libCoreLib.so",hostname="/lib/libCoreLib.so",low-address="0x0",high-address="0x0",symbols-loaded="0",thread-group="i1"
回答by shodanex
You can debug with the library installed on your host, provided the debugging machine is also the development machine. In that case, you use set sysroot instead of set sysroot-on-target. For example :
您可以使用安装在主机上的库进行调试,前提是调试机器也是开发机器。在这种情况下,您可以使用 set sysroot 而不是 set sysroot-on-target。例如 :
set sysroot /home/username/.../rootfs/
where /home/username/.../rootfs/
contains a copy of your target filesystem
where/home/username/.../rootfs/
包含目标文件系统的副本
I think you should also specify /
instead of /lib
我认为你也应该指定/
而不是/lib
回答by Mahendra Gunawardena
Similar issue was encountered while debugging. The debug was hanging up. Configuration is as follows
调试时遇到类似问题。调试挂了。配置如下
Host: Ubuntu 12.04LTS
主机:Ubuntu 12.04LTS
IDE: Eclipse Kepler
IDE: Eclipse 开普勒
Target: Beaglebone Black / ARM A8
目标: Beaglebone Black / ARM A8
OS: Angstrom
操作系统:埃
Solution
解决方案
Update libraries and includes
更新库并包含
Select properties for project in Eclipse
在 Eclipse 中为项目选择属性
C/C++ General > Paths and Symbols > (include TAB) GNU C > Add > Files systems > / > usr Change from /usr/lib/gcc/i686-linux-gnu/4/6/include to /usr/arm-linux-gnueabi/include
C/C++ General > Paths and Symbols > (Include TAB) GNU C++> Add >
Files systems > / > usr /usr/arm-linux-gnueabi/include/c++/4.6.3/arm-linux-gnueabiC/C++ General > Paths and Symbols > (Library Paths TAB) > Add > Files systems > / > usr /usr/arm-linux-gnueabi/lib
C/C++ General > Paths and Symbols > (include TAB) GNU C > Add > Files systems > / > usr 将 /usr/lib/gcc/i686-linux-gnu/4/6/include 改为 /usr/arm- linux-gnueabi/包括
C/C++ General > Paths and Symbols > (Include TAB) GNU C++> Add >
Files systems > / > usr /usr/arm-linux-gnueabi/include/c++/4.6.3/arm-linux-gnueabiC/C++ General > Paths and Symbols > (Library Paths TAB) > Add > Files systems > / > usr /usr/arm-linux-gnueabi/lib
回答by Frix
Good day,
再会,
If the 'debug-file-directory' variable in GDB is set incorrectly, then the reported error messages contains: warning: Unable to find dynamic linker breakpoint function.
如果 GDB 中的 'debug-file-directory' 变量设置不正确,则报告的错误消息包含:警告:无法找到动态链接器断点函数。
The root filesystem of the target is located on my host PC at /opt/arm-linux-gnueabihf-rootfs
目标的根文件系统位于我的主机 PC 上的 /opt/arm-linux-gnueabihf-rootfs
The following two commands helped me to get remote debugging working via gdbserver using GDB (v7.11.1):
以下两个命令帮助我使用 GDB (v7.11.1) 通过 gdbserver 进行远程调试:
set debug-file-directory /opt/arm-linux-gnueabihf-rootfs/usr/lib/debug
set sysroot /opt/arm-linux-gnueabihf-rootfs
I've noticed that if 'sysroot' has a trailing slash in the path, then GDB fails to use it.You will see this (incorrect output) after connecting to the remote target:
我注意到如果“sysroot”在路径中有一个尾部斜杠,那么 GDB 将无法使用它。您将在连接到远程目标后看到这个(错误的输出):
Reading /lib/ld-linux-armhf.so.3 from remote target...
or
或者
Reading symbols from /opt/arm-linux-gnueabihf-rootfs/lib/ld-linux-
armhf.so.3...(no debugging symbols found)...done
instead of the correct output:
而不是正确的输出:
Reading symbols from /opt/arm-linux-gnueabihf-rootfs/lib/ld-linux-
armhf.so.3...
Reading symbols from /opt/arm-linux-gnueabihf-rootfs/usr/lib/debug/
lib/arm-linux-gnueabihf/ld-2.23.so...done.
Regards, Frikkie Thirion
问候,弗里基·西里昂