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

来源:互联网 发布:国内gis软件 编辑:程序博客网 时间:2024/06/01 23:10

       先不多说, 看代码:

#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/d23352fd770753e375bd0caecf375bd77bded5Reading symbols from /usr/lib/libstdc++.so.6...(no debugging symbols found)...done.Loaded symbols for /usr/lib/libstdc++.so.6Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done.Loaded symbols for /lib/libm.so.6Reading symbols from /lib/libgcc_s.so.1...(no debugging symbols found)...done.Loaded symbols for /lib/libgcc_s.so.1Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.Loaded symbols for /lib/libc.so.6Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.Loaded symbols for /lib/ld-linux.so.2Core was generated by `./a.out'.Program terminated with signal 11, Segmentation fault.#0  0x009a6935 in __memset_sse2 () from /lib/libc.so.6Missing 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 localsNo symbol table info available.(gdb) i argsNo symbol table info available.(gdb) i catchprint_frame_label_vars disabled.(gdb) f 1#1  0x080485aa in inner (xx=30, yy=40) at main.cpp:1010memset(p, 0, 1);(gdb) i localsa = 1b = 2p = 0x0(gdb) i argsxx = 30yy = 40(gdb) i catchprint_frame_label_vars disabled.(gdb) 
       无需多说。



0 0
原创粉丝点击