繁体   English   中英

gdb错误不是可执行格式:无法识别文件格式

[英]gdb error not in executable format: File format not recognized

我试图在Ubuntu 16.04上调试一个简单的“hello world”C ++程序,但是gdb无法识别可执行文件格式。 但是,我能够在命令行上成功运行可执行文件。 这是代码

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

我使用命令编译程序文件TestProject.cpp

g++ -g TestProject.cpp -o hello

然后调试,我给出命令

gdb ./hello

我收到以下错误消息

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
"/home/<home>/./hello": not in executable format: File format not recognized

Ubuntu机器似乎有些东西被破坏了。 因为我能够在另一个Ubuntu 16.04虚拟机上调试相同的程序。

几乎可以肯定ks1322的评论是正确的:

  1. 您已经安装了64位GCC,因此./hello是64位二进制文​​件(使用file ./hello进行确认)。
  2. 您已经安装了仅32位的GDB,因此它不知道如何调试x86_64二进制文件。

修复很简单:安装64位GDB(能够调试32位和64位二进制文​​件), 或者在32位模式下构建hello (使用g++ -m32 ... )。

我在mac os上遇到了同样的问题。 gdb中有一个错误: https//sourceware.org/bugzilla/show_bug.cgi? id = 23746他们的git存储库已经有了修复。 不幸的是,自制软件中的垃圾箱还没有。 所以,我不得不克隆git://sourceware.org/git/binutils-gdb.git,编译它并按照自述文件中的描述进行安装。 我相信这会在ubuntu上解决你的问题。

PS它适用于我的机器,但我必须以root身份运行eclipse:sudo /.../MacOS/eclipse。 否则,我已启动:配置GDB中止配置GDB 因为我不知道如何解决它(

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM