gdb 反汇编:显示以 16 为基数的函数偏移量

发布于 2024-11-08 11:20:44 字数 799 浏览 3 评论 0原文

反汇编函数时,gdb 将显示以 16 为基数的内存地址,但以 10 为基数显示偏移量。

示例:

(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 才能够找到所需的指令。

可以告诉gdb显示带有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
   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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2024-11-15 11:20:44

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

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
陌上芳菲 2024-11-15 11:20:44

你必须修补 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文