Compile with -g option but “Single stepping until exit from function main, which has no line number information”

后端 未结 3 1207
终归单人心
终归单人心 2021-01-18 23:28

I have some trouble with gdb. This is my code in a single file named main.cpp

#include 

void myfunc();

int main(){
    char msg[] = \"Hello         


        
相关标签:
3条回答
  • 2021-01-19 00:09

    Try to use '-Og', too. Maybe that will help, because as @KevinDTimm wrote: compiler may optimize it.

    Reference:

    • "c++ --help=optimizers"
    0 讨论(0)
  • 2021-01-19 00:14

    Compile using -g and -ggdb flags.

    Your command should be

    g++ -g -ggdb -Wall main.cpp -o foo
    
    0 讨论(0)
  • 2021-01-19 00:15

    Thank you for your answers. I found what is wrong. As jcm says my gcc is relatively new. I have update gdb to the last current version which is GNU gdb (GDB) 7.6. Now this works perfectly.

    By the way, with the version g++ (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04) 4.6.4, gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04 works perfectly.

    Thank you for all of you.

    0 讨论(0)
提交回复
热议问题