Script started on Wed 01 Feb 2017 11:26:50 AM PST [perkins@D-172-16-9-157 11-gdb-files]$ emacs reverse.c & [1] 2912 [perkins@D-172-16-9-157 11-gdb-files]$ ./reverse Please enter a string: hello The original string was: >hello < Backwards, that string is: >< Thank you for trying our program. [perkins@D-172-16-9-157 11-gdb-files]$ gdb ./reverse GNU gdb (GDB) Red Hat Enterprise Linux 7.11-67.el7 Copyright (C) 2016 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 main Breakpoint 1 at 0x4007ab: file reverse.c, line 43. (gdb) run Starting program: /home/perkins/cse374/11-gdb-files/reverse Missing separate debuginfos, use: debuginfo-install glibc-2.17-157.el7_3.1.x86_64 Breakpoint 1, main () at reverse.c:43 43 printf("Please enter a string: "); (gdb) list 38 /* Ask the user for a string, then print it forwards and backwards. */ 39 int main() { 40 char line[MAX_STR]; /* original input line */ 41 char * rev_line; /* backwards copy from reverse function */ 42 43 printf("Please enter a string: "); 44 fgets(line, MAX_STR, stdin); 45 rev_line = reverse(line); 46 printf("The original string was: >%s<\n", line); 47 printf("Backwards, that string is: >%s<\n", rev_line); (gdb) n 44 fgets(line, MAX_STR, stdin); (gdb) n Please enter a string: hello 45 rev_line = reverse(line); (gdb) p line $1 = "hello\n\000\000\275ȫ\367\377\177\000\000v\332\377\377\377\177\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\377\262\360\000\000\000\000\000\001\000\000\000\000\000\000\000m\b@", '\000' , " \b@\000\000\000\000\000\360\005@\000\000\000\000\000p\331\377\377" (gdb) quit A debugging session is active. Inferior 1 [process 3009] will be killed. Quit anyway? (y or n) y [perkins@D-172-16-9-157 11-gdb-files]$ gcc -Wall -g -std=c11 -o reverse reverse.c [perkins@D-172-16-9-157 11-gdb-files]$ ./reverse Please enter a string: hello The original string was: >hello< Backwards, that string is: >< Thank you for trying our program. [perkins@D-172-16-9-157 11-gdb-files]$ gdb ./reverse GNU gdb (GDB) Red Hat Enterprise Linux 7.11-67.el7 Copyright (C) 2016 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: debuginfo-install glibc-2.17-157.el7_3.1.x86_64 Please enter a string: hello Breakpoint 1, reverse (s=0x7fffffffd820 "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 /* allocate space for copy */ (gdb) p s $1 = 0x7fffffffd820 "hello" (gdb) p result $2 = 0x0 (gdb) p L $3 = 32767 (gdb) p R $4 = -134225592 (gdb) p /x L $5 = 0x7fff (gdb) p /x R $6 = 0xf7ffe148 (gdb) s 19 int size = strlen(s)+1; (gdb) 20 result = (char *)malloc(size); (gdb) 23 strcpy(result, s); (gdb) 25 L = 0; (gdb) 26 R = strlen(result); (gdb) 27 while (L < R) { (gdb) list 22 /* copy original string then reverse and return the copy */ 23 strcpy(result, s); 24 25 L = 0; 26 R = strlen(result); 27 while (L < R) { 28 ch = result[L]; 29 result[L] = result[R]; 30 result[R] = ch; 31 L++; R--; (gdb) p s $7 = 0x7fffffffd820 "hello" (gdb) p result $8 = 0x602010 "hello" (gdb) $9 = 0x602010 "hello" (gdb) p L $10 = 0 (gdb) p R $11 = 5 (gdb) break 27 Breakpoint 2 at 0x400746: file reverse.c, line 27. (gdb) cont Continuing. The original string was: >hello< Backwards, that string is: >< Thank you for trying our program. [Inferior 1 (process 3031) exited normally] (gdb) list 32 } 33 34 return result; 35 } 36 37 38 /* Ask the user for a string, then print it forwards and backwards. */ 39 int main() { 40 char line[MAX_STR]; /* original input line */ 41 char * rev_line; /* backwards copy from reverse function */ (gdb) run Starting program: /home/perkins/cse374/11-gdb-files/reverse Please enter a string: hello Breakpoint 1, reverse (s=0x7fffffffd820 "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 /* allocate space for copy */ (gdb) s 19 int size = strlen(s)+1; (gdb) s 20 result = (char *)malloc(size); (gdb) s 23 strcpy(result, s); (gdb) s 25 L = 0; (gdb) s 26 R = strlen(result); (gdb) s Breakpoint 2, reverse (s=0x7fffffffd820 "hello") at reverse.c:27 27 while (L < R) { (gdb) s 28 ch = result[L]; (gdb) s 29 result[L] = result[R]; (gdb) s 30 result[R] = ch; (gdb) s 31 L++; R--; (gdb) s 27 while (L < R) { (gdb) p result $12 = 0x602010 "" (gdb) p result[5] $13 = 104 'h' (gdb) p result[4] $14 = 111 'o' (gdb) p result[0] $15 = 0 '\000' (gdb) quit A debugging session is active. Inferior 1 [process 3070] will be killed. Quit anyway? (y or n) y [perkins@D-172-16-9-157 11-gdb-files]$ gcc -Wall -g -std=c11 -o reverse reverse.c [perkins@D-172-16-9-157 11-gdb-files]$ ./reverse Please enter a string: does it work now??? The original string was: >does it work now???< Backwards, that string is: >???won krow ti seod< Thank you for trying our program. [perkins@D-172-16-9-157 11-gdb-files]$ ./reverse Please enter a string: hello The original string was: >hello< Backwards, that string is: >olleh< Thank you for trying our program. [perkins@D-172-16-9-157 11-gdb-files]$ ./reverse Please enter a string: goodbye The original string was: >goodbye< Backwards, that string is: >eybdoog< Thank you for trying our program. [perkins@D-172-16-9-157 11-gdb-files]$ ./clint.py reverse.c reverse.c:23: Almost always, snprintf is better than strcpy [runtime/printf] [4] reverse.c:31: More than one command on the same line [whitespace/newline] [4] Done processing reverse.c Total errors found: 2 [perkins@D-172-16-9-157 11-gdb-files]$ ./clint.py reverse.c reverse.c:31: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Done processing reverse.c Total errors found: 1 [perkins@D-172-16-9-157 11-gdb-files]$ ./clint.py reverse.c Done processing reverse.c Total errors found: 0 [perkins@D-172-16-9-157 11-gdb-files]$ exit exit Script done on Wed 01 Feb 2017 12:22:03 PM PST