346
技術社區[雲棲]
gdb可以查詢執行文件的宏, 但是查詢不了o文件的宏
在gcc使用-g3編譯的時候, gdb可以查看對應c語言的宏.
gdb a.out -ex 'list main' -ex 'info macro XXXX' -ex 'q'
Defined at /xvdc/w.c:6 #define XXXX ppppppppppppp
但是o文件卻看不了對應的宏,
gdb w.o -ex 'list main' -ex 'info macro XXXX' -ex 'q'
The symbol `XXXX' has no definition as a C/C++ preprocessor
<user-defined>:-1
網上找了半天也沒發現什麼有用的地方, 隻能自己看gdb的源代碼調
一路調試了半天, 找到了個關鍵地方
函數dwarf_decode_macros裏麵解析macinfo_type的時候, a.out和w.o有所區別
switch (macinfo_type)
{
/* A zero macinfo type indicates the end of the macro
information. */
case 0:
break;
case DW_MACRO_define:
case DW_MACRO_undef:
case DW_MACRO_start_file:
case DW_MACRO_end_file:
a.out文件的macinfo_type序列是DW_MACRO_import DW_MACRO_start_file
o文件的macinfo_type序列是5個DW_MACRO_define_strp
而在gdb內部產生macro表格的路徑是由DW_MACRO_start_file開始的
case DW_MACRO_start_file:
{
unsigned int bytes_read;
int line, file;
line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
current_file = macro_start_file (file, line, current_file, lh);
}
下一步要做的就是看看如何讓gcc在生產o文件的時候, section .debug_macro裏麵帶上DW_MACRO_start_file
看遍gcc選項也沒發現什麼, 難道又要去看gcc源代碼了, 這種突如其來的領域問題真是難搞
最後更新:2017-07-14 15:32:20