gdb 8.2 在 macOS Mojave 10.14 上无法识别可执行文件 [英] gdb 8.2 can't recognized executable file on macOS Mojave 10.14
问题描述
我通过 brew install gdb
获得 gdb.
I get gdb by brew install gdb
.
源文件内容为:
#include <cstdio>
int main(){
int a = 10;
for(int i = 0; i< 10; i++){
a += i;
}
printf("%d
",a);
return 0;
}
这是名为demo"的可执行文件:https://pan.baidu.com/s/1wg-ffGCYzPGDI77pRxhyaw
Here is the executable file named 'demo': https://pan.baidu.com/s/1wg-ffGCYzPGDI77pRxhyaw
我这样编译源文件:
c++ -g -o demo demo.cpp
然后运行 gdb
gdb ./demo
但是,它不能工作.它无法识别可执行文件.
But, it can't work. It can't recognized the executable file.
GNU gdb (GDB) 8.2
Copyright (C) 2018 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-darwin18.0.0".
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"...
BFD: /Users/xxx/Codes/demo: unknown load command 0x32
BFD: /Users/xxx/Codes/demo: unknown load command 0x32
"/Users/xxx/Codes/demo": not in executable format: file format not recognized
我使用 file demo
,它的输出是 demo: Mach-O 64-bit executable x86_64
I use file demo
,its ouput is demo: Mach-O 64-bit executable x86_64
我使用file ./demo
,它的输出是./demo: Mach-O 64-bit executable x86_64
输入c++ -v
,输出为:
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
运行./demo
,其输出为55
在gdb中输入show configuration
,显示:
run ./demo
,its output is 55
type show configuration
in gdb,it shows:
This GDB was configured as follows:
configure --host=x86_64-apple-darwin18.0.0 --target=x86_64-apple-darwin18.0.0
--with-auto-load-dir=:${prefix}/share/auto-load
--with-auto-load-safe-path=:${prefix}/share/auto-load
--with-expat
--with-gdb-datadir=/usr/local/Cellar/gdb/8.2/share/gdb (relocatable)
--with-jit-reader-dir=/usr/local/Cellar/gdb/8.2/lib/gdb (relocatable)
--without-libunwind-ia64
--without-lzma
--without-babeltrace
--without-intel-pt
--disable-libmcheck
--without-mpfr
--with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
--without-guile
--with-separate-debug-dir=/usr/local/Cellar/gdb/8.2/lib/debug (relocatable)
谁能帮帮我?非常感谢!!!
Who can help me ? Thank you very much !!!
推荐答案
问题是 clang-1000.11.45.2
与 Apple LLVM version 10.0.0
一起分发增加了一个名为 LC_BUILD_VERSION
的 o-mach 可执行文件的新加载命令.
The problem is that clang-1000.11.45.2
distributed with Apple LLVM version 10.0.0
adds a new load command to o-mach executables named LC_BUILD_VERSION
.
$ otool -l test.o
...
Load command 1
cmd LC_BUILD_VERSION
cmdsize 24
platform macos
sdk n/a
minos 10.14
ntools 0
...
来自苹果来源:
/*
* The build_version_command contains the min OS version on which this
* binary was built to run for its platform. The list of known platforms and
* tool values following it.
*/
所以目前 bfd
(gdb 用来操作可执行文件的程序)无法解释此命令并返回错误.
So currently bfd
(the program used by gdb to manipulate executables) is not able to interpret this command and returns the error.
作为一个临时解决方案,您可以编辑 bfd
源代码提供的 gdb
.
As a temporary solution, you can edit the bfd
sources code provides with gdb
.
首先,从 mirrors下载 gdb-8.0.1
源代码一个>.然后在 gdb-8.0.1/bfd/mach-o.c
的 4649
行添加以下代码:
First, download gdb-8.0.1
sources from mirrors. Then add to gdb-8.0.1/bfd/mach-o.c
the following code at line 4649
:
case BFD_MACH_O_LC_BUILD_VERSION:
break;
最后在 gdb-8.0.1/include/mach-o/loader.h
的第 189
行:
Finally inside gdb-8.0.1/include/mach-o/loader.h
at line 189
:
BFD_MACH_O_LC_BUILD_VERSION = 0x32
别忘了在BFD_MACH_O_LC_VERSION_MIN_WATCHOS = 0x30
之后的第188行末尾添加一个,
.
Don't forget to add a ,
at the end of the line 188 after BFD_MACH_O_LC_VERSION_MIN_WATCHOS = 0x30
).
然后按照 README 中的说明处理经典的 gdb
编译:
Then process a classic gdb
compilation following instructions from the README :
run the ``configure'' script here, e.g.:
./configure
make
To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
make install
别忘了在 这里 签署 gdb
.如果仍然出现 (os/kern) failure (0x5) 错误,只需运行 sudo gdb
.
Don't forget to sign gdb
as explain here.
If you still get the (os/kern) failure (0x5) error, just run sudo gdb
.
这是等待 GNU 团队修复的临时解决方案.
This is a temporary solution in order to wait for a fix from GNU team.
编辑
Binutils-gdb
已更新,这些更改现已在提交 fc7b364.
Binutils-gdb
has been updated, these changes are now implemented in commit fc7b364.
希望对您有所帮助.
这篇关于gdb 8.2 在 macOS Mojave 10.14 上无法识别可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!