Script started on Fri 17 Oct 2008 02:28:52 PM PDT ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ emacs & [1] 2830 ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gcc -Wall -g -o reverse rebverse.c /tmp/ccJrNtqr.o: In function `main': /home/perkins/cse303/reverse.c:43: warning: the `gets' function is dangerous and should not be used. ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ ./reverse Please enter a string: radar is an acronym Segmentation fault ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb reverse [?1034hGNU gdb Fedora (6.8-22.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: here is another string Program received signal SIGSEGV, Segmentation fault. strcpy (dest=, src=) at strcpy.c:40 40 s[off] = c; (gdb) bt #0 strcpy (dest=, src=) at strcpy.c:40 #1 0x080484a3 in reverse (s=0xbf9494cc "here is another string") at reverse.c:19 #2 0x0804854c in main () at reverse.c:44 (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=0xbf9494cc "here is another string") 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 = 0xbf9494cc "here is another string" (gdb) p result $2 = 0x0 (gdb) quit The program is running. Exit anyway? (y or n) y ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb reverse./reversegcc -Wall -g -o reverse reverse.c ls -lgcc -Wall -g -o reverse reverse.c /tmp/ccyYRmSH.o: In function `main': /home/perkins/cse303/reverse.c:46: 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: hi there L=0, R=8 L=1, R=7 L=2, R=6 L=3, R=5 The original string was: >hi there< Backwards, that string is: >< Thank you for trying our program. ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb result [?1034hGNU gdb Fedora (6.8-22.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"... result: No such file or directory. (gdb) break reverse No symbol table is loaded. Use the "file" command. (gdb) break ./reverse Can't find member of namespace, class, struct, or union named "./reverse" Hint: try './reverse or './reverse (Note leading single quote.) (gdb) bueye Undefined command: "bye". Try "help". (gdb) quit ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb resulteverse [?1034hGNU gdb Fedora (6.8-22.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 reverse Breakpoint 1 at 0x80484ba: file reverse.c, line 19. (gdb) run Starting program: /home/perkins/cse303/reverse Please enter a string: hi there Breakpoint 1, reverse (s=0xbf8283ac "hi there") at reverse.c:19 19 result = (char *) malloc((strlen(s)+1)*sizeof(char)); (gdb) list 14 char * result; /* the reversed string */ 15 int L, R; 16 char ch; 17 18 /* allocate enought space for a copy of s */ 19 result = (char *) malloc((strlen(s)+1)*sizeof(char)); 20 21 /* copy original string then reverse and return the copy */ 22 strcpy(result,s); 23 (gdb) s __libc_malloc (bytes=) at malloc.c:3544 3544 __malloc_ptr_t (*hook) (size_t, __const __malloc_ptr_t) = __malloc_hook; (gdb) s 3545 if (hook != NULL) (gdb) finish Run till exit from #0 __libc_malloc (bytes=) at malloc.c:3545 0x080484d0 in reverse (s=0xbf8283ac "hi there") at reverse.c:19 19 result = (char *) malloc((strlen(s)+1)*sizeof(char)); Value returned is $1 = (void *) 0x8dff008 (gdb) n 22 strcpy(result,s); (gdb) bn 24 L = 0; (gdb) list 19 result = (char *) malloc((strlen(s)+1)*sizeof(char)); 20 21 /* copy original string then reverse and return the copy */ 22 strcpy(result,s); 23 24 L = 0; 25 R = strlen(result); 26 while (L < R) { 27 printf("L=%d, R=%d\n", L, R); 28 ch = result[L]; (gdb) n 25 R = strlen(result); (gdb) n 26 while (L < R) { (gdb) list 21 /* copy original string then reverse and return the copy */ 22 strcpy(result,s); 23 24 L = 0; 25 R = strlen(result); 26 while (L < R) { 27 printf("L=%d, R=%d\n", L, R); 28 ch = result[L]; 29 result[L] = result[R]; 30 result[R] = ch; (gdb) p L $2 = 0 (gdb) p R $3 = 8 (gdb) p s $4 = 0xbf8283ac "hi there" (gdb) n 27 printf("L=%d, R=%d\n", L, R); (gdb) n L=0, R=8 28 ch = result[L]; (gdb) n 29 result[L] = result[R]; (gdb) n 30 result[R] = ch; (gdb) n 31 L++; R--; (gdb) chpr ch $5 = 104 'h' (gdb) p result[R] $6 = 104 'h' (gdb) p result[0] $7 = 0 '\0' (gdb) quit The program is running. Exit anyway? (y or n) y ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ gdb reversesult./reversegcc -Wall -g -o reverse reverse.c /tmp/cca5koKK.o: In function `main': /home/perkins/cse303/reverse.c:45: warning: the `gets' function is dangerous and should not be used. ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ ./reverse Please enter a string: dows     oes it work? The original string was: >does it work?< Backwards, that string is: >?krow ti seod< Thank you for trying our program. ]0;perkins@localhost:~/cse303[perkins@localhost cse303]$ exit exit Script done on Fri 17 Oct 2008 03:19:43 PM PDT