GDB does not show the starting 11 lines of code

0

I tried to run a test program with GDB 8.1, but to my surprise it doesn't show the first 11 lines of source code when I use the 'list' command. This was my code that I wrote to a file called 'Test.c'.

#include <stdio.h>

int global_var = 5;

void function_1() {
        int local_var = 15;
        printf("[function_1]: 1.\t[local_var] = %d\n", local_var);
        local_var++;
        printf("[function_1]: 2.\t[local_var] = %d\n", local_var);
        printf("[function_1]: 3.\t[global_var] = %d\n", global_var);
        global_var++;
        printf("[function_1]: 4.\t[global_var] = %d\n", global_var);
}

void function_2() {
        static int static_var =  25;
        printf("[function_2]: 1.\t[static_var] = %d\n", static_var);
        static_var++;
        printf("[function_2]: 2.\t[static_var] = %d\n", static_var);
        printf("[function_2]: 3.\t[global_var] = %d\n", global_var);
        global_var++;
        printf("[function_2]: 4.\t[global_var] = %d\n", global_var);
}

int main() {
        printf("[main]: 1.\t[global_var] = %d\n", global_var);
        function_1();
        function_2();
        printf("[main]: 2.\t[global_var] = %d\n", global_var);
        function_1();
        function_2();

        return 0;
}

I compiled it using GCC 7.4 with this command: gcc -g Test.c -o Test.out. Here is a screenshot of terminal where gdb did this:

Terminal screenshot

Can someone explain why this happened, and how to solve this issue?

Yahya

Posted 2019-05-16T17:36:30.253

Reputation: 1

No answers