如何区分GDB中不同对象文件中具有相同名称的符号?

如何区分GDB中不同对象文件中具有相同名称的符号?,gdb,arm,debug-symbols,nm,Gdb,Arm,Debug Symbols,Nm,我有两个源文件(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

我有两个源文件(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文件中转储符号,则这些重复符号的调试信息似乎已被剥离。这是正常的行为吗,即自动发生

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\u gpiote\u user\u enable等符号中。如果我尝试打印其中一个副本,如
m\u user\u array\u size
,gdb告诉我,
当前上下文中没有符号“m\u user\u array\u size”。
但是,如果我打印
app\u gpiote\u user\u enable
,gdb对此很满意

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

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

    重复符号的打印方式如下:p'f2.c'::x。这是解释

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


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

    太好了!我确实指定了-flto。知道我可以指定文件也很有帮助。
    print *(int*)0x60103c