【问题标题】:gdb fails to run ELF 64-bit program with "File format not recognized"gdb 无法运行“无法识别文件格式”的 ELF 64 位程序
【发布时间】:2010-09-21 11:41:50
【问题描述】:

我正在尝试使用 GDB 进行调试(以查找烦人的段错误)。当我跑步时:

gdb ./filename

从命令行,我收到以下错误:

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

当我执行时:

file /path/executable/

我得到以下信息:

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

我使用的是 GDB 6.1,可执行文件是用 gcc 版本 3.4.6 编译的。

在使用 gdb 方面,我有点不知所措,但据我所知,它应该在这种情况下工作。有什么想法吗?

【问题讨论】:

    标签: c gcc debugging gdb


    【解决方案1】:

    可执行文件是 64 位 (x86-64),调试器是 32 位 (i686-pc-linux) 版本。您可能需要安装 64 位 (x86-64) 版本的调试器。

    【讨论】:

    • 谢谢。我认为这可能是问题所在,结果发现在同一台机器上一个更模糊的路径中安装了 64 位版本的 gdb。
    • 谢谢 - 我在几天前安装了 debian gdb:i386 包和其他一些包后遇到了这个问题,以避免创建 chroot 来构建 i386 版本的 debian 包。
    • 当我无法从 QtCreator 调试 android 应用程序时,这对我来说几乎是一回事。我有 64 位 android 设备时使用了 32 位 gdbserver
    【解决方案2】:

    问题是指“./filename”和“/path/executable”。这些是同一个文件吗?

    如果您要进行事后分析,您将运行:

    gdb executable-file core-file
    

    如果你要忽略核心文件,你会运行:

    gdb executable-file
    

    在这两种情况下,'executable-file' 表示您要调试的二进制文件的路径名。大多数情况下,这实际上是当前目录中的一个简单文件名,因为那里有来自调试版本的源代码。

    在 Solaris 上,64 位版本的 GDB 应该能够调试 32 位和 64 位可执行文件(尽管我在使用最新版本的 GDB 时遇到了一些问题)。我不确定是否相反 - 32 位 GDB 一定可以调试 64 位可执行文件。

    【讨论】:

      【解决方案3】:

      我不确定这是否是您的问题,但我经常遇到这种情况。构建树中的可执行文件,由 make/automake 构建的不是二进制文件,而是脚本,因此您不能将 gdb 与它一起使用。尝试安装应用程序并更改目录,否则 gdb 会尝试调试脚本。

      【讨论】:

      • 这不是我的问题,但这是我检查过的。谢谢您的帮助。据我所知,您可以在可执行文件上运行 file 以查看它是否为二进制文件。
      • @quinmars 你能解释一下Try to install the application and change the directory 的意思吗,我刚刚遇到了同样的问题,在检查文件类型时它是POSIX shell script
      • @HadyElsahar 使用 install 我的意思是 make install。但实际上不需要安装。按照这里的解释:sourceware.org/autobook/autobook/…
      • @quinmars ,当执行libtool --mode=execute gdb th 时,它仍然给出同样的错误。我已将问题移至此处的另一个线程stackoverflow.com/questions/30663780/…
      【解决方案4】:

      您需要检查的是真正的 bfd 库。 binary file descriptor 库是 binutils / gdb 用来实际解析和处理二进制文件(ELF/a.out 等)的库。

      可以通过objdump查看当前支持的平台;

      # objdump -H
      
      objdump: supported targets: elf32-powerpc aixcoff-rs6000 elf32-powerpcle ppcboot elf64-powerpc elf64-powerpcle elf64-little elf64-big elf32-little elf32-big srec symbolsrec tekhex binary ihex
      objdump: supported architectures: rs6000:6000 rs6000:rs1 rs6000:rsc rs6000:rs2 powerpc:common powerpc:common64 powerpc:603 powerpc:EC603e powerpc:604 powerpc:403 powerpc:601 powerpc:620 powerpc:630 powerpc:a35 powerpc:rs64ii powerpc:rs64iii powerpc:7400 powerpc:e500 powerpc:MPC8XX powerpc:750
      
      The following PPC specific disassembler options are supported for use with
      the -M switch:
        booke|booke32|booke64    Disassemble the BookE instructions
        e300                     Disassemble the e300 instructions
        e500|e500x2              Disassemble the e500 instructions
        efs                      Disassemble the EFS instructions
        power4                   Disassemble the Power4 instructions
        power5                   Disassemble the Power5 instructions
        power6                   Disassemble the Power6 instructions
        32                       Do not disassemble 64-bit instructions
        64                       Allow disassembly of 64-bit instructions
      

      【讨论】:

        【解决方案5】:

        您的 GNU 调试器 (gdb) 似乎不支持 x86_64 架构。

        所以尝试LLDB Debugger (lldb) 来替换它。它支持 i386、x86-64 和 ARM 指令集。

        它在 BSD/OS X 上默认可用,在 Linux 上安装通过:sudo apt-get install lldb(或使用yum)。

        请参阅:gdb to lldb command map 页面了解更多信息。

        【讨论】:

          猜你喜欢
          • 2017-09-13
          • 2021-12-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-02-15
          • 1970-01-01
          • 2018-05-18
          • 1970-01-01
          相关资源
          最近更新 更多