【问题标题】:How do I differentiate symbols with the same name from different object files in GDB?如何区分 GDB 中不同对象文件中的同名符号?
【发布时间】:2015-01-09 18:26:41
【问题描述】:

我有两个具有相同名称的全局变量的源文件(在 C 中)。全局变量是静态的。如果我使用 nm 从目标文件中转储符号,我可以看到包含调试信息:

hostname:ble_app_hrs username$ find Debug -name '*.o' -exec /usr/local/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-nm -o -l {} \; | grep m_user_array_size
Debug/components/libraries/gpiote/app_gpiote.o:00000000 b m_user_array_size GNU_ARM_Eclipse/nRF51_SDK_7/components/libraries/gpiote/app_gpiote.c:36
Debug/components/libraries/timer/app_timer.o:00000000 b m_user_array_size   GNU_ARM_Eclipse/nRF51_SDK_7/components/libraries/timer/app_timer.c:131

但是,如果我在链接完成后从 ELF 文件中转储符号,则这些重复符号的调试信息似乎已被删除。这是正常行为吗? what's described here 是自动发生的吗?

hostname:ble_app_hrs username$ /usr/local/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-nm -o -l Debug/ble_app_hrs.elf | grep user
Debug/ble_app_hrs.elf:0001cb50 T app_gpiote_user_enable GNU_ARM_Eclipse/nRF51_SDK_7/components/libraries/gpiote/app_gpiote.c:224
Debug/ble_app_hrs.elf:0001ca88 T app_gpiote_user_register   GNU_ARM_Eclipse/nRF51_SDK_7/components/libraries/gpiote/app_gpiote.c:190
Debug/ble_app_hrs.elf:200020a4 B m_enabled_users_mask.6444
Debug/ble_app_hrs.elf:200020c0 B m_gpiote_user_id.6603
Debug/ble_app_hrs.elf:20002080 B m_user_array_size.5782
Debug/ble_app_hrs.elf:200020a8 B m_user_array_size.6446
Debug/ble_app_hrs.elf:200020a9 B m_user_count.6445
Debug/ble_app_hrs.elf:20002084 B mp_users.5783
Debug/ble_app_hrs.elf:200020ac B mp_users.6443
Debug/ble_app_hrs.elf:0001d688 t user_id_get.5752.4484  GNU_ARM_Eclipse/nRF51_SDK_7/components/libraries/timer/app_timer.c:1056
Debug/ble_app_hrs.elf:0001d2cc t user_op_alloc.5716.4521    GNU_ARM_Eclipse/nRF51_SDK_7/components/libraries/timer/app_timer.c:794
Debug/ble_app_hrs.elf:0001d2b4 t user_op_enque.5691.4546    GNU_ARM_Eclipse/nRF51_SDK_7/components/libraries/timer/app_timer.c:781

请注意,并非所有调试信息都已被删除 - 对于像 app_gpiote_user_enable 这样的符号,它仍然存在。如果我尝试打印其中一个重复项,例如 m_user_array_size,gdb 会告诉我,No symbol "m_user_array_size" in current context. 但是,如果我打印 app_gpiote_user_enable,gdb 对此很满意。

  1. 我应该如何在 gdb 中打印重复的符号?我必须使用地址而不是符号吗?
  2. 重复符号末尾的.5782 等数字是什么?这会帮助我将符号映射回目标文件吗?

注意:我宁愿不只是重命名变量——它们都是在第 3 方库中定义的。

【问题讨论】:

    标签: gdb arm debug-symbols nm


    【解决方案1】:

    重复符号打印如下:p 'f2.c'::x。解释为in this section of GDB manual

    使用地址打印可以这样(假设0x60103c是整数变量的地址):

    print *(int*)0x60103c
    

    仅当使用 -flto 标志构建可执行文件时,我才在符号末尾看到数字。这(对于默认的 Ubuntu 14.04 工具链)也破坏了 gdb 从其他文件打印符号的能力(它打印错误的文件)。一种解决方法是在调试时不使用 -flto 进行构建。

    【讨论】:

    • 太棒了!我确实指定了-flto。知道我可以指定文件也很有帮助。
    猜你喜欢
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多