Linux GDB Debugging Essentials Quiz Quiz

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.

  1. Launching GDB

    Which command is correctly used to start GDB and debug the executable named 'myapp'?

    1. gdb myapp
    2. debug myapp
    3. gdb --run myapp
    4. run gdb 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.

  2. Setting Breakpoints

    What GDB command is used to set a breakpoint at the start of the function named 'processData'?

    1. b processData
    2. bp processData
    3. breakpoint processData
    4. stop 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.

  3. Running the Program

    After launching GDB with an executable, which command begins program execution under the debugger?

    1. run
    2. start
    3. go
    4. execute

    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.

  4. Inspecting Variable Values

    Within GDB, which command displays the current value of the variable named 'count'?

    1. print count
    2. show count
    3. display count
    4. info 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.

  5. Stepping Line by Line

    Which GDB command executes the next line of code, stepping into function calls?

    1. step
    2. next
    3. continue
    4. skip

    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.

  6. Exiting GDB

    How can you gracefully exit GDB from the debugger prompt?

    1. quit
    2. exit
    3. leave
    4. close

    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.

  7. Viewing the Call Stack

    What GDB command is used to display the current call stack or backtrace?

    1. backtrace
    2. stack
    3. trace
    4. callstack

    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.

  8. Removing Breakpoints

    Which command removes all existing breakpoints in the active GDB session?

    1. delete
    2. clear
    3. remove
    4. unset

    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.

  9. Continuing Execution

    After stopping at a breakpoint, which command resumes program execution until the next breakpoint or program exit?

    1. continue
    2. next
    3. step
    4. resume

    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.

  10. Examining Memory Content

    What is the correct GDB command to display 4 integer values starting at memory address 0x7ffdf8a0?

    1. x/4d 0x7ffdf8a0
    2. m 0x7ffdf8a0 4
    3. display 0x7ffdf8a0 4
    4. memdump 0x7ffdf8a0 4

    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.

  11. Adding Watches

    Which GDB command is used to continuously monitor and display the value of variable 'score' during program execution?

    1. display score
    2. watch score
    3. trace score
    4. observe score

    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.

  12. Automatic Execution at Startup

    Which file can be placed in your home directory to automatically run GDB commands at startup?

    1. .gdbinit
    2. .gdb.cnf
    3. .gdbrun
    4. .gdbconfig

    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.

  13. Compiling for Debugging

    Which compiler flag should you use to include debug symbols for GDB when compiling your C or C++ program?

    1. -g
    2. -dbg
    3. -symbols
    4. -debug

    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.

  14. Changing Execution Flow

    In GDB, which command allows you to change the next line of code to be executed without running any code in between?

    1. jump
    2. goto
    3. move
    4. shift

    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.

  15. Listing Source Code

    What GDB command displays the lines of source code around the current execution point?

    1. list
    2. show
    3. browse
    4. display

    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.

  16. Checking Loaded Shared Libraries

    Which GDB command lists all shared libraries currently loaded by the debugged program?

    1. info sharedlibrary
    2. libs
    3. show libraries
    4. libraryinfo

    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.