先不多说, 看代码:

 

#include <iostream>
#include <cstring>
using namespace std;

void inner(int xx, int yy)
{
	int a = 1;
	int b = 2;
	char *p = NULL;
	memset(p, 0, 1);
}

void middle()
{
	int x = 10;
	int y = 20;
	inner(30, 40);
}

void outer()
{
	int m = 100;
	int n = 200;
	middle();
}

int main()
{
	int s = 3;
	int t = 4;
	outer();
	
	return 0;
}

      编译运行并调试:

 

 

taoge@localhost Desktop> g++ -g main.cpp 
taoge@localhost Desktop> ./a.out 
Segmentation fault (core dumped)
taoge@localhost Desktop> gdb a.out core.8146 
GNU gdb (GDB) Red Hat Enterprise Linux (7.1-29.el6)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/taoge/Desktop/a.out...done.
[New Thread 8146]
Missing separate debuginfo for 
Try: yum --disablerepo='*' --enablerepo='*-debuginfo' install /usr/lib/debug/.build-id/74/d23352fd770753e375bd0caecf375bd77bded5
Reading symbols from /usr/lib/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x009a6935 in __memset_sse2 () from /lib/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.7.el6.i686 libgcc-4.4.4-13.el6.i686 libstdc++-4.4.4-13.el6.i686
(gdb) 
(gdb) 
(gdb) 
(gdb) bt
#0  0x009a6935 in __memset_sse2 () from /lib/libc.so.6
#1  0x080485aa in inner (xx=30, yy=40) at main.cpp:10
#2  0x080485d4 in middle () at main.cpp:17
#3  0x080485ef in outer () at main.cpp:24
#4  0x0804860f in main () at main.cpp:31
(gdb) f 0
#0  0x009a6935 in __memset_sse2 () from /lib/libc.so.6
(gdb) i locals
No symbol table info available.
(gdb) i args
No symbol table info available.
(gdb) i catch
print_frame_label_vars disabled.
(gdb) f 1
#1  0x080485aa in inner (xx=30, yy=40) at main.cpp:10
10		memset(p, 0, 1);
(gdb) i locals
a = 1
b = 2
p = 0x0
(gdb) i args
xx = 30
yy = 40
(gdb) i catch
print_frame_label_vars disabled.
(gdb) 

       无需多说。


 

 


本文转载:CSDN博客