我可以给 objdump 一个地址并让它反汇编包含的函数吗?

发布于 2024-11-16 19:17:47 字数 123 浏览 5 评论 0原文

我发现必须反汇编大量库代码才能获得足够的上下文来查看导致崩溃的原因,这真的很烦人。有什么方法可以让 objdump 传递一个地址,并让它为我找到包含函数的边界吗?

编辑:更好的是,我可以让它为我反汇编整个堆栈跟踪吗?

I'm finding it really annoying to have to disassemble large swathes of library code just to get enough context to see what is causing a crash. Is there any way that I can just hand objdump an address, and have it find the boundaries of the containing function for me?

EDIT: Better yet, can I have it disassemble an entire stack trace for me?

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

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

发布评论

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

评论(3

不离久伴 2024-11-23 19:17:47

也许是这样的?

$ objdump -S --start-address=0x42 foo.o | awk '{print $0} $3~/retq?/{exit}'

它从 0x42 开始打印反汇编列表,直到找到 ret(q),假设边界ret 标记(q)

Something like this perhaps?

$ objdump -S --start-address=0x42 foo.o | awk '{print $0} $3~/retq?/{exit}'

It prints the dis-assembly listing starting from 0x42 till it finds a ret(q), assuming the boundary is marked by ret(q)

纵山崖 2024-11-23 19:17:47

GDB 反汇编

gdb -batch -ex "file $EXECUTABLE" -ex "disassemble/rs $ADDRESS"

例如:

ac

#include <assert.h>

int myfunc(int i) {
    i = i + 2;
    i = i * 2;
    return i;
}

int main(void) {
    assert(myfunc(1) == 6);
    assert(myfunc(2) == 8);
    return 0;
}

编译并反汇编myfunc以查找地址:

gcc -std=c99 -O0 -g a.c
gdb -batch -ex 'file a.out' -ex "disassemble/rs myfunc"

输出:

Dump of assembler code for function myfunc:
a.c:
3   int myfunc(int i) {
   0x000000000000064a <+0>: 55  push   %rbp
   0x000000000000064b <+1>: 48 89 e5    mov    %rsp,%rbp
   0x000000000000064e <+4>: 89 7d fc    mov    %edi,-0x4(%rbp)

4       i = i + 2;
   0x0000000000000651 <+7>: 83 45 fc 02 addl   $0x2,-0x4(%rbp)

5       i = i * 2;
   0x0000000000000655 <+11>:    d1 65 fc    shll   -0x4(%rbp)

6       return i;
   0x0000000000000658 <+14>:    8b 45 fc    mov    -0x4(%rbp),%eax

7   }
   0x000000000000065b <+17>:    5d  pop    %rbp
   0x000000000000065c <+18>:    c3  retq   
End of assembler dump.

OK,所以 0x00000000000000655 在 myfunc中code>,让我们确认它是否有效:

gdb -batch -ex 'file a.out' -ex 'disassemble/rs 0x0000000000000655'

输出:与之前的反汇编相同。

另请参阅:如何使用 objdump 反汇编单个函数?

在 Ubuntu 18.04、GDB 8.1 上测试。

GDB disassemble

gdb -batch -ex "file $EXECUTABLE" -ex "disassemble/rs $ADDRESS"

For example:

a.c

#include <assert.h>

int myfunc(int i) {
    i = i + 2;
    i = i * 2;
    return i;
}

int main(void) {
    assert(myfunc(1) == 6);
    assert(myfunc(2) == 8);
    return 0;
}

Compile and disassemble myfunc to find an address:

gcc -std=c99 -O0 -g a.c
gdb -batch -ex 'file a.out' -ex "disassemble/rs myfunc"

Output:

Dump of assembler code for function myfunc:
a.c:
3   int myfunc(int i) {
   0x000000000000064a <+0>: 55  push   %rbp
   0x000000000000064b <+1>: 48 89 e5    mov    %rsp,%rbp
   0x000000000000064e <+4>: 89 7d fc    mov    %edi,-0x4(%rbp)

4       i = i + 2;
   0x0000000000000651 <+7>: 83 45 fc 02 addl   $0x2,-0x4(%rbp)

5       i = i * 2;
   0x0000000000000655 <+11>:    d1 65 fc    shll   -0x4(%rbp)

6       return i;
   0x0000000000000658 <+14>:    8b 45 fc    mov    -0x4(%rbp),%eax

7   }
   0x000000000000065b <+17>:    5d  pop    %rbp
   0x000000000000065c <+18>:    c3  retq   
End of assembler dump.

OK, so 0x0000000000000655 is in myfunc, let's confirm it works:

gdb -batch -ex 'file a.out' -ex 'disassemble/rs 0x0000000000000655'

Output: same as previous disassembly.

See also: How to disassemble one single function using objdump?

Tested on Ubuntu 18.04, GDB 8.1.

花开柳相依 2024-11-23 19:17:47

objdump --start-address= 或许?

objdump --start-address= perhaps ?

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