【问题标题】:Debugging shared libraries with gdbserver使用 gdbserver 调试共享库
【发布时间】:2012-01-26 12:38:17
【问题描述】:

我在目标和 CodeSourcery IDE 上使用 gdbserver。我的硬件是带有 omap3530 的 gumstix。

我可以在我的主应用程序中单步执行代码,但如果我尝试单步执行共享库中的函数,我会得到内存地址并且调试器会终止。

这是我的库,已编译并复制到目标系统上的 /lib 文件夹。(它确实有调试符号)我试图使用 .gbdinit 文件来设置 solib-absolute-prefix /lib

以下是来自 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"

导致

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"

【问题讨论】:

标签: linux gdb shared-libraries gdbserver


【解决方案1】:

您可以使用安装在主机上的库进行调试,前提是调试机器也是开发机器。在这种情况下,您使用 set sysroot 而不是 set sysroot-on-target。例如:

set sysroot /home/username/.../rootfs/

其中/home/username/.../rootfs/ 包含目标文件系统的副本

我认为您还应该指定/ 而不是/lib

【讨论】:

  • 我的主机调试机器是一个 windows 盒子,所以我不确定我的 rootfs 将位于它的什么位置。谢谢
【解决方案2】:

带有调试符号的目标

这是开始工作的最简单方法,在开发特定共享库时特别有用。

首先将测试可执行文件和共享库复制到目标调试信息:

然后瞄准目标:

gdbserver --multi :1234 ./executable_name

主持人:

arm-linux-gnueabihf-gdb -q -nh \
  -ex "target extended-remote target-hostname-or-ip:1234" \
  -ex "file ./executable_name" \
  -ex 'tb main' \
  -ex 'c' \
  -ex 'set solib-search-path .'

sharedlibrary libmylib.so 也可以。

我遇到的问题是gdbservermain 之前在动态加载器处停止,并且动态库此时尚未加载,因此GDB 还不知道符号将在内存中的位置。

GDB 似乎有一些自动加载共享库符号的机制,如果我为主机编译并在本地运行 gdbserver,则不需要运行到 main。但在 ARM 目标上,这是最可靠的做法。

目标 gdbserver 7.12-6,来自 Linaro 的主机 arm-linux-gnueabihf-gdb 7.6.1。

没有调试符号的目标库

通常在部署到嵌入式目标之前剥离目标库,因为调试信息会使它们变大。

例如,Buildroot 默认执行此操作,但您可以使用 BR2_STRIP_none=y 禁用它。

您可以通过运行来识别这种情况:

info shared

显示类似:

From                To                  Syms Read   Shared Object Library
0x00007ffff7df7f90  0x00007ffff7dfcdd7  Yes (*)     target:/lib/ld64-uClibc.so.0
0x00007ffff7b3a9b0  0x00007ffff7bbe05d  Yes (*)     target:/lib/libc.so.0
(*): Shared library is missing debugging information.

所以两个库都有星号 (*),表示缺少调试信息。

如果是这种情况,那么您必须告诉 GDB 使用主机上的共享库它们被剥离之前。

例如,Buildroot 对我们来说很容易,因为它维护了 staging 目录,该目录包含共享库在被剥离之前包含在与目标相同的相对路径中:

set sysroot buildroot/output/staging/

设置此选项后,gdb 会立即在主机而不是目标中搜索库,并在路径buildroot/output/staging/ + /lib/libc.so.0 处找到/lib/libc.so.0

Reading symbols from buildroot/output/staging/lib/ld64-uClibc.so.0...done.
Reading symbols from buildroot/output/staging/lib/libc.so.0...done.

TODO:我认为您不能设置多个sysroot,因此您的所有共享库都必须放置在目标图像中的正确相对路径中。

如果您检查错误的默认 sysroot,您将看到:

show sysroot

给:

target:

这意味着gdb默认搜索目标根/上的共享库。

【讨论】:

    【解决方案3】:

    调试时遇到类似问题。调试挂了。配置如下

    主机:Ubuntu 12.04LTS

    IDE:Eclipse 开普勒

    目标:Beaglebone Black / ARM A8

    操作系统:埃

    解决方案

    更新库和包含

    在 Eclipse 中选择项目的属性

    • C/C++ 常规 > 路径和符号 >(包括 TAB)GNU C > 添加 > 文件 系统 > / > usr 从 /usr/lib/gcc/i686-linux-gnu/4/6/include 更改 到 /usr/arm-linux-gnueabi/include

    • C/C++ 常规 > 路径和符号 >(包括 TAB)GNU C++> 添加 >
      文件系统 > / > usr /usr/arm-linux-gnueabi/include/c++/4.6.3/arm-linux-gnueabi

    • C/C++ 常规 > 路径和符号 >(库路径选项卡)> 添加 > 文件 系统 > // usr /usr/arm-linux-gnueabi/lib

    【讨论】:

      【解决方案4】:

      早安,

      如果 GDB 中的 'debug-file-directory' 变量设置不正确, 那么报告的错误信息包含: 警告:找不到动态链接器断点函数。

      目标的根文件系统位于我的主机 PC 上 /opt/arm-linux-gnueabihf-rootfs

      以下两个命令帮助我进行远程调试 通过使用 GDB (v7.11.1) 的 gdbserver:

      set debug-file-directory /opt/arm-linux-gnueabihf-rootfs/usr/lib/debug
      set sysroot /opt/arm-linux-gnueabihf-rootfs
      

      我注意到如果 'sysroot' 在路径中有一个斜杠, 然后 GDB 无法使用它。连接到远程目标后,您将看到此(错误输出):

      Reading /lib/ld-linux-armhf.so.3 from remote target...
      

      Reading symbols from /opt/arm-linux-gnueabihf-rootfs/lib/ld-linux-
      armhf.so.3...(no debugging symbols found)...done
      

      而不是正确的输出:

      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.
      

      问候, Frikkie Thirion

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-10-09
        • 1970-01-01
        • 2014-04-15
        • 2022-01-11
        • 1970-01-01
        • 1970-01-01
        • 2011-03-10
        相关资源
        最近更新 更多