5

I started learning Rust, and I want to set up debugging in Visual Studio Code, but can't get breakpoints working. I use the Native Debug & RustyCode extensions for VS Code.

Here is my launch file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "gdb",
            "request": "launch",
            "target": "target/debug/test",
            "cwd": "${workspaceRoot}"
        }
    ]
}

But when I run this configuration, breakpoints do not get hit. I see in the debug console that the debugger started and the app ran fine, but there is a warning message "No Symbols loaded":

No symbol table is loaded.  Use the "file" command.
No symbol table is loaded.  Use the "file" command.
Running executable
[New Thread 32168.0x81e0]
[New Thread 32168.0x3360]
[New Thread 32168.0x61b8]
[New Thread 32168.0x8040]
The program "+ + * - /" calculates the value 1
[Thread 32168.0x61b8 exited with code 0]
[Thread 32168.0x3360 exited with code 0]
[Thread 32168.0x8040 exited with code 0]
[Inferior 1 (process 32168) exited normally]

Here is the source of the app I am using. How can I make breakpoints work?

3
  • What is gdb version you are using ? Commented Jan 4, 2017 at 20:41
  • GNU gdb (GDB) 7.9.1 Commented Jan 5, 2017 at 2:45
  • I had a similar issue and I found that if I have hyphens in my project name (E.g. "abc-def"), then the code will run, but the breakpoints won't hit. Commented Aug 2, 2020 at 13:06

3 Answers 3

6

I was having the same problem until I realized I was using an msvc build of rustc.

GDB is only supposed to work with gnu builds, so if you use rustup, the solution is as simple as rustup default stable (or beta/nightly). GNU is default, for msvc you would need to do stable-msvc).

If you don't want to use rustup you should just re-install a gnu build of Rust manually.

Edit: As noted in a comment below, don't forget to re-build!

Sign up to request clarification or add additional context in comments.

2 Comments

And if you're wondering why it still doesn't work like I was, don't forget to re-build!
On Windows msvc is the default for rustup github.com/rust-lang-nursery/…
2

I had similar problems with breakpoints and found that adding this line to the settings.json fixed it:

{
    "debug.allowBreakpointsEverywhere": true
}

I am also using Microsoft's C/C++ Debugger plugin, not the native one. It still works for GDB.

Comments

0

As it was said before - gdb debugger doesn't work well with msvc build of rustc. Rustup defaults to msvc build on Windows right now.
To switch your default rustc build to gnu you have to run this command:

rustup default stable-gnu

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.