$ 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二进制文件会失败?
答案 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
如果您希望调试合并的可执行文件,可以尝试使用LLDB或Apple version of gdb。
答案 1 :(得分:3)
作为OP commented,使用Apple的gdb将解决问题。
以下是在OS 10.9上从源代码构建Apple gdb 6.3.50.20050815-cvs的说明:
注意:您需要安装Xcode并设置构建环境。如果您安装了Homebrew,请运行brew doctor
以查看“您的系统是否已准备好酿造。”
从以下网址下载gdb-1822源代码tarball:http://opensource.apple.com/tarballs/gdb/gdb-1822.tar.gz
将其解压缩到临时目录中。打开终端,cd
进入gdb-1822/src
。
运行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)
运行make:
make make install
按照https://sourceware.org/gdb/wiki/BuildingOnDarwin#Creating_a_certificate上的说明创建gdb-cert代码签名证书。
cd
加入$HOME/.local/stow/gdb-1822/bin
并签署gdb
可执行文件:
codesign -s gdb-cert gdb
cd
进入$HOME/.local/stow
和stow gdb-1822
文件夹:
stow gdb-1822
将$HOME/.local/bin
添加到PATH
,然后重启终端,或clear Bash's cache到gdb
的位置:
hash -d gdb