# 2014 February 3 # # Using GDB (debugger) on third variation of reverse program (reverse3.c) # # Added comments are preceded by a single # and a space. Lines starting # with # followed immediately by a number and no space are output from GDB. # # # Compile with the -g option to fully utilize the debugger. # Use GDB on the executable. # $ gcc -Wall -g -o reverse reverse3.c $ gdb reverse GNU gdb (GDB) Fedora 7.6.1-46.fc19 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 /homes/campbl4/GDB_Demo/reverse...done. # # Use the break command to set a breakpoint at main # (gdb) break main Breakpoint 1 at 0x4007a1: file reverse3.c, line 46. (gdb) run Starting program: /homes/campbl4/GDB_Demo/reverse Breakpoint 1, main () at reverse3.c:46 46 printf("Please enter a string: "); Missing separate debuginfos, use: debuginfo-install glibc-2.17-20.fc19.x86_64 # # Use the next command to advance past the next executable statement within main # (gdb) next 47 fgets(line, MAX_STR, stdin); # # Use the next command to advance past the next executable statement within main # (Next will not step into the fgets function call) # (gdb) next Please enter a string: hello 49 rev_line = reverse(line); # # Use the next command to advance past the next executable statement # (gdb) next 51 printf("The original string was: >%s<\n", line); # # print the current value of line # (note all the garbage values in some of the cells) # (gdb) print line $1 = "hello\n\000\000`\343\377\377\377\177\000\000\070\001\301K3\000\000\000X\326\377\367\377\177\000\000}\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000m\b@\000\000\000\000\000\277", '\000' , " \b@\000\000\000\000\000\360\005@\000\000\000\000\000 \344\377\377" # # print the current value of rev_line # (gdb) print rev_line $2 = 0x602010 "\nolleh" # # Use the continue command to finish execution of the current function, main # The line and rev_line both contain the newline character \n but otherwise # the reverse ordering of characters is working # (gdb) continue Continuing. The original string was: >hello < Backwards, that string is: > olleh< Thank you for trying our program. [Inferior 1 (process 23899) exited normally] # # quit gdb # (gdb) quit $