[Solved] How to step into std source code when debugging in VS Code?

I’m using VS Code with the CodeLLDB extension on macOS.

I’m using this step to step through my rust unit tests in the debugger. This is working well, but I would also like to step into rust’s std libraries and see debug symbols. Currently I can step into std, but just see assembly. How do I set things up so that I can step into std and see debug symbols?

I did run rustup component add rust-src but it said I was already up-to-date.

The std binaries distributed by the Rust organization do not contain debugging information, so this is not possible out of the box. If you really want it, you can compile std yourself with debug info enabled.

1 Like

std does contain debuginfo.

I believe you’ll just need to add a source map entry pointing the debugger to where your rust-src is located: https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#source-path-remapping

1 Like

Huh ok, you’re right, I was mistaken.

Edit: oh yeah, I was thinking about rustc debug info, not std.

Thanks for help. After a few missteps I think I figured it out:

First I found rust std sources on my computer at:


Next what I tried to step into Vec::new() I saw (which contains a “Source location”):

; id = {0x00000180}, range = [0x0000000100002760-0x00000001000027b0), name="_$LT$alloc..vec..Vec$LT$T$GT$$GT$::new::h50925563cb2ee1ff", mangled="_ZN33_$LT$alloc..vec..Vec$LT$T$GT$$GT$3new17h50925563cb2ee1ffE"
; Source location: /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/liballoc/vec.rs:329
100002760: 55                         pushq  %rbp
100002761: 48 89 E5                   movq   %rsp, %rbp
100002764: 48 83 EC 20                subq   $0x20, %rsp

I then combined these two things in .vscode/settings.json like this:

  "lldb.executable": "rust-lldb",
  "lldb.launch.sourceLanguages": ["rust"],
  "lldb.launch.sourceMap": {
    "/rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/": "/Users/jessegrosjean/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/"

And I can step into std! Yeah and thank you!


In case someone uses Visual Studio Code with GDB and wants to achieve the same behavior, here is how I do it:

In launch.json:

    "version": "0.2.0",
    "configurations": [
            "type": "gdb",
            "autorun": [
                "set substitute-path /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858 <your-home-dir>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust"

Notice that /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858 depends on the exact toolchain you’re using. So updating your toolchain will probably require modifying this string. The way I easily find the hash is by running the following command in the project directory:

$ strings target/debug/<your-binary-name> | grep -o '^/rustc/[^/]\+/' | uniq

The idea is that Visual Studio Code will issue the GDB commands specified in the autorun array right after GDB is initialized, before actual debugging is started. The command set substitute-path of GDB is documented in Specifying Source Directories.

1 Like