Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot debug Rust in Visual Studio Code?

I am trying to debug a Rust program in VS Code, but I get an error: https://i.sstatic.net/QapPo.png

After clicking OK, VS Code opens "settings.json": https://i.sstatic.net/X17Ss.png

I have these extensions installed:

https://i.sstatic.net/HPpZ6.png

My program is a simple "hello world" app.

like image 469
WasTabon Avatar asked Feb 01 '26 08:02

WasTabon


1 Answers

Unfortunately VS Code can't debug Rust out of the box :( But no need to worry, just few steps of configuration will do the work :)

Steps

  1. Install C/C++ extension if you are on windows and CodeLLDB if on OS X/Linux

  2. Click Debug -> Add Configuration, a launch.json file should open, you need to change the program name here manually

     {
         "version": "0.2.0",
         "configurations": [
             {
                 "name": "(Windows) Launch",
                 "type": "cppvsdbg",
                 "request": "launch",
                 "program": "${workspaceRoot}/target/debug/foo.exe",
                 "args": [],
                 "stopAtEntry": false,
                 "cwd": "${workspaceRoot}",
                 "environment": [],
                 "externalConsole": true
             },
             {
                 "name": "(OSX) Launch",
                 "type": "lldb",
                 "request": "launch",
                 "program": "${workspaceRoot}/target/debug/foo",
                 "args": [],
                 "cwd": "${workspaceRoot}",
             }
         ]
     }
    
  3. Make sure Allow setting breakpoints in any file is checkend under File -> Preferences -> Settings

For detailed steps and more you can refer the article I used to answer this

Credits- Forrest Smith

like image 82
Saurav Rao Avatar answered Feb 03 '26 01:02

Saurav Rao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!