this post was submitted on 07 Oct 2024
12 points (92.9% liked)

Rust

5930 readers
33 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

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.

top 4 comments
sorted by: hot top controversial new old
[–] BB_C 8 points 3 weeks ago (1 children)
  • 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.

[–] [email protected] 6 points 3 weeks ago* (last edited 3 weeks 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...

[–] [email protected] 1 points 3 weeks ago

I'm not sure, but in the debug config try to point "program" to the actual executable in /target/debug/hello_world

[–] FizzyOrange 1 points 3 weeks ago* (last edited 3 weeks 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.