mac 10.9上的gdb失败,"不是可执行格式:文件格式无法识别"适用于32 + 64拱

时间:2013-12-12 20:40:32

标签: macos g++ gdb

$ file app
app: Mach-O universal binary with 2 architectures
app (for architecture i386):    Mach-O executable i386
app (for architecture x86_64):  Mach-O 64-bit executable x86_64

$ gdb app
GNU gdb (GDB) 7.6
Copyright (C) 2013 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 "x86_64-apple-darwin13.0.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
"app": not in executable format: File format not recognized


$ file test
test: Mach-O 64-bit executable x86_64

$ gdb test
GNU gdb (GDB) 7.6
Copyright (C) 2013 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 "x86_64-apple-darwin13.0.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /Users/dmulder/test...Reading symbols from /Users/dmulder/test.dSYM/Contents/Resources/DWARF/test...done.
done.

为什么64位二进制文​​件会成功,但64 + 32二进制文件会失败?

2 个答案:

答案 0 :(得分:15)

不幸的是,非Apple版本的GNU gdb目前无法调试通用(或“胖”)二进制文件(包含32位和64位可执行文件的二进制文件)。

一种选择是使用lipo提取单个体系结构并在其上运行gdb:

lipo -thin x86_64 -output app-x86_64 ./app

lipo -thin i386 -output app-i386 ./app

如果您希望调试合并的可执行文件,可以尝试使用LLDBApple version of gdb

答案 1 :(得分:3)

作为OP commented,使用Apple的gdb将解决问题。

以下是在OS 10.9上从源代码构建Apple gdb 6.3.50.20050815-cvs的说明:

注意:您需要安装Xcode并设置构建环境。如果您安装了Homebrew,请运行brew doctor以查看“您的系统是否已准备好酿造。”

  1. 从以下网址下载gdb-1822源代码tarball:http://opensource.apple.com/tarballs/gdb/gdb-1822.tar.gz

  2. 将其解压缩到临时目录中。打开终端,cd进入gdb-1822/src

  3. 运行configure脚本:

    ./configure --prefix="$HOME/.local/stow/gdb-1822" --disable-debug --disable-dependency-tracking --with-system-readline
    

    (最后三个配置参数来自homebrew-dupes公式:https://github.com/Homebrew/homebrew-dupes/blob/master/gdb.rb

  4. 运行make:

    make
    make install
    
  5. 按照https://sourceware.org/gdb/wiki/BuildingOnDarwin#Creating_a_certificate上的说明创建gdb-cert代码签名证书。

  6. cd加入$HOME/.local/stow/gdb-1822/bin并签署gdb可执行文件:

    codesign -s gdb-cert gdb
    
  7. cd进入$HOME/.local/stowstow gdb-1822文件夹:

    stow gdb-1822
    
  8. $HOME/.local/bin添加到PATH,然后重启终端,或clear Bash's cachegdb的位置:

    hash -d gdb