Script started on Mon 31 Jan 2011 12:37:55 PM PST ]0;perkins@fc13:~/Desktop[?1034h[perkins@fc13 Desktop]$ ./reverse Please enter a string: does this work? Segmentation fault (core dumped) ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gdb reverse [?1034hGNU gdb (GDB) Fedora (7.1-34.fc13) Copyright (C) 2010 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 "i686-redhat-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/Desktop/reverse...(no debugging symbols found)...done. (gdb) run Starting program: /home/perkins/Desktop/reverse Please enter a string: good luck  ck Program received signal SIGSEGV, Segmentation fault. 0x0044ddc8 in strcpy () from /lib/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.12.2-1.i686 (gdb) bt #0 0x0044ddc8 in strcpy () from /lib/libc.so.6 #1 0x080484c3 in reverse () #2 0x08048557 in main () (gdb) up #1 0x080484c3 in reverse () (gdb) list No symbol table is loaded. Use the "file" command. (gdb) print s No symbol table is loaded. Use the "file" command. (gdb) quit A debugging session is active. Inferior 1 [process 2595] will be killed. Quit anyway? (y or n) y ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ ls -l total 16 -rw-r--r-- 1 perkins auser 0 Jan 31 12:37 debugsession drwxr-xr-x 2 perkins auser 4096 Jan 28 19:04 old -rwxr-xr-x 1 perkins auser 5433 Jan 31 12:33 reverse -rw-r--r-- 1 perkins auser 1135 Jan 28 19:06 reverse.c ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gcc -Wall -g o-o reverse reverse.c ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gcbdb reverse [?1034hGNU gdb (GDB) Fedora (7.1-34.fc13) Copyright (C) 2010 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 "i686-redhat-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/Desktop/reverse...done. (gdb) run Starting program: /home/perkins/Desktop/reverse Please enter a string: what's wrong? Program received signal SIGSEGV, Segmentation fault. 0x0044ddc8 in strcpy () from /lib/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.12.2-1.i686 (gdb) list 30 return result; 31 } 32 33 34 /* Ask the user for a string, then print it forwards and backwards. */ 35 int main() { 36 char line[MAX_STR]; /* original input line */ 37 char * rev_line; /* backwards copy from reverse function */ 38 39 printf("Please enter a string: "); (gdb) hgbt #0 0x0044ddc8 in strcpy () from /lib/libc.so.6 #1 0x080484c3 in reverse (s=0xbffff268 "what's wrong?\n") at reverse.c:19 #2 0x08048557 in main () at reverse.c:41 (gdb) up #1 0x080484c3 in reverse (s=0xbffff268 "what's wrong?\n") at reverse.c:19 19 strcpy(result,s); (gdb) list 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) print s $1 = 0xbffff268 "what's wrong?\n" (gdb) print s[0] $2 = 119 'w' (gdb) print s[1] $3 = 104 'h' (gdb) print *s $4 = 119 'w' (gdb) print *(s+3) $5 = 116 't' (gdb) p s $6 = 0xbffff268 "what's wrong?\n" (gdb) p result $7 = 0x0 (gdb) list 24 ch = result[L]; 25 result[L] = result[R]; 26 result[R] = ch; 27 L++; R--; 28 } 29 30 return result; 31 } 32 33 (gdb) list 20-30 Function "20" not defined. (gdb) list 20 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) { 24 ch = result[L]; (gdb) kill Kill the program being debugged? (y or n) y (gdb) quit ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gdb reversecc -Wall -g -o reverse reverse.c ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gcc -Wall -g -o reverse reverse.c ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ ./reverse Please enter a string: this should work! The original string was: >this should work! < Backwards, that string is: >< Thank you for trying our program. ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gdb reverse [?1034hGNU gdb (GDB) Fedora (7.1-34.fc13) Copyright (C) 2010 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 "i686-redhat-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/Desktop/reverse...done. (gdb) break reverse Breakpoint 1 at 0x80484da: file reverse.c, line 14. (gdb) run Starting program: /home/perkins/Desktop/reverse Please enter a string: what's wrong? Breakpoint 1, reverse (s=0xbffff268 "what's wrong?\n") at reverse.c:14 14 char * result = NULL; /* the reversed string */ Missing separate debuginfos, use: debuginfo-install glibc-2.12.2-1.i686 (gdb) p s $1 = 0xbffff268 "what's wrong?\n" (gdb) p result $2 = 0x1
(gdb) s 19 result = (char *)malloc(strlen(s)+1); (gdb) p result $3 = 0x0 (gdb) step 20 strcpy(result,s); (gdb) p result $4 = 0x804a008 "" (gdb) nextp *p No symbol "p" in current context. (gdb) p *result $5 = 0 '\000' (gdb) strtep 22 L = 0; (gdb) p result $6 = 0x804a008 "what's wrong?\n" (gdb) s 23 R = strlen(result); (gdb) s 24 while (L < R) { (gdb) s 25 ch = result[L]; (gdb) s 26 result[L] = result[R]; (gdb) s 27 result[R] = ch; (gdb) s 28 L++; R--; (gdb) p L $7 = 0 (gdb) p R $8 = 14 (gdb) p result $9 = 0x804a008 "" (gdb) p strlen(result) $10 = 0 (gdb) p *result $11 = 0 '\000' (gdb) p *(result+12) $12 = 104 'h' (gdb) p *(result+1))2) $13 = 97 'a' (gdb) quit A debugging session is active. Inferior 1 [process 2743] will be killed. Quit anyway? (y or n) y ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gdb reverse [?1034hGNU gdb (GDB) Fedora (7.1-34.fc13) Copyright (C) 2010 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 "i686-redhat-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/Desktop/reverse...done. (gdb) brek eak reverse Breakpoint 1 at 0x80484da: file reverse.c, line 14. (gdb) run Starting program: /home/perkins/Desktop/reverse Please enter a string: short Breakpoint 1, reverse (s=0xbffff268 "short\n") at reverse.c:14 14 char * result = NULL; /* the reversed string */ Missing separate debuginfos, use: debuginfo-install glibc-2.12.2-1.i686 (gdb) s 19 result = (char *)malloc(strlen(s)+1); (gdb) s 20 strcpy(result,s); (gdb) s 22 L = 0; (gdb) p s $1 = 0xbffff268 "short\n" (gdb) p restullult $2 = 0x804a008 "short\n" (gdb) s 23 R = strlen(result); (gdb) s 24 while (L < R) { (gdb) p L $3 = 0 (gdb) p R $4 = 6 (gdb) s 25 ch = result[L]; (gdb) s 26 result[L] = result[R]; (gdb) s 27 result[R] = ch; (gdb) p result[L] $5 = 0 '\000' (gdb) p s $6 = 0xbffff268 "short\n" (gdb) quit A debugging session is active. Inferior 1 [process 2787] will be killed. Quit anyway? (y or n) y ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gdb reverse./reverse [24@gcc -Wall -g -o reverse reverse.c ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ gcc -Wall -g -o reverse reverse.c reverse bash: reverse: command not found ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ ./reverse Please enter a string: does it work? The original string was: >does it work?< Backwards, that string is: >?krow ti seod< Thank you for trying our program. ]0;perkins@fc13:~/Desktop[perkins@fc13 Desktop]$ ````exit exit Script done on Mon 31 Jan 2011 01:11:45 PM PST