Debugging Rust with gdb

后端 未结 2 2093
忘掉有多难
忘掉有多难 2021-02-20 00:21

I\'m aware of the debugging Rust questions here on StackOverflow and I also used gdb before with Go. However, I\'m running into a problem where it seems gdb is unable t

相关标签:
2条回答
  • 2021-02-20 00:39

    Ok, I figured out what was wrong. I have to manually emit the main.o file. I thought the -g parameter would just cut it.

    Now that I run

    rustc -g main.rs --emit="obj,link"
    

    I can run

    gdb main
    

    And everything works like a charme.

    I created two aliases for my bash to make things simple:

    alias rd='rustc -g --emit="obj,link"'
    
    compile_and_run() {
         rustc -g --emit="obj,link" $1 && gdb ${1%.*}
    }
    
    alias rdr=compile_and_run
    

    Now I can just call rdr main.rs and it will start debugging main.rs with gdb.

    0 讨论(0)
  • 2021-02-20 00:49

    Same question, later Rust version (1.0.0-beta), totally different answer:

    In GDB, when debugging a Rust executable, break main sets a breakpoint in some setup code that is part of the Rust standard library. This isn't what you want.

    Instead type: break $YOUR_CRATE::main, substituting the name of your program for $YOUR_CRATE.

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