gdb-fout niet in uitvoerbaar formaat: bestandsformaat niet herkend

Ik probeer een eenvoudig “hallo wereld” C++-programma op Ubuntu 16.04 te debuggen, maar gdb kan het uitvoerbare bestandsformaat niet herkennen. Ik kan het uitvoerbare bestand echter met succes uitvoeren op de opdrachtregel.
Hier is de code

#include <iostream>
using namespace std;
int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

Ik compileer het programmabestand TestProject.cpp met het commando

g++ -g TestProject.cpp -o hello

Om vervolgens te debuggen, geef ik het commando

gdb ./hello

Ik krijg de volgende foutmelding

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

Er lijkt beschadigd te zijn met de Ubuntu-machine. Omdat ik hetzelfde programma kan debuggen op een andere Ubuntu 16.04-virtuele machine.


Antwoord 1, Autoriteit 100%

Het is Bijna Bepaalt dat de opmerking van KS1322 correct is:

  1. U hebt een 64-bit GCC geïnstalleerd, dus uw ./hellois een 64-bits binair (gebruik file ./helloom te bevestigen).
  2. U hebt een GDB van 32-bits geïnstalleerd, dus het weet niet hoe u x86_64binaries wilt debuggen.

De fix is ​​eenvoudig: installeer 64-bit GDB (dat in staat is om zowel 32 als 64-bits binaries te debuggen), of build helloin een 32-bits modus (met g++ -m32 ...).


Antwoord 2, Autoriteit 47%

Ik had hetzelfde probleem op Mac OS.
Er is een bug in GDB: https://sourceware.org/bugzilla/show_bug.cgi? ID = 23746
Hun Git Repository heeft de oplossing al gehad. Helaas hebben de bakken in Homebrew het nog niet gehad. Dus, ik moest kloon git geven: //sourceware.org/git/binutils-gdb.git, gecompileerd en geïnstalleerd zoals beschreven in het README-bestand.
Ik geloof wel dat dit de jouwe op Ubuntu zal repareren.

P.S. Het werkt op mijn machine, maar ik moet Eclipse als root uitvoeren:
sudo /…/macos/eclipse. Anders heb ik Lancering: GDB configureren Conforteren GDB . Oorzaak, ik weet niet hoe ik het moet oplossen (

Other episodes