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

时间:2011-02-10 09:51:26

标签: gdb solaris 32bit-64bit

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

2 个答案:

答案 0 :(得分:2)

上面的答案是不正确的。您需要一个64位调试器来调试64位进程。这正是gdb在幕后分配64位副本的原因。

答案 1 :(得分:0)

是。 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位二进制文​​件。这就是你所经历的。