32位gdb可以调试64位二进制文​​件吗?

发布于 2024-10-16 22:02:48 字数 29 浏览 2 评论 0原文

32位gdb可以调试64位二进制文​​件吗?

Can 32bit gdb debug 64bit binary?

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

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

发布评论

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

评论(2

冧九 2024-10-23 22:02:48

上面的答案是不正确的。您需要 64 位调试器来调试 64 位进程。这正是 gdb 在幕后创建 64 位自身副本的原因。

The answer above is incorrect. You need a 64-bit debugger to debug a 64-bit process. That's precisely the reason why gdb forks a 64-bit copy of itself behind the scenes.

蓝戈者 2024-10-23 22:02:48

是的。 32 位 gdb 在 Solaris 上可以很好地调试 64 位二进制文​​件,至少在最新版本上是这样。

$ cat /etc/release
                      Oracle Solaris 11 Express snv_151a X86
     Copyright (c) 2010, Oracle and/or its affiliates.  All rights reserved.
                           Assembled 04 November 2010
$ file /usr/bin/gdb
/usr/bin/gdb:   ELF 32-bit LSB executable 80386 Version 1 [FPU], dynamically linked, not stripped, no debugging information available
$ file a 
a:              ELF 64-bit LSB executable AMD64 Version 1, dynamically linked, not stripped
$ gdb a                                 
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.11"...
(gdb) b main
Breakpoint 1 at 0x400e9c: file a.c, line 3.
(gdb) run
Starting program: /tmp/a 

Breakpoint 1, main () at a.c:3
3               printf("hello world !");
(gdb) quit
The program is running.  Exit anyway? (y or n) y
$

然而,如果您仔细观察,就会发现这个 32 位 gdb 在幕后启动了一个 64 位 gdb:

$ truss -f -t execve /usr/bin/gdb a
1793:   execve("/usr/bin/gdb", 0x0804755C, 0x08047568)  argc = 2
1793:   execve("/usr/bin/amd64/gdb", 0x0804755C, 0x08047568)  argc = 2
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.11"...
(gdb)

无论调试的二进制文件是 32 位还是 64 位,它都会执行此操作。

我仍然认为 Solaris 下调试器与进程交互的方式与大小无关,因此从技术上讲,32 位二进制调试器应该能够调试 64 位程序。

64 位 gdb 能够调试32 位和 64 位二进制文​​件,但 32 位 gdb 无法调试 64 位二进制文​​件。这就是你正在经历的。

Yes. A 32 bit gdb debugs 64 bit binaries fine on Solaris, at least on the latest release.

$ cat /etc/release
                      Oracle Solaris 11 Express snv_151a X86
     Copyright (c) 2010, Oracle and/or its affiliates.  All rights reserved.
                           Assembled 04 November 2010
$ file /usr/bin/gdb
/usr/bin/gdb:   ELF 32-bit LSB executable 80386 Version 1 [FPU], dynamically linked, not stripped, no debugging information available
$ file a 
a:              ELF 64-bit LSB executable AMD64 Version 1, dynamically linked, not stripped
$ gdb a                                 
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.11"...
(gdb) b main
Breakpoint 1 at 0x400e9c: file a.c, line 3.
(gdb) run
Starting program: /tmp/a 

Breakpoint 1, main () at a.c:3
3               printf("hello world !");
(gdb) quit
The program is running.  Exit anyway? (y or n) y
$

However, if you look closer, this 32 gdb is launching a 64 bit gdb under the hood:

$ truss -f -t execve /usr/bin/gdb a
1793:   execve("/usr/bin/gdb", 0x0804755C, 0x08047568)  argc = 2
1793:   execve("/usr/bin/amd64/gdb", 0x0804755C, 0x08047568)  argc = 2
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.11"...
(gdb)

It does it regardless of whether the binary debugged is 32 or 64 bit.

I still think the way a debugger interact with a process under Solaris is size independent so technically, a 32 bit only binary debugger should be able to debug a 64 bit program.

A 64 bit gdb is able to debug both 32 bit and 64 bit binaries but a 32 bit gdb cannot debug 64 bit ones. This is what you are experiencing.

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