Ash*_*dey 12 c++ gdb ubuntu-16.04
我试图在Ubuntu 16.04上调试一个简单的"hello world"C++程序,但是gdb无法识别可执行文件格式.但是,我能够在命令行上成功运行可执行文件.这是代码
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用命令编译程序文件TestProject.cpp
g++ -g TestProject.cpp -o hello
Run Code Online (Sandbox Code Playgroud)
然后调试,我给出命令
gdb ./hello
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息
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
Run Code Online (Sandbox Code Playgroud)
Ubuntu机器似乎有些东西被破坏了.因为我能够在另一个Ubuntu 16.04虚拟机上调试相同的程序.
这是几乎可以肯定,ks1322的评论是正确的:
./hello是64位二进制文件(用于file ./hello确认).x86_64二进制文件.修复很简单:安装64位GDB(能够调试32位和64位二进制文件),或者构建hello32位模式(带g++ -m32 ...).
小智 7
我在 mac os 上遇到了同样的问题。gdb 中有一个错误:https : //sourceware.org/bugzilla/show_bug.cgi? id =23746 他们的 git 存储库已经修复了。不幸的是,自制软件中的垃圾箱还没有。所以,我不得不 git clone git://sourceware.org/git/binutils-gdb.git,编译它并按照自述文件中的描述进行安装。我相信这会在 ubuntu 上解决您的问题。
PS 它可以在我的机器上运行,但我必须以 root 身份运行 eclipse:sudo /.../MacOS/eclipse。否则,我将启动:配置 GDB 中止配置 GDB。因为我不知道如何解决它(