开发者

gdb disassemble: show function offsets in base 16

When disassembling functions, gdb will display memory addresses in base 16, but offsets in base 10.

Example:

(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
 开发者_如何学JAVA  0x00037086 <+6>: mov    %ebx,-0xc(%ebp)
   0x00037089 <+9>: mov    %esi,-0x8(%ebp)
   0x0003708c <+12>:mov    %eax,%ebx
   0x0003708e <+14>:mov    %edi,-0x4(%ebp)

The function offsets are the <+N> next to the address, and as you can see they are in base 10.

When the Linux kernel crashes, it displays a backtrace using base 16:

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

It's very annoying to have to convert backtrace addresses from base 16 to base 10 to be able to find the desired instruction.

Can gdb be told to display disassembly output with base 16 offsets?


GDB currently uses hard-coded '%d' for the offset.

It's very annoying to have to convert backtrace addresses ... to be able to find the desired instruction

You do realize that you can simply do

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


you have to patch gdb to show offset in hex.

for example, in gdb 6.8,

change *_field_int in cli-out.c, mi/mi-out.c, tui/tui-out.c

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜