Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb fails to run ELF 64-bit program with "File format not recognized"

Tags:

c

gcc

debugging

gdb

I'm trying to use GDB to debug (to find an annoying segfault). When I run:

gdb ./filename

from the command line, I get the following error:

This GDB was configured as "i686-pc-linux-
gnu"..."/path/exec": not in executable 
format: File format not recognized

When I execute:

file /path/executable/

I get the following info:

 ELF 64-bit LSB executable, AMD x86-64,
 version 1 (SYSV), for GNU/Linux 2.4.0, 
 dynamically linked (uses shared libs), not stripped

I am using GDB 6.1, and the executable is compiled with gcc version 3.4.6.

I'm a little out of my water in terms of using gdb, but as far as I can tell it should be working in this instance. Any ideas what's going wrong?

like image 946
pbh101 Avatar asked Nov 09 '08 01:11

pbh101


People also ask

How ELF file is executed?

An ELF file consists of zero or more segments, and describe how to create a process/memory image for runtime execution. When the kernel sees these segments, it uses them to map them into virtual address space, using the mmap(2) system call. In other words, it converts predefined instructions into a memory image.

How do I read an ELF file?

gcc produces executable files in the ELF file format. you can use readelf and objdump to read parts of an elf file. You can also use 'hexdump filename' to get a hexdump of the contents of a binary file (this is likely only useful if you like reading machine code or you are writing an assembler).

What kind of file is ELF?

An ELF file is an executable file format for the Linux and Unix platforms. Its known file extensions are . axf, . bin, .

What is an ELF file embedded?

Whenever we compile any code, the output that we get is an executable file, which we generally don't bother about. We execute it on our desired target. If it is an embedded system, we flash it to the target device and run it. Usually, this executable file is the ELF (Executable and Linkable Format) file.


3 Answers

The executable is 64-bit (x86-64) and the debugger is a 32 bit (i686-pc-linux) build. You may need to install a 64-bit (x86-64) version of the debugger.

like image 122
ConcernedOfTunbridgeWells Avatar answered Nov 02 '22 00:11

ConcernedOfTunbridgeWells


I'm not sure if this is your problem, but I faced this situation very often. The executable in the build tree, build by make/automake is not a binary, but a script, so you cannot use gdb with it. Try to install the application and change the directory, because else gdb tries to debug the script.

like image 5
quinmars Avatar answered Nov 01 '22 22:11

quinmars


The question refers to "./filename" and to "/path/executable". Are these the same file?

If you are doing a post-mortem analysis, you would run:

gdb executable-file core-file

If you are going to ignore the core file, you would run:

gdb executable-file

In both cases, 'executable-file' means a pathname to the binary you want to debug. Most usually, that is actually a simple filename in the current directory, since you have the source code from your debug build there.

On Solaris, a 64-bit build of GDB is supposed to be able to debug both 32-bit and 64-bit executables (though I've had some issues with recent versions of GDB). I'm not sure of the converse - that a 32-bit GDB can necessarily debug 64-bit executables.

like image 4
Jonathan Leffler Avatar answered Nov 01 '22 23:11

Jonathan Leffler