在带有Centos 5的64位计算机上使用32位二进制文​​件的gdb和gdbserver抱怨内存访问或格式不正确的数据 [英] Using gdb and gdbserver with a 32 bit binary on a 64 bit machine with Centos 5 complains about memory access or badly formatted data

查看:393
本文介绍了在带有Centos 5的64位计算机上使用32位二进制文​​件的gdb和gdbserver抱怨内存访问或格式不正确的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



然而,如果我用-m32编译我的Hello World以生成32位二进制文​​件,系统正在编译,那么我不知道如何让gdb和gdbserver正确连接。在我尝试完全升级系统之前,我想我应该把它和你好打交道。根据我如何尝试连接gdb和gdbserver,我要么收到关于格式不正确的寄存器的消息,关于体系结构不匹配的警告或者非法的内存引用。

我似乎没有太多的理解我的编译中-m32的含义是什么,不知道如何启动gdb和gdbserver,或者没有正确的顺序来指定体系结构或文件等。 :(b / b>

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



下面的例子,谢谢你,

Jerry

hello.cpp:

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

}

以下是三次运行:


  1. gdb,set architecture i386 /然后连接到gdbserver => bad architecture

  2. 在gdb中,设置架构i386 / file hello /然后连接到gdbserver =>坏架构
  3. 在gdb中,设置体系结构(错误地)i386:x86-64 / file hello /然后连接到gdbserver =>无法访问内存

或者再详细一点:

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



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

  
$ gdbserver --multi rdev6:2010 hello
过程hello created; pid = 32603
监听端口2010
从主机进行远程调试134.51.26.149
readchar:已获得EOF
远程端已终止连接。 GDBserver将重新打开连接。
听港口2010

在我们的本地:



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




  • 假设它是i386 32位,将archi设置为i386,然后连接
    注意:在gdb端,可执行文件未被指定或加载



  
$ gdb
GNU gdb Fedora(6.8-37.el5)
his GDB被配置为x86_64-redhat-linux-gnu。
(gdb)set archi i386
目标体系结构假定为i386
(gdb)目标扩展远程rdev6:2010
使用rdev6:2010进行远程调试
警告:所选架构i386与报告的目标架构i386不兼容:x86-64
远程寄存器格式错误:T0506:0000000000000000; 07:b0dcdfff00000000; 10:1018620000000000;线程:7f5b;
here:0000000; 07:b0dcdfff00000000; 10:1018620000000000; thread:7f5b;
尝试通过`file'首先加载可执行文件,
您也可以检查`set / show architecture'。
(gdb)

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




  • 假设它是i386 32位,将archi设置为i386,然后连接
    注意:在gdb端,可执行文件已被加载文件


  
$ gdb
GNU gdb Fedora(6.8-37.el5)
他的GDB被配置为x86_64-redhat-linux-gnu。
(gdb)set archi i386
目标体系结构假定为i386
(gdb)文件hello
读取/home/j/hello...done中的符号。
(gdb)target extended-remote rdev6:2010
使用rdev6:2010进行远程调试
警告:选定的架构i386与报告的目标架构不兼容i386:x86-64
远程寄存器格式不正确:T0506:0000000000000000; 07:b0dcdfff00000000; 10:1018620000000000;线程:7f5b;
here:0000000; 07:b0dcdfff00000000; 10:1018620000000000; thread:7f5b;
尝试通过`file'首先加载可执行文件,
您也可以检查`set / show architecture'。
(gdb)sho archi
目标体系结构假设为i386
(gdb)

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




  • 假设(它应该是不正确的)它是i386:x86-64,将archi设置为i386:x86-64,然后连接
    注意:在gdb端,可执行文件具有已加载文件



  
$ gdb
GNU gdb Fedora 6.8-37.el5)
这个GDB被配置为x86_64-redhat-linux-gnu。
(gdb)set archi i386:x86-64
目标体系结构假定为i386:x86-64
(gdb)文件hello
从/ home / j读取符号/hello...done。
(gdb)show archi
假设目标体系结构为i386:x86-64
(gdb)target extended-remote rdev6:2010
使用rdev6进行远程调试:2010
[New Thread 32667]
无法访问地址0x800000008
(gdb)


解决方案

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

  gdbserver / ChangeLog:

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

Biarch支持i386 / amd64 gdbserver。

或者,您可以通过运行

  ./ configure CC ='gcc -m32'

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


I have two identical 64 bit Centos 5 machines, that are networked, and share their /home mount. I compile a simple Hello World program on one, and then I have figured out how to use gdb on one machine to remotely debug it running on the other machine. That seems to work fine when everyone defaults to 64 bitness.

However, if I compile my Hello World with -m32 to generate a 32 bit binary, the way our full up system is being compiled, then I cannot figure out how to get gdb and gdbserver to correctly connect. Before I try it on our full up system, I figure I should get it working with hello. Depending on how I try connecting gdb and gdbserver, I either get messages about badly formatted registers, warnings about architecture mismatches, or illegal memory references.

I seem to have little understanding of what the implications of -m32 are in my compile and no idea of how to start gdb and gdbserver or the right order to specify architecture or files or something. :(

What does it take to use gdb and gdbserver on a 32 bit (-m32) executable on a 64 bit linux box?

Examples below, and thank you,

Jerry

hello.cpp:

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

}

Here are three runs:

  1. In gdb, set architecture i386 / then connect to gdbserver => bad architecture
  2. In gdb, set architecture i386 / file hello / then connect to gdbserver => bad architecture
  3. In gdb, set architecture (incorrectly) i386:x86-64 / file hello / then connect to gdbserver => Cannot access memory

Or in a bit more detail:

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

For each run, the remote gdbserver said:


    $ 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

And on our local:

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

  • Assuming it is i386 32 bit, setting archi to i386, then connecting note: on the gdb side, the executable hasn't been specified or loaded


    $ 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)

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

  • Assuming it is i386 32 bit, setting archi to i386, then connecting note: on the gdb side, the executable has been loaded with file


    $ 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)

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

  • Assuming (which should be incorrect) that it is i386:x86-64, setting archi to i386:x86-64, then connecting note: on the gdb side, the executable has been loaded with file


    $ 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)

解决方案

If you want to debug 32-bit process using 64-bit gdb/gdbserver, you need a newer version of GDB. In particular, you need this:

gdbserver/ChangeLog:

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

        Biarch support for i386/amd64 gdbserver.

Alternatively, you can build gdb/gdbserver you already have from source in 32-bit mode by running

./configure CC='gcc -m32'

and use gdb32/gdbserver32 to debug your processes. I don't see any advantage of doing this though -- newer versions of GDB have many fixes, speedups, and STL pretty printers are nice.

这篇关于在带有Centos 5的64位计算机上使用32位二进制文​​件的gdb和gdbserver抱怨内存访问或格式不正确的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆