AAB
AAB

Reputation: 1653

gdb full file not being loaded

I used Visual Studio 2013 to compile and debug a C program. Then compiled the same program in gcc and tried debugging but for some reason, I am not able to jump to a specific line. The message I get is no line line_number in current file.

Here is the C Code

#include<stdio.h>

int main() {
    while (1) { 
    }
    printf("Hello World!");
    printf("Bye World!");
    return 0;
}

Now for the above code in VS 2013, I am able to move the yellow arrow and make it point to the print function, but in case of GDB I am not able to use jump to move to the print function.

I used gcc -g file.c -o file to compile my C file. My guess is since its an infinite loop, some optimization only shows instruction till the loop.

Edit:

GDB commands I used are

1) gdb 2) file exec_name 3) break line_number 4) run 5) jump line_number

If I modify the loop to

int x = 1;
while (x) {
}

The jump works fine

Upvotes: 0

Views: 173

Answers (1)

ks1322
ks1322

Reputation: 35706

in case of GDB I am not able to use jump to move to the print function

This is because GCC does not emit unreachable code even with optimizations disabled with -O0. See it on godbolt: https://godbolt.org/z/lpXNmn. You can jump in Visual Studio because the code is emitted: https://godbolt.org/z/7452oP. It seems that there is no way to force GCC to emit this unreachable code as well. And actually there is no sense to emit it for this artificial example.

Upvotes: 2

Related Questions