Script started on Mon 26 Apr 2010 12:46:50 PM PDT ]0;perkins@ubuntu: ~perkins@ubuntu:~$ emacs reverse.c. (emacs:2219): GLib-WARNING **: g_set_prgname() called multiple times ls -l ^Z [1]+ Stopped emacs reverse.c ]0;perkins@ubuntu: ~perkins@ubuntu:~$ bg [1]+ emacs reverse.c & ]0;perkins@ubuntu: ~perkins@ubuntu:~$ ls -l total 1004 -rw-r--r-- 1 perkins perkins 93 2010-04-09 11:48 characters -rw-r--r-- 1 perkins perkins 5745 2010-04-23 13:21 debugdemo -rw-r--r-- 1 perkins perkins 0 2010-04-26 12:46 debugdemo0426 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 -rw-r--r-- 1 perkins perkins 3383 2010-04-25 19:46 list.c 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 10770 2010-04-23 13:19 reverse -rw-r--r-- 1 perkins perkins 1231 2010-04-26 12:47 reverse.c -rw-r--r-- 1 perkins perkins 1231 2010-04-23 13:19 reverse.c~ -rw-r--r-- 1 perkins perkins 884 2010-04-25 19:46 structs.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: hello The original string was: >hello < Backwards, that string is: >< Thank you for trying our program. ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gdb revseerse 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 warning: Source file is more recent than executable. 14 char * result = NULL; /* the reversed string */ (gdb) print s $1 = 0xbffff428 "hello\n" (gdb) p s $2 = 0xbffff428 "hello\n" (gdb) quit A debugging session is active. Inferior 1 [process 2245] will be killed. Quit anyway? (y or n) y ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gdb reverse gcc -Wall -g -o reverse reverse.c ]0;perkins@ubuntu: ~perkins@ubuntu:~$ ./reverse Please enter a string: hello The original string was: >hello< Backwards, that string is: >< Thank you for trying our program. ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gcdb 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) brekak 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") 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 s $1 = 0xbffff428 "hello" (gdb) p result $2 = 0x804b008 "hello" (gdb) s 23 R = strlen(result); (gdb) s 24 while (L < R) { (gdb) p lL $3 = 0 (gdb) p R $4 = 5 (gdb) s 25 ch = result[L]; (gdb) s 26 result[L] = result[R]; (gdb) p vh No symbol "vh" in current context. (gdb) p vch $5 = 104 'h' (gdb) s 27 result[R] = ch; (gdb) p ch $6 = 104 'h' (gdb) s 28 L++; R--; (gdb) s 24 while (L < R) { (gdb) p L $7 = 1 (gdb) p R $8 = 4 (gdb) p s $9 = 0xbffff428 "hello" (gdb) p result $10 = 0x804b008 "" (gdb) quit A debugging session is active. Inferior 1 [process 2326] will be killed. Quit anyway? (y or n) y ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gdb reverse ./gcc -Wall -g -o reverse reverse.c ]0;perkins@ubuntu: ~perkins@ubuntu:~$ gcc -Wall -g -o reverse reverse.c db reverse ./ Please enter a string: hello The original string was: >hello< Backwards, that string is: >olleh< Thank you for trying our program. ]0;perkins@ubuntu: ~perkins@ubuntu:~$ exit exit Script done on Mon 26 Apr 2010 01:24:20 PM PDT