【问题标题】:gdb error not in executable format: File format not recognizedgdb 错误不是可执行格式:文件格式无法识别
【发布时间】:2018-05-18 07:00:01
【问题描述】:

我正在尝试在 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 虚拟机上调试相同的程序。

【问题讨论】:

  • Ubuntu 机器似乎有问题。因为我可以在另一个 Ubuntu 16.04 虚拟机上调试相同的程序。
  • file ./hello 给出了什么?
  • This GDB was configured as "i686-linux-gnu". 您可能正在尝试使用 32 位配置的 gdb 调试 64 位可执行文件。尝试构建 32 位可执行文件:g++ -m32 -g TestProject.cpp -o hello 或安装 64 位配置的 gdb。

标签: c++ gdb ubuntu-16.04


【解决方案1】:

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

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

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

【讨论】:

  • 自我注意:不要仅仅因为 Github 允许你在两者之间共享代码而在 Mac 上编译然后尝试在 Linux 上运行它!
  • 第二个要点对我有用
【解决方案2】:

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

附:它可以在我的机器上运行,但我必须以 root 身份运行 eclipse: 须藤/.../MacOS/eclipse。否则,我有Launching : Configuring GDB Aborting configuring GDB。因为我不知道如何解决它(

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    相关资源
    最近更新 更多