Script started on Mon 26 Oct 2015 02:01:56 PM PDT ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ gdb rev./vreverse GNU gdb (GDB) Fedora 7.9.1-19.fc22 Copyright (C) 2015 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 "x86_64-redhat-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./reverse...(no debugging symbols found)...done. (gdb) run Starting program: /home/perkins/cse374/11-gdb-files/reverse Missing separate debuginfos, use: dnf debuginfo-install glibc-2.21-8.fc22.x86_64 Please enter a string: hello Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7ac01d5 in __strcpy_sse2_unaligned () from /lib64/libc.so.6 (gdb) bt #0 0x00007ffff7ac01d5 in __strcpy_sse2_unaligned () from /lib64/libc.so.6 #1 0x00000000004006bd in reverse () #2 0x000000000040076b in main () (gdb) up #1 0x00000000004006bd in reverse () (gdb) p s No symbol table is loaded. Use the "file" command. (gdb) quit A debugging session is active. Inferior 1 [process 1808] will be killed. Quit anyway? (y or n) y ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ ls -l total 24 -rw-rw-r-- 1 perkins perkins 1236 Oct 22 14:16 final-reverse.c -rw-rw-r-- 1 perkins perkins 0 Oct 26 14:01 lec11-demo.txt -rw-rw-r-- 1 perkins perkins 1126 Oct 22 14:03 original-reverse.c -rwxrwxr-x 1 perkins perkins 8792 Oct 26 13:58 reverse -rw-rw-r-- 1 perkins perkins 1126 Oct 22 14:03 reverse.c ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ gdb gcc -g -Wall -g -std=c11 -o reverse reverse.c ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ gdb ./reverse GNU gdb (GDB) Fedora 7.9.1-19.fc22 Copyright (C) 2015 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 "x86_64-redhat-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./reverse...done. (gdb) run Starting program: /home/perkins/cse374/11-gdb-files/reverse Missing separate debuginfos, use: dnf debuginfo-install glibc-2.21-8.fc22.x86_64 Please enter a string: oh no!! Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7ac01f3 in __strcpy_sse2_unaligned () from /lib64/libc.so.6 (gdb) bt #0 0x00007ffff7ac01f3 in __strcpy_sse2_unaligned () from /lib64/libc.so.6 #1 0x00000000004006bd in reverse (s=0x7fffffffdf20 "oh no!!\n") at reverse.c:19 #2 0x000000000040076b in main () at reverse.c:41 (gdb) list 25 result[L] = result[R]; 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. */ (gdb) up #1 0x00000000004006bd in reverse (s=0x7fffffffdf20 "oh no!!\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) up #2 0x000000000040076b in main () at reverse.c:41 41 rev_line = reverse(line); (gdb) list 36 char line[MAX_STR]; /* original input line */ 37 char * rev_line; /* backwards copy from reverse function */ 38 39 printf("Please enter a string: "); 40 fgets(line, MAX_STR, stdin); 41 rev_line = reverse(line); 42 printf("The original string was: >%s<\n", line); 43 printf("Backwards, that string is: >%s<\n", rev_line); 44 printf("Thank you for trying our program.\n"); 45 return 0; (gdb) p line $1 = "oh no!!\n\000\000\000\000\000\000\000\000\210\340\377\377\377\177\000\000\260\337\377\377\377\177\000\000H\341\377\367\377\177\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\375\a@\000\000\000\000\000\240\005@", '\000' , "\260\a@\000\000\000\000\000\240\005@\000\000\000\000\000p\340\377\377" (gdb) p linep[0] $2 = 111 'o' (gdb) p line+0 $3 = 0x7fffffffdf20 "oh no!!\n" (gdb) p line+2 $4 = 0x7fffffffdf22 " no!!\n" (gdb) p line[4] $5 = 111 'o' (gdb) donwn #1 0x00000000004006bd in reverse (s=0x7fffffffdf20 "oh no!!\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 $6 = 0x7fffffffdf20 "oh no!!\n" (gdb) p result $7 = 0x0 (gdb) quit A debugging session is active. Inferior 1 [process 1849] will be killed. Quit anyway? (y or n) y ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ gdb ./reversecc -Wall -g -std=c11 -o reverse reverse.c ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ ./reverse Please enter a string: does it work now? The original string was: >does it work now? < Backwards, that string is: >< Thank you for trying our program. ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ ./reverse gcc -Wall -g -std=c11 -o reverse reverse.c ./reverse gcc -Wall -g -std=c11 -o reverse reverse.c db ./reverse GNU gdb (GDB) Fedora 7.9.1-19.fc22 Copyright (C) 2015 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 "x86_64-redhat-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./reverse...done. (gdb) break reverse Breakpoint 1 at 0x4006f2: file reverse.c, line 14. (gdb) run Starting program: /home/perkins/cse374/11-gdb-files/reverse Missing separate debuginfos, use: dnf debuginfo-install glibc-2.21-8.fc22.x86_64 Please enter a string: asdfasdfsadf xyzzy Breakpoint 1, reverse (s=0x7fffffffdf20 "asdfasdfsadf xyzzy\n") at reverse.c:14 14 char * result = NULL; /* the reversed string */ (gdb) plist 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) p s $1 = 0x7fffffffdf20 "asdfasdfsadf xyzzy\n" (gdb) p reverse $2 = {char *(char *)} 0x4006e6 (gdb) step 19 result = (char *)malloc(strlen(s)+1); (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 result = (char *)malloc(strlen(s)+1); 20 strcpy(result, s); 21 22 L = 0; 23 R = strlen(result); (gdb) next 20 strcpy(result, s); (gdb) list 15 int L, R; 16 char ch; 17 18 /* copy original string then reverse and return the copy */ 19 result = (char *)malloc(strlen(s)+1); 20 strcpy(result, s); 21 22 L = 0; 23 R = strlen(result); 24 while (L < R) { (gdb) p s $3 = 0x7fffffffdf20 "asdfasdfsadf xyzzy\n" (gdb) p result $4 = 0x602010 "" (gdb) p /x reult No symbol "reult" in current context. (gdb) p /x reultsult $5 = 0x602010 (gdb) s 22 L = 0; (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) p l No symbol "l" in current context. (gdb) p L $6 = 0 (gdb) p R $7 = 19 (gdb) p s[L] $8 = 97 'a' (gdb) p Ss[R] $9 = 0 '\000' (gdb) s 27 result[R] = ch; (gdb) s 28 L++; R--; (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) 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) s 24 while (L < R) { (gdb) p L $10 = 3 (gdb) P R $11 = 16 (gdb) p s $12 = 0x7fffffffdf20 "asdfasdfsadf xyzzy\n" (gdb) p result $13 = 0x602010 "" (gdb) p result[0] $14 = 0 '\000' (gdb) p result[0]1] $15 = 10 '\n' (gdb) p result[1]]2] $16 = 121 'y' (gdb) p result[2]]3] $17 = 102 'f' (gdb) p result[+1 $18 = 0x602011 "\nyfasdfsadf xyzzdsa" (gdb) list 19 result = (char *)malloc(strlen(s)+1); 20 strcpy(result, s); 21 22 L = 0; 23 R = strlen(result); 24 while (L < R) { 25 ch = result[L]; 26 result[L] = result[R]; 27 result[R] = ch; 28 L++; R--; (gdb) 29 } 30 31 return result; 32 } 33 34 35 /* Ask the user for a string, then print it forwards and backwards. */ 36 int main() { 37 char line[MAX_STR]; /* original input line */ 38 char * rev_line; /* backwards copy from reverse function */ (gdb) break 31 Breakpoint 2 at 0x400796: file reverse.c, line 31. (gdb) cont Continuing. Breakpoint 2, reverse (s=0x7fffffffdf20 "asdfasdfsadf xyzzy\n") at reverse.c:31 31 return result; (gdb) p s $19 = 0x7fffffffdf20 "asdfasdfsadf xyzzy\n" (gdb) rp result $20 = 0x602010 "" (gdb) p result+1 $21 = 0x602011 "\nyzzyx fdasfdsafdsa" (gdb) kquit A debugging session is active. Inferior 1 [process 1892] will be killed. Quit anyway? (y or n) quity ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ gdb ./reverse./reverse gcc -Wall -g -std=c11 -o reverse reverse.c ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ ./reverse Please enter a string: success? The original string was: >success? < Backwards, that string is: >?sseccus < Thank you for trying our program. ]0;perkins@f22:~/cse374/11-gdb-filesf22:~/cse374/11-gdb-files $ quexit exit Script done on Mon 26 Oct 2015 02:21:56 PM PDT