GDB反汇编:以16进制显示函数偏移量

11

在反汇编函数时,gdb会以十六进制显示内存地址,但以十进制显示偏移量。

例如:

(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>,并且它们以十进制表示。

当Linux内核崩溃时,会使用十六进制显示回溯信息:

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

将回溯地址从16进制转换为10进制以查找所需指令非常麻烦。

是否可以告诉 gdb 使用16进制偏移量显示反汇编输出?

2个回答

6

目前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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接