2015-01-09 87 views
1

我有兩個源文件(C語言),它們具有相同名稱的全局變量。全局變量是靜態的。如果我使用nm從目標文件轉儲符號,我可以看到調試信息包括:如何從GDB中的不同目標文件中區分具有相同名稱的符號?

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等數字在重複符號的末尾?這會幫助我將符號映射回目標文件嗎?

注意:我寧願不只是重命名變量 - 它們都在第三方庫中定義。

回答

1

重複的符號打印如下:p'f2.c':: x。這是解釋in this section of GDB manual

通過使用地址打印可以這樣來完成(假設0x60103c是整數變量的地址):

print *(int*)0x60103c 

我在碼元的端部觀察的數字僅當-flto標誌被用來建立可執行。這個(對於默認的Ubuntu 14.04工具鏈)也打破了gdb打印來自其他文件的符號的能力(它打印錯誤的文件)。這種解決方法是在調試時不使用-flto。

+0

非常好!我確實有-fl指定。也知道我可以指定文件是有幫助的。 – watkipet 2015-01-13 06:00:05

相關問題