Just started learning Rust today and got Rust installed, got the hello world example compiled and running. I installed rust-analyzer and CodeLLDB extensions in VSCode. Enable the debug.allowBreakpointsEverywhere settings to VSCode to be true. Setup a debug configuration in VSCode.

However I keep getting errors from rust-analyzer when I run the debugger…

2024-10-06T22:16:04.808655Z ERROR FetchWorkspaceError: rust-analyzer failed to load workspace: Failed to load the project at /home/john/Documents/Snippets/Rust/Cargo.toml: Failed to read Cargo metadata from Cargo.toml file /home/john/Documents/Snippets/Rust/Cargo.toml, Some(Version { major: 1, minor: 81, patch: 0 }): Failed to run `cd "/home/john/Documents/Snippets/Rust" && RUSTUP_TOOLCHAIN="/home/john/.rustup/toolchains/stable-x86_64-unknown-linux-gnu" "/home/john/.cargo/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/john/Documents/Snippets/Rust/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: failed to parse manifest at `/home/john/Documents/Snippets/Rust/Cargo.toml`

Caused by:
  no targets specified in the manifest
  either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present

I not sure how to fix this.

I would like to get the VSCode debugger to work for launch debugging, attach debugging and launch and attach debugging for rust running inside a docker container. This will be a good setup for getting started I believe.

This is my VSCode debugger configuration…

{
	// Use IntelliSense to learn about possible attributes.
	// Hover to view descriptions of existing attributes.
	// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
	"version": "0.2.0",
	"configurations": [
		{
			"type": "lldb",
			"request": "launch",
			"name": "Debug",
			"program": "${workspaceFolder}/hello-world",
			"args": [],
			"cwd": "${workspaceFolder}"
		}
	]
}

Any help and advice will be most appreciated.

  • BB_C@programming.dev
    link
    fedilink
    arrow-up
    8
    ·
    29 days ago
    • Why do you think this is a debugger issue?
    • May I suggest you try to learn how to use the rust toolchain directly first?
    • The error message looks informative to me. What part of this line did you not get?
       either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present 
      

    I think you’re tying yourself too close to VSCode. Reading this Cargo guide is a minimal requirement. And you should learn how to use cargo (the command), at least for basic operations. This is not hard. If anything, it’s much simpler than those bloated and opaque editor/IDE setups.

    • Ephera@lemmy.ml
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      29 days ago

      Maybe should be mentioned, if you just run cargo run in the project repo, you should get the same error without all the noise surrounding it…

  • hawgietonight@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    29 days ago

    I’m not sure, but in the debug config try to point “program” to the actual executable in /target/debug/hello_world

  • FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    28 days ago

    My advice is that you debug via tests. If you install Rust-analyzer (you probably already have) then any tests you add have a little “Run test” and “Debug test” button next to them that you can just click. It magically works without having to faff around with JSON files.

    As for your current setup, as other said you have an issue in Cargo.toml which is unrelated to debugging, and the target binary is in target/debug, not in the workspace root.