Script started on Fri 30 Jan 2009 10:52:12 AM PST ]0;perkins@localhost:~/cse303[?1034h[perkins@localhost cse303]$ ls -l total 324 -rwxrwxr-x 1 perkins perkins 6792 2009-01-30 09:41 array1 -rwx------ 1 perkins perkins 612 2008-04-15 21:11 array1.c -rwx------ 1 perkins perkins 798 2008-04-15 21:14 array2.c -rwx------ 1 perkins perkins 691 2008-04-15 21:17 array3.c -rw-rw-r-- 1 perkins perkins 32187 2009-01-29 17:22 compiler_complaint.png -rw-rw-r-- 1 perkins perkins 0 2009-01-30 10:52 gdb.demo -rw-rw-r-- 1 perkins perkins 215 2009-01-29 13:41 hello.c -rw-rw-r-- 1 perkins perkins 14529 2009-01-30 10:36 hello.e -rw-rw-r-- 1 perkins perkins 64795 2009-01-26 18:18 lec10.pdf -rw-rw-r-- 1 perkins perkins 56424 2009-01-28 17:25 lec15.pdf drwxrwxr-x 3 perkins perkins 4096 2009-01-29 13:55 old -rw-rw-r-- 1 perkins perkins 84499 2009-01-08 14:43 real_programmers.png -rw-rw-r-- 1 perkins perkins 21570 2009-01-28 09:50 reminders.odp -rw-rw-r-- 1 perkins perkins 1300 2009-01-29 11:48 reverse.c -rw-r--r-- 1 perkins perkins 834 2007-10-17 13:34 structs.c ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gcc -Wall -g -o helloarray1 iarray1.c ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb array1 [?1034hGNU gdb Fedora (6.8-23.fc9) Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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"... (gdb) break zero Breakpoint 1 at 0x80483fa: file array1.c, line 12. (gdb) run Starting program: /home/perkins/cse303/array1 17 42 37 303 416 Breakpoint 1, zero (a=0xbfd44130, len=5) at array1.c:12 12 for (k = 0; k < len; k++) { (gdb) list 7 #include 8 9 /* Zero out a[0..len-1]. */ 10 void zero(int a[], int len) { 11 int k; 12 for (k = 0; k < len; k++) { 13 a[k] = 0; 14 } 15 } 16 (gdb) p len $1 = 5 (gdb) p k $2 = 5 (gdb) p a $3 = (int *) 0xbfd44130 (gdb) p a[0] $4 = 17 (gdb) p* *a $5 = 17 (gdb) p a[1] $6 = 42 (gdb) p *(a+1) $7 = 42 (gdb) p a $8 = (int *) 0xbfd44130 (gdb) p a+1 $9 = (int *) 0xbfd44134 (gdb) s 13 a[k] = 0; (gdb) s 12 for (k = 0; k < len; k++) { (gdb) s 13 a[k] = 0; (gdb) s 12 for (k = 0; k < len; k++) { (gdb) s 13 a[k] = 0; (gdb) p k $10 = 2 (gdb) p a[0] $11 = 0 (gdb) p a[1] $12 = 0 (gdb) p a[2] $13 = 37 (gdb) list 8 9 /* Zero out a[0..len-1]. */ 10 void zero(int a[], int len) { 11 int k; 12 for (k = 0; k < len; k++) { 13 a[k] = 0; 14 } 15 } 16 17 /* Print the contents of a[0..len-1] on one line */ (gdb) p k $14 = 2 (gdb) p &k $15 = (int *) 0xbfd44104 (gdb) runc Continuing. 0 0 0 0 0 Program exited normally. (gdb) help List of classes of commands: aliases -- Aliases of other commands breakpoints -- Making program stop at certain points data -- Examining data files -- Specifying and examining files internals -- Maintenance commands obscure -- Obscure features running -- Running the program stack -- Examining the stack status -- Status inquiries support -- Support facilities tracepoints -- Tracing of program execution without stopping the program user-defined -- User-defined commands Type "help" followed by a class name for a list of commands in that class. Type "help all" for the list of all commands. Type "help" followed by command name for full documentation. Type "apropos word" to search for commands related to "word". Command name abbreviations are allowed if unambiguous. (gdb) help print Print value of expression EXP. Variables accessible are those of the lexical environment of the selected stack frame, plus all those whose scope is global or an entire file. $NUM gets previous value number NUM. $ and $$ are the last two values. $$NUM refers to NUM'th value back from the last one. Names starting with $ refer to registers (with the values they would have if the program were to return to the stack frame now selected, restoring all registers saved by frames farther in) or else to debugger "convenience" variables (any such name not a known register). Use assignment expressions to give values to convenience variables. {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP. @ is a binary operator for treating consecutive data objects anywhere in memory as an array. FOO@NUM gives an array whose first element is FOO, whose second element is stored in the space following where FOO is stored, etc. FOO must be an expression whose value resides in memory. EXP may be preceded with /FMT, where FMT is a format letter but no count or size letter (see "x" command). (gdb) quit ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ ls -l total 328 -rwxrwxr-x 1 perkins perkins 6792 2009-01-30 11:03 array1 -rwx------ 1 perkins perkins 612 2008-04-15 21:11 array1.c -rwx------ 1 perkins perkins 798 2008-04-15 21:14 array2.c -rwx------ 1 perkins perkins 691 2008-04-15 21:17 array3.c -rw-rw-r-- 1 perkins perkins 32187 2009-01-29 17:22 compiler_complaint.png -rw-rw-r-- 1 perkins perkins 4096 2009-01-30 11:12 gdb.demo -rw-rw-r-- 1 perkins perkins 215 2009-01-29 13:41 hello.c -rw-rw-r-- 1 perkins perkins 14529 2009-01-30 10:36 hello.e -rw-rw-r-- 1 perkins perkins 64795 2009-01-26 18:18 lec10.pdf -rw-rw-r-- 1 perkins perkins 56424 2009-01-28 17:25 lec15.pdf drwxrwxr-x 3 perkins perkins 4096 2009-01-29 13:55 old -rw-rw-r-- 1 perkins perkins 84499 2009-01-08 14:43 real_programmers.png -rw-rw-r-- 1 perkins perkins 21570 2009-01-28 09:50 reminders.odp -rw-rw-r-- 1 perkins perkins 1300 2009-01-29 11:48 reverse.c -rw-r--r-- 1 perkins perkins 834 2007-10-17 13:34 structs.c ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gcc -Wall -g -o reverse reverse.c /tmp/cchMCJcv.o: In function `main': /home/perkins/cse303/reverse.c:42: warning: the `gets' function is dangerous and should not be used. ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ ./reverse Please enter a string: it was a dard k a  nd foggy morning Segmentation fault ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb reverse [?1034hGNU gdb Fedora (6.8-23.fc9) Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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"... (gdb) run Starting program: /home/perkins/cse303/reverse Please enter a string: hello Program received signal SIGSEGV, Segmentation fault. strcpy (dest=, src=) at strcpy.c:40 40 s[off] = c; (gdb) brt #0 strcpy (dest=, src=) at strcpy.c:40 #1 0x080484a3 in reverse (s=0xbfb8656c "hello") at reverse.c:19 #2 0x08048532 in main () at reverse.c:43 (gdb) list 35 size_t n; 36 37 do 38 { 39 c = *s++; 40 s[off] = c; 41 } 42 while (c != '\0'); 43 44 n = s - src; (gdb) up #1 0x080484a3 in reverse (s=0xbfb8656c "hello") at reverse.c:19 19 strcpy(result,s); (gdb) plist 14 char * result = NULL; /* the reversed string */ 15 int L, R; 16 char ch; 17 18 /* copy original string then reverse and return the copy */ 19 strcpy(result,s); 20 21 L = 0; 22 R = strlen(result); 23 while (L < R) { (gdb) p s $1 = 0xbfb8656c "hello" (gdb) p *s $2 = 104 'h' (gdb) p s[3] $3 = 108 'l' (gdb) p result $4 = 0x0 (gdb) quit The program is running. Exit anyway? (y or n) y ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb reverse./reverse [24@gcc -Wall -g -o reverse reverse.c /tmp/cckQpPI9.o: In function `main': /home/perkins/cse303/reverse.c:42: warning: the `gets' function is dangerous and should not be used. ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gcc -Wall -g -o reverse reverse.c db reverse./reverse Please enter a string: hello The original string was: >hello< Backwards, that string is: >< Thank you for trying our program. ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ exit exit Script done on Fri 30 Jan 2009 11:21:05 AM PST