在64位计算机上使用带有32位二进制文​​件的gdb和gdbserver,Centos 5抱怨内存访问或格式错误的数据

时间:2010-06-18 22:15:24

标签: gdb 32bit-64bit gdbserver

我有两台相同的64位Centos 5机器,它们是联网的,并共享他们的/ home mount。我在一个上编译了一个简单的Hello World程序,然后我想出了如何在一台机器上使用gdb远程调试它在另一台机器上运行。当每个人都默认为64位时,这似乎工作正常。

但是,如果我使用-m32编译我的Hello World以生成32位二进制文​​件,就像我们的完整系统正在编译的那样,那么我无法弄清楚如何让gdb和gdbserver正确连接。在我对我们的完整系统进行尝试之前,我认为我应该让它与你好。根据我尝试连接gdb和gdbserver的方式,我要么得到有关格式错误的寄存器的消息,有关架构不匹配的警告或非法内存引用。

我似乎很少理解-m32在我的编译中的含义,并且不知道如何启动gdb和gdbserver或正确的命令来指定架构或文件或其他东西。 :(

在64位Linux机器上的32位(-m32)可执行文件上使用gdb和gdbserver需要什么?

以下示例,谢谢,

杰里

HELLO.CPP:

#include <iostream>
int main(int argc, char *argv[])
{
    std::cout << "Hello World." << std::endl;
    return -1;

}

以下是三次运行:

  1. 在gdb中,设置架构i386 /然后连接到gdbserver =&gt;糟糕的建筑
  2. 在gdb中,设置架构i386 / file hello /然后连接到gdbserver =&gt;糟糕的建筑
  3. 在gdb中,设置架构(错误地)i386:x86-64 / file hello /然后连接到gdbserver =&gt;无法访问内存
  4. 或者更详细一点:

    ==============================

    对于每次运行,远程gdbserver说:

    
        $ gdbserver --multi rdev6:2010 hello
        Process hello created; pid = 32603
        Listening on port 2010
        Remote debugging from host 134.51.26.149
        readchar: Got EOF
        Remote side has terminated connection.  GDBserver will reopen the connection.
        Listening on port 2010
    

    在我们当地:

    ==============================

    • 假设它是i386 32位,将archi设置为i386,然后连接 注意:在gdb端,尚未指定或加载可执行文件
    
        $ gdb
        GNU gdb Fedora (6.8-37.el5)
        his GDB was configured as "x86_64-redhat-linux-gnu".
        (gdb) set archi i386
        The target architecture is assumed to be i386
        (gdb) target extended-remote rdev6:2010
        Remote debugging using rdev6:2010
        warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
        Remote register badly formatted: T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
        here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
        Try to load the executable by `file' first,
        you may also check `set/show architecture'.
        (gdb)
    

    ==============================

    • 假设它是i386 32位,将archi设置为i386,然后连接 注意:在gdb端,可执行文件已加载文件
    
        $ gdb
        GNU gdb Fedora (6.8-37.el5)
        his GDB was configured as "x86_64-redhat-linux-gnu".
        (gdb) set archi i386
        The target architecture is assumed to be i386
        (gdb) file hello
        Reading symbols from /home/j/hello...done.
        (gdb) target extended-remote rdev6:2010
        Remote debugging using rdev6:2010
        warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
        Remote register badly formatted: T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
        here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
        Try to load the executable by `file' first,
        you may also check `set/show architecture'.
        (gdb) sho archi
        The target architecture is assumed to be i386
        (gdb)
    

    ==============================

    • 假设(应该是不正确的)它是i386:x86-64,将archi设置为i386:x86-64,然后连接 注意:在gdb端,可执行文件已加载文件
    
        $ gdb
        GNU gdb Fedora (6.8-37.el5)
        This GDB was configured as "x86_64-redhat-linux-gnu".
        (gdb) set archi i386:x86-64
        The target architecture is assumed to be i386:x86-64
        (gdb) file hello
        Reading symbols from /home/j/hello...done.
        (gdb) show archi
        The target architecture is assumed to be i386:x86-64
        (gdb) target extended-remote rdev6:2010
        Remote debugging using rdev6:2010
        [New Thread 32667]
        Cannot access memory at address 0x800000008
        (gdb)
    

1 个答案:

答案 0 :(得分:5)

如果要使用64位gdb / gdbserver调试32位进程,则需要更新版本的GDB。特别是,你需要这个:

gdbserver/ChangeLog:

2009-05-12  Doug Evans  <dje@google.com>

        Biarch support for i386/amd64 gdbserver.

或者,您可以通过运行

在32位模式下从源代码构建gdb / gdbserver
./configure CC='gcc -m32'

并使用gdb32 / gdbserver32来调试您的进程。我没有看到这样做的任何优势 - 更新版本的GDB有很多修复,加速和STL漂亮的打印机都很好。