Script started on Fri 23 Apr 2010 01:10:53 PM PDT ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gcc -Wall -g -o reverse reverse.c ]0;perkins@ubuntu: ~perkins@ubuntu:~$ ls -l total 984 -rw-r--r-- 1 perkins perkins 93 2010-04-09 11:48 characters -rw-r--r-- 1 perkins perkins 0 2010-04-23 13:10 debugdemo drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Desktop drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Documents drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Downloads -rw-r--r-- 1 perkins perkins 12903 2010-04-09 10:56 index.html drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Music drwxr-xr-x 3 perkins perkins 4096 2010-04-20 19:35 old drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Pictures drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Public -rwxr-xr-x 1 perkins perkins 10724 2010-04-23 13:11 reverse -rw-r--r-- 1 perkins perkins 1175 2010-04-20 19:34 reverse.c drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Templates drwxr-xr-x 2 perkins perkins 4096 2010-03-28 17:39 Videos -rw-r--r-- 1 perkins perkins 931708 2009-04-29 10:52 words ]0;perkins@ubuntu: ~perkins@ubuntu:~$ ./reverse Please enter a string: Does this work? Segmentation fault ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gdb reverse GNU gdb (GDB) 7.0-ubuntu Copyright (C) 2009 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 "i486-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/reverse...done. (gdb) run Starting program: /home/perkins/reverse Please enter a string: help!!! Program received signal SIGSEGV, Segmentation fault. 0x001a0a84 in strcpy () from /lib/tls/i686/cmov/libc.so.6 (gdb) bt #0 0x001a0a84 in strcpy () from /lib/tls/i686/cmov/libc.so.6 #1 0x08048553 in reverse (s=0xbffff428 "help!!!\n") at reverse.c:19 #2 0x080485f3 in main () at reverse.c:41 (gdb) uplist 26 result[R] = ch; 27 L++; R--; 28 } 29 30 return result; 31 } 32 33 34 /* Ask the user for a string, then print it forwards and backwards. */ 35 int main() { (gdb) up #1 0x08048553 in reverse (s=0xbffff428 "help!!!\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) p s $1 = 0xbffff428 "help!!!\n" (gdb) p result $2 = 0x0 (gdb) quit A debugging session is active. Inferior 1 [process 2493] will be killed. Quit anyway? (y or n) y ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gdb reverse./reverse ls -lgcc -Wall -g -o reverse reverse.c ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gcc -Wall -g -o reverse reverse.c db reverse GNU gdb (GDB) 7.0-ubuntu Copyright (C) 2009 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 "i486-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/reverse...done. (gdb) run Starting program: /home/perkins/reverse Please enter a string: ehll    hello The original string was: >hello < Backwards, that string is: >< Thank you for trying our program. Program exited normally. (gdb) quit ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gdb reverse GNU gdb (GDB) 7.0-ubuntu Copyright (C) 2009 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 "i486-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/reverse...done. (gdb) break reverse Breakpoint 1 at 0x804857a: file reverse.c, line 14. (gdb) run Starting program: /home/perkins/reverse Please enter a string: hello Breakpoint 1, reverse (s=0xbffff428 "hello\n") at reverse.c:14 14 char * result = NULL; /* the reversed string */ (gdb) list 9 #include 10 #include 11 12 /* Return a new string with the contents of s backwards */ 13 char * reverse(char * s) { 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 */ (gdb) s 19 result = (char *)malloc(sizeof(char)*(strlen(s)+1)); (gdb) s 20 strcpy(result,s); (gdb) s 22 L = 0; (gdb) p result $1 = 0x804b008 "hello\n" (gdb) print s $2 = 0xbffff428 "hello\n" (gdb) quit A debugging session is active. Inferior 1 [process 2538] will be killed. Quit anyway? (y or n) y ]0;perkins@ubuntu: ~perkins@ubuntu:~$ exit exit Script done on Fri 23 Apr 2010 01:21:20 PM PDT