Sharpen your understanding of GDB debugging within Linux environments with this beginner-focused quiz. Explore core concepts, common commands, and practical usage to enhance your troubleshooting and analysis skills using the GNU Debugger tool on Linux.
Which command is correctly used to start GDB and debug the executable named 'myapp'?
Explanation: The 'gdb myapp' command correctly launches GDB attached to the 'myapp' executable. 'debug myapp' and 'run gdb myapp' are not valid GDB commands. 'gdb --run myapp' is incorrect syntax, as '--run' is not a recognized GDB launch flag.
What GDB command is used to set a breakpoint at the start of the function named 'processData'?
Explanation: 'b processData' is the abbreviated command to set a breakpoint at 'processData'. 'bp processData' and 'breakpoint processData' are not correct GDB commands. 'stop processData' is also invalid. Only 'b' or 'break' is used for breakpoints.
After launching GDB with an executable, which command begins program execution under the debugger?
Explanation: The 'run' command starts the debugging session, executing the program as controlled by GDB. 'start' is used for a different purpose—it runs to the beginning of main(). 'go' and 'execute' are incorrect as they are not recognized GDB commands.
Within GDB, which command displays the current value of the variable named 'count'?
Explanation: 'print count' displays the current value of 'count' in GDB. 'display count' sets up the variable for automatic printing each time a breakpoint is hit, but does not immediately show its value. 'show count' and 'info count' are not appropriate for displaying variable values.
Which GDB command executes the next line of code, stepping into function calls?
Explanation: 'step' executes the next line and enters functions if present. 'next' also moves to the next line but does not enter functions. 'continue' resumes execution until the next breakpoint, and 'skip' is not a standard GDB command.
How can you gracefully exit GDB from the debugger prompt?
Explanation: Typing 'quit' at the GDB prompt safely exits the debugger. 'exit' might work on some setups but is not universally correct in GDB. 'leave' and 'close' are not valid GDB commands for quitting.
What GDB command is used to display the current call stack or backtrace?
Explanation: The 'backtrace' command (often abbreviated as 'bt') lists the active call stack frames. 'stack', 'trace', and 'callstack' are not standard GDB commands for this purpose.
Which command removes all existing breakpoints in the active GDB session?
Explanation: 'delete' without arguments removes all breakpoints in GDB. 'clear' is used to remove specific breakpoints or lines, not all. 'remove' and 'unset' are not valid commands to delete breakpoints.
After stopping at a breakpoint, which command resumes program execution until the next breakpoint or program exit?
Explanation: 'continue' resumes the program until a breakpoint is hit or execution ends. 'next' and 'step' only advance a single line, while 'resume' is not a recognized GDB command.
What is the correct GDB command to display 4 integer values starting at memory address 0x7ffdf8a0?
Explanation: 'x/4d 0x7ffdf8a0' uses GDB's examine command to display four integers at a specific address. The other options use invalid or incorrect syntax for displaying memory in GDB.
Which GDB command is used to continuously monitor and display the value of variable 'score' during program execution?
Explanation: 'display score' ensures that the value of 'score' is shown every time the program stops. 'watch score' stops execution when 'score' changes, not just for display. 'trace score' and 'observe score' are not valid GDB commands.
Which file can be placed in your home directory to automatically run GDB commands at startup?
Explanation: The '.gdbinit' file contains commands that GDB reads and executes at startup. The other options, such as '.gdb.cnf', '.gdbrun', and '.gdbconfig', are not standard GDB initialization files.
Which compiler flag should you use to include debug symbols for GDB when compiling your C or C++ program?
Explanation: The '-g' flag instructs the compiler to include debug symbols, which are essential for effective use with GDB. The other options are either typos or not universally accepted by compilers for generating debugging information.
In GDB, which command allows you to change the next line of code to be executed without running any code in between?
Explanation: 'jump' allows you to change the program counter to another line or address. 'goto' is not a GDB command and is used in programming code themselves. 'move' and 'shift' are unrelated to execution control in GDB.
What GDB command displays the lines of source code around the current execution point?
Explanation: 'list' shows the surrounding lines of source code currently being executed. 'show' is generally used for settings, 'browse' is not a GDB command, and 'display' is used for variable values, not source lines.
Which GDB command lists all shared libraries currently loaded by the debugged program?
Explanation: 'info sharedlibrary' provides a list of all loaded shared libraries in the debugged process. The other options, including 'libs', 'show libraries', and 'libraryinfo', are not recognized GDB commands.