Script started on Mon 30 Jan 2017 12:10:17 PM PST [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: reverse me Segmentation fault (core dumped) [perkins@D-172-16-9-157 11-gdb-files]$ gdb ./reverse GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7 Copyright (C) 2013 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". For bug reporting instructions, please see: ... Reading symbols from /home/perkins/cse374/11-gdb-files/reverse...done. (gdb) run Starting program: /home/perkins/cse374/11-gdb-files/./reverse Please enter a string: help me Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7ab06e3 in __strcpy_sse2_unaligned () from /lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.17-157.el7_3.1.x86_64 (gdb) bt #0 0x00007ffff7ab06e3 in __strcpy_sse2_unaligned () from /lib64/libc.so.6 #1 0x00000000004006bd in reverse (s=0x7fffffffd840 "help me\n") at reverse.c:19 #2 0x000000000040076b in main () at reverse.c:41 (gdb) list 30 return result; 31 } 32 33 34 /* Ask the user for a string, then print it forwards and backwards. */ 35 int main() { 36 char line[MAX_STR]; /* original input line */ 37 char * rev_line; /* backwards copy from reverse function */ 38 39 printf("Please enter a string: "); (gdb) bt #0 0x00007ffff7ab06e3 in __strcpy_sse2_unaligned () from /lib64/libc.so.6 #1 0x00000000004006bd in reverse (s=0x7fffffffd840 "help me\n") at reverse.c:19 #2 0x000000000040076b in main () at reverse.c:41 (gdb) up #1 0x00000000004006bd in reverse (s=0x7fffffffd840 "help me\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 = "help me\n\000ȫ\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\000\375\a@", '\000' , "\260\a@\000\000\000\000\000\240\005@\000\000\000\000\000\220\331\377\377" (gdb) p rev_line $2 = 0x0 (gdb) down #1 0x00000000004006bd in reverse (s=0x7fffffffd840 "help me\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) print s $3 = 0x7fffffffd840 "help me\n" (gdb) p result $4 = 0x0 (gdb) quit A debugging session is active. Inferior 1 [process 3100] 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: >< Thank you for trying our program. [perkins@D-172-16-9-157 11-gdb-files]$ exit exit Script done on Mon 30 Jan 2017 12:20:25 PM PST