gpt4 book ai didi

gdb - 在使用 gdb 的指令中间反汇编?

转载 作者:行者123 更新时间:2023-12-04 19:34:49 28 4
gpt4 key购买 nike

我相信这在以前工作得很好,但也许我只是忘记了正确的语法。

(gdb) disas main
Dump of assembler code for function main:
0x0000000000001125 <+0>: push rbp
0x0000000000001126 <+1>: mov rbp,rsp
0x0000000000001129 <+4>: mov DWORD PTR [rbp-0x4],edi
0x000000000000112c <+7>: mov QWORD PTR [rbp-0x10],rsi
0x0000000000001130 <+11>: mov eax,0x0
0x0000000000001135 <+16>: pop rbp
0x0000000000001136 <+17>: ret

现在我想在 0x0000000000001127 处反汇编,这是第一条 mov 指令的 1 个字节:
(gdb) disas 0x0000000000001127
Dump of assembler code for function main:
0x0000000000001125 <+0>: push rbp
0x0000000000001126 <+1>: mov rbp,rsp
0x0000000000001129 <+4>: mov DWORD PTR [rbp-0x4],edi
0x000000000000112c <+7>: mov QWORD PTR [rbp-0x10],rsi
0x0000000000001130 <+11>: mov eax,0x0
0x0000000000001135 <+16>: pop rbp
0x0000000000001136 <+17>: ret

它仍然在main的顶部开始反汇编。

我也尝试过诸如 main+1、disas/r 等。gdb 的行为是否有某种改变?我想这可能与这是一个 PIE 二进制文件有关,但是当我用 -no-pie 重新编译它时,我仍然遇到这个问题,因为它是如此简单。

什么是正确的语法?

最佳答案

It still starts the disassembly at the top of main.



当你给 disas单个参数,它找到封闭的函数,并反汇编整个函数。这是自古以来的行为。

如果你给 disas取而代之的是两个参数,那么它只会反汇编给定的范围:
(gdb) disas &main
Dump of assembler code for function main:
0x00000000000005fa <+0>: push %rbp
0x00000000000005fb <+1>: mov %rsp,%rbp
0x00000000000005fe <+4>: mov $0x0,%eax
0x0000000000000603 <+9>: pop %rbp
0x0000000000000604 <+10>: retq
End of assembler dump.

(gdb) disas &main+3,&main+11
Dump of assembler code from 0x5fd to 0x605:
0x00000000000005fd <main+3>: in $0xb8,%eax
0x00000000000005ff <main+5>: add %al,(%rax)
0x0000000000000601 <main+7>: add %al,(%rax)
0x0000000000000603 <main+9>: pop %rbp
0x0000000000000604 <main+10>: retq
End of assembler dump.

您也可以使用 x/i :
(gdb) x/4i &main+3
0x5fd <main+3>: in $0xb8,%eax
0x5ff <main+5>: add %al,(%rax)
0x601 <main+7>: add %al,(%rax)
0x603 <main+9>: pop %rbp

关于gdb - 在使用 gdb 的指令中间反汇编?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54113391/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com