以下是我遵循的步骤:
使用 brew install gdb 安装 GDB。并按照 https://sourceware.org/gdb/wiki/PermissionsDarwin 上的说明在我的 macOS 上安装 gdb-cert
奔跑
g++ -ggdb -Wall -o main main.cc
输出:产生的主要
./main
输出:
\`cha@cent gdb\_ % ./main
Creating Node, 1 are in existence right now
Creating Node, 2 are in existence right now
Creating Node, 3 are in existence right now
Creating Node, 4 are in existence right now
The fully created list is:
4
3
2
1
Now removing elements:
Creating Node, 5 are in existence right now
Destroying Node, 4 are in existence right now
4
3
2
1
zsh: segmentation fault ./main\`
gdb main
输出:
\`GNU gdb (GDB) 13.1
Copyright (C) 2023 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-darwin22.3.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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"...
Reading symbols from main...
Reading symbols from /Users/cha/gdb\_/main.dSYM/Contents/Resources/DWARF/main...
\
(gdb) run
输出:
Starting program: /Users/cha/gdb_/main
[New Thread 0x2003 of process 12358]
[New Thread 0x2803 of process 12358]
During startup program terminated with signal SIGKILL, Killed.`
预期输出:
(gdb) run
Starting program: /home/cec/s/a/agg1/.www-docs/tutorial/main
Creating Node, 1 are in existence right now
Creating Node, 2 are in existence right now
Creating Node, 3 are in existence right now
Creating Node, 4 are in existence right now
The fully created list is:
4
3
2
1
Now removing elements:
Creating Node, 5 are in existence right now
Destroying Node, 4 are in existence right now
4
3
2
1
Program received signal SIGSEGV, Segmentation fault.
Node<int>::next (this=0x0) at main.cc:28
28 Node<T>* next () const { return next_; }`
系统规格:MacOS Ventura 13.0终端
目录中的文件
cha@cent gdb\_ % ls
Makefile main main.cc main.dSYM