Script started on Tue Apr 13 13:45:44 1999 cs102@fac44 [51] : g++ -g error.C cs102@fac44 [52] : a.out Segmentation fault cs102@fac44 [53] : cat error.C #include struct SomeInts { int i1; int i2; int i3; }; void Die() { int a[100]; int i; i = 0; for (i=0; i >= 0; i++) a[i] = i; } main() { int i = 7; SomeInts *ptr = new SomeInts; ptr->i1 = 10; ptr->i2 = 9; ptr->i3 = 8; i = 7; Die(); } cs102@fac44 [54] : gdb a.out GDB is free software and you are welcome to 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. GDB 4.16 (sparc-sun-solaris2.6), Copyright 1996 Free Software Foundation, Inc... (gdb) run Starting program: /home/cs102/public_html/Brad/Examples/a.out warning: Unable to find dynamic linker breakpoint function. warning: GDB will be unable to debug shared library initializers warning: and track explicitly loaded dynamic code. Program received signal SIGSEGV, Segmentation fault. 0x1059c in Die () at error.C:16 16 a[i] = i; (gdb) where #0 0x1059c in Die () at error.C:16 #1 0x10610 in main () at error.C:29 #2 0x104ec in _start () Cannot access memory at address 0xcc. (gdb) list 11 int a[100]; 12 int i; 13 14 i = 0; 15 for (i=0; i >= 0; i++) 16 a[i] = i; 17 } 18 19 main() 20 { (gdb) print i $1 = 722 (gdb) print a $2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99} (gdb) where #0 0x1059c in Die () at error.C:16 #1 0x10610 in main () at error.C:29 #2 0x104ec in _start () #3 0x9d in ?? () Cannot access memory at address 0xd0. (gdb) up #1 0x10610 in main () at error.C:29 29 Die(); (gdb) list 24 ptr->i1 = 10; 25 ptr->i2 = 9; 26 ptr->i3 = 8; 27 28 i = 7; 29 Die(); 30 } (gdb) print i $3 = 129 (gdb) print ptr $4 = (SomeInts *) 0x80 (gdb) quit The program is running. Quit anyway (and kill it)? (y or n) y cs102@fac44 [55] : gdb a.out GDB is free software and you are welcome to 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. GDB 4.16 (sparc-sun-solaris2.6), Copyright 1996 Free Software Foundation, Inc... (gdb) bra eak Die Breakpoint 1 at 0x10564: file error.C, line 14. (gdb) break error.C:14 Note: breakpoint 1 also set at pc 0x10564. Breakpoint 2 at 0x10564: file error.C, line 14. (gdb) break error.C:28 Breakpoint 3 at 0x10600: file error.C, line 28. (gdb) run Starting program: /home/cs102/public_html/Brad/Examples/a.out warning: Unable to find dynamic linker breakpoint function. warning: GDB will be unable to debug shared library initializers warning: and track explicitly loaded dynamic code. Breakpoint 3, main () at error.C:28 28 i = 7; (gdb) list 23 24 ptr->i1 = 10; 25 ptr->i2 = 9; 26 ptr->i3 = 8; 27 28 i = 7; 29 Die(); 30 } (gdb) print ptr $1 = (SomeInts *) 0x208c8 (gdb) print *ptr $2 = {i1 = 10, i2 = 9, i3 = 8} (gdb) next 29 Die(); (gdb) next Breakpoint 1, Die () at error.C:14 14 i = 0; (gdb) list 9 void Die() 10 { 11 int a[100]; 12 int i; 13 14 i = 0; 15 for (i=0; i >= 0; i++) 16 a[i] = i; 17 } 18 (gdb) next 15 for (i=0; i >= 0; i++) (gdb) next 16 a[i] = i; (gdb) next Program received signal SIGSEGV, Segmentation fault. 0x1059c in Die () at error.C:16 16 a[i] = i; (gdb) quit The program is running. Quit anyway (and kill it)? (y or n) y cs102@fac44 [56] : exit exit script done on Tue Apr 13 14:02:51 1999