1、gcc -g -o demo demo.c
2、执行 gdb ./demo 之后
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 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-linux-gnu".
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"...
Reading symbols from ./demo...done.
(gdb)
3、输入 run 执行
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400981 in DFS (g=..., v=-1) at demo.cpp:95
95 if(!visited[val]){
(gdb)
4、输入quit 命令 退出