UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

16.7. Self-assessment questions

Check with these questions that you understand how the debugger works.

  1. After create an executable file, ./program, and invoke the debugger with gdb program, you want to execute the program through the debugger. Which is the correct command?

    • run or r

    • start or s

    • continue or c

  2. Once you have started to execute the program through the debugger, you want to introduce a breakpoint in line 36 of your code. Which is the correct command?

    • l 36

    • b l 36

    • b 36

    • p 36

    • First, you have to stop the program execution in order to introduce a breakpoint.

  3. Having the following piece of code from the program calculate_square.c:

    5  int calculate_square(int n)
    6  {
    7    /* Function to print the square of a number */
    8    int square = 0;
    9    if (n<=250)
    10   {
    11     square = n * n;
    12     printf(''The square of %d is %d \n", n, square);
    13   }
    14   return square;
    15 }
    16 int main(int argc, char **argv)
    17 {
    18   calculate_square(5);
    19   calculate_square(251);
    20   return 0;
    21 }  

    You invoke the debugger, introduce a breakpoint in the function call in line 19 and start the execution of the program through the debugger. The program stops in line 19, and you want to get inside the calculate_square function to see how that function behaves with the argument number 251, so:

    • You execute c for the debugger to both continue and get inside the function.

    • You execute n for the debugger to both continue and get inside the function.

    • You execute s for the debugger to both continue and get inside the function.

    • You first execute c for the debugger to continue and, second, execute n for the debugger to get inside the function.