我通过 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位可执行文件 x86_64
我使用file ./demo
命令,它的输出是./demo: Mach-O 64位可执行文件 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
版本?你是如何获取它的?你是否从 https://sourceware.org/gdb/download/ 下载了它的源代码并编译了它?如果是,你是如何配置它的?如果不是,请在gdb
中显示show configuration
的输出。同样的,你的c++
是什么(是 GCC,Clang,还是其他)?请显示c++ -v
的输出。你能在同一个终端中运行./demo
吗?file ./demo
的输出是什么? - Basile Starynkevitchdemo.cpp
的源代码(或者将其变成一个微型[MCVE])。首先尝试使用一个类似于“hello-world”的例子。 - Basile Starynkevitchlldb
(它可以正常工作)。 - Xiaoyu Chen