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

gdb error not in executable format: File format not recognized(gdb 错误不是可执行格式:文件格式无法识别)
本文介绍了gdb 错误不是可执行格式:文件格式无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to debug a simple "hello world" C++ program on Ubuntu 16.04 but gdb is not able to recognize the executable file format. However, I am able to successfully run the executable on the command line. Here is the code

#include <iostream>
using namespace std;

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

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

I compile the program file TestProject.cpp using the command

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 虚拟机上调试相同的程序.

Something seems to be corrupt with the Ubuntu machine. Because I am able to debug the same program on another Ubuntu 16.04 virtual machine.

推荐答案

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

It is almost certain that ks1322's comment is correct one:

  1. 您已安装 64 位 GCC,因此您的 ./hello 是 64 位二进制文​​件(使用 file ./hello 确认).
  2. 您只安装了 32 位 GDB,因此它不知道如何调试 x86_64 二进制文件.
  1. You've installed a 64-bit GCC, so your ./hello is a 64-bit binary (use file ./hello to confirm).
  2. You've installed a 32-bit only GDB, so it doesn't know how to debug x86_64 binaries.

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

The fix is simple: install 64-bit GDB (which is capable of debugging both 32 and 64-bit binaries), or build hello in 32-bit mode (with g++ -m32 ...).

这篇关于gdb 错误不是可执行格式:文件格式无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)