2. ./hello
[indou@std tstPrg027]$ ./hello
セグメンテーション違反です
[indou@std tstPrg027]$
3. gdb hello core.10123
[indou@std tstPrg027]$ gdb hello core.10123
GNU gdb Red Hat Linux (6.3.0.0-1.153.el4_6.2rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db
library "/lib/tls/libthread_db.so.1".
Core was generated by `./hello'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0 0x00ae34a6 in strcpy () from /lib/tls/libc.so.6 # <- strcpyで止まっている。
(gdb) where # <- 関数呼び出しの状態を確認
#0 0x00ae34a6 in strcpy () from /lib/tls/libc.so.6
#1 0x080483d3 in main (argc=1, argv=0xbfe992b4) at hello.c:6
(gdb) up # <- strcpyの中で止まっているので、-gオプション付きでコンパイルされてないため、一つ上へ
#1 0x080483d3 in main (argc=1, argv=0xbfe992b4) at hello.c:6
6 strcpy(ptr, "hello, world\n");
(gdb) l 6
1 #include
2 #include
3 #include
4 int main(int argc, char *argv[]) {
5 char *ptr = NULL;
6 strcpy(ptr, "hello, world\n");
7 printf("%s", ptr);
8 return EXIT_SUCCESS;
9 }
(gdb) p ptr # <- NULLポインタへの書き込み
$1 = 0x0
(gdb) quit
[indou@std tstPrg027]$
0 件のコメント:
コメントを投稿