2011-05-18 64 views
5

放映功能偏移當拆卸功能,GDB將顯示在基座16的存儲器地址,但在鹼的偏移量10。GDB拆機:在底座16

實施例:

(gdb) disassemble unregister_sysctl_table 
Dump of assembler code for function unregister_sysctl_table: 
    0x00037080 <+0>: push %ebp 
    0x00037081 <+1>: mov %esp,%ebp 
    0x00037083 <+3>: sub $0x14,%esp 
    0x00037086 <+6>: mov %ebx,-0xc(%ebp) 
    0x00037089 <+9>: mov %esi,-0x8(%ebp) 
    0x0003708c <+12>:mov %eax,%ebx 
    0x0003708e <+14>:mov %edi,-0x4(%ebp) 

函數偏移是在<+N>旁邊的地址,你可以看到他們是在基地10

當Linux內核崩潰,它顯示使用基地16回溯:

[ 0.524380] [<c10381d5>] unregister_sysctl_table+0x65/0x70 

這是非常煩人的必須將回溯地址從基地16轉換爲基地10以能夠找到所需的指令。

Can gdb被告知顯示具有16個基點偏移的反彙編輸出?

回答

3

GDB當前使用硬編碼的'%d'作爲偏移量。

這是非常惱人不得不轉換回溯地址......能夠找到需要的指令

你一定要明白,你可以簡單地做

x/i 0xc10381d5  # the crashing instruction (if looking at the inner frame) 
x/i 0xc10381d5-5  # the call (if looking at caller frame) 
x/10i 0xc10381d5-20 # context around the desired location 
1

你必須修補gdb以十六進制顯示偏移量。

例如,在gdb 6.8,在CLI-out.c,MI/MI-out.c,TUI/TUI-out.c

變化* _field_int

void 
cli_field_int (struct ui_out *uiout, int fldno, int width, 
enum ui_align alignment, 
const char *fldname, int value) 
{ 
char buffer[40]; /* FIXME: how many chars long a %d can become? */ 


cli_out_data *data = ui_out_data (uiout); 
if (data->suppress_output) 
    return; 
sprintf (buffer, "%d:%X", value, value); 
cli_field_string (uiout, fldno, width, alignment, fldname, buffer);