gdb调试之 f 1 , i locals, i args, i catch ------ 并用这些来调试core dump

       先不多说, 看代码:

 

#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) 

       无需多说。


 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值