【发布时间】:2018-09-27 05:13:31
【问题描述】:
我通过brew install gdb获取gdb。
源文件内容为:
#include <cstdio>
int main(){
int a = 10;
for(int i = 0; i< 10; i++){
a += i;
}
printf("%d\n",a);
return 0;
}
这是名为“demo”的可执行文件: https://pan.baidu.com/s/1wg-ffGCYzPGDI77pRxhyaw
我这样编译源文件:
c++ -g -o demo demo.cpp
然后运行 gdb
gdb ./demo
但是,它不能工作。它无法识别可执行文件。
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
我使用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,它显示:
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)
谁能帮帮我?非常感谢!!!
【问题讨论】:
-
你在用什么
gdb?你是如何得到的?你有没有从sourceware.org/gdb/download下载它的源代码并编译它?如果是,您是如何配置的?如果否,则在gdb中显示show configuration的输出。同样对于您的c++(是GCC,Clang,....)?显示c++ -v的输出。你能在同一个终端运行./demo吗?file ./demo的输出是什么? -
可能显示
demo.cpp的来源(或将其设为很小的minimal reproducible example)。首先尝试使用 hello-world 之类的示例 -
这听起来很像sourceware.org/bugzilla/show_bug.cgi?id=13157,只是在 8.2 中已修复。另请注意,有一些 macOS 修复程序仅在 git master 上 - 至少从 High Sierra 开始需要它们。
-
另外,我认为在 gdb 上工作的任何人都没有尝试过 Mojave。提交一个 gdb 错误会很棒。更好的是在失败的地方附加一个“hello world”类型的可执行文件。
-
gdb 8.0 和 8.2 都试过了,同样的问题