[latelee@latelee creadline]$ ./a.out Hit any key to stop autoboot: 0 You abort. NotAShell> print in print ... Segmentation fault (core dumped) (已经产生了coredump文件)
GNU gdb Fedora (6.8-29.fc10) Copyright (C) 2008 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 "i386-redhat-linux-gnu"...
warning: Can't read pathname for load map: Input/output error. Reading symbols from /usr/lib/libstdc++.so.6...done. Loaded symbols for /usr/lib/libstdc++.so.6 Reading symbols from /lib/libm.so.6...done. Loaded symbols for /lib/libm.so.6 Reading symbols from /lib/libgcc_s.so.1...done. Loaded symbols for /lib/libgcc_s.so.1 Reading symbols from /lib/libc.so.6...done. Loaded symbols for /lib/libc.so.6 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 Core was generated by `./a.out'. Program terminated with signal 11, Segmentation fault. [New process 2896] #0 0x0084d626 in memcpy () from /lib/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.9-2.i686 libgcc-4.3.2-7.i386 libstdc++-4.3.2-7.i386 (gdb)
使用bt命令查看函数调用的栈帧(用where命令也可以):
1 2 3 4 5 6 7 8
(gdb) bt #0 0x0084d626 in memcpy () from /lib/libc.so.6 #1 0x08048660 in ?? () #2 0x08049f5d in do_print (argc=1, argv=0xbf8935dc) at my_command.c:31 #3 0x08048cc2 in run_command (cmd=0x804cca0 "print") at command.c:380 #4 0x08049e93 in readline_test () #5 0x08049ee6 in main () (gdb)
latelee@latelee:creadline$ arm_v5t_le-gdb readline_arm readline_arm.core.11.1941 GNU gdb 6.3 (MontaVista 6.3-20.0.66.0600975 2006-07-06) ... Core was generated by `./readline_arm'. Program terminated with signal 11, Segmentation fault. ... #0 0x4020f164 in memcpy () from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/target/lib/libc.so.6 (gdb) bt #0 0x4020f164 in memcpy () from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/target/lib/libc.so.6 #1 0x0000b660 in do_print (argc=1, argv=0xbefffcd0) at my_command.c:242 #2 0x00009574 in run_command (cmd=0x16c64 "print") at command.c:380 #3 0x0000af7c in readline_test () at main.c:78 #4 0x0000b20c in main (argc=1, argv=0xbefffe64) at main.c:139 (gdb) frame 1 #1 0x0000b660 in do_print (argc=1, argv=0xbefffcd0) at my_command.c:242 242 memcpy(p, buf, 5); (gdb)