# 2014 January 31 # # Using GDB (debugger) on first variation of reverse program (reverse1.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 normally, show that the program gives a segmentation fault when run. # $ gcc -Wall -o reverse reverse1.c $ ./reverse Please enter a string: hello Segmentation fault # # Attempt to use GDB on the executable (was not compiled with -g option). # $ 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...(no debugging symbols found)...done. # # The run command begins execution of the program # (gdb) run Starting program: /homes/campbl4/GDB_Demo/reverse Please enter a string: hello # # The segmentation fault happened around the strcpy command. # Program received signal SIGSEGV, Segmentation fault. 0x000000334bc861c0 in __strcpy_sse2 () from /lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.17-20.fc19.x86_64 # # The backtrace (bt) command traces the stack of function calls. # Here, main called reverse which called strcpy. # (gdb) backtrace #0 0x000000334bc861c0 in __strcpy_sse2 () from /lib64/libc.so.6 #1 0x00000000004006b7 in reverse () #2 0x0000000000400765 in main () # # The list command lists the source code if the executable was compiled with -g (we did not). # (gdb) list No symbol table is loaded. Use the "file" command. # # The up command will unwind the stack of function calls one level at a time. # (gdb) up #1 0x00000000004006b7 in reverse () # # The print command can print the value of a variable within the current scope # if the executable was compiled with -g (we did not). # (gdb) print s No symbol table is loaded. Use the "file" command. # # The quit command will quit GDB. # (gdb) quit A debugging session is active. Inferior 1 [process 23696] will be killed. Quit anyway? (y or n) y $