Step by step interactive debugger for Rust? Ask Question

Step by step interactive debugger for Rust? Ask Question

How can I debug Rust application step by step interactively like I'm able to do with "pry" in Ruby?

I want to be able to see and preferably change the variables in real time when I reach a break point. Is there any production ready finished project?

ベストアンサー1

I find a good level of usability with VS Code and the CodeLLDB extension:

  1. Install VS Code

  2. Search and install the extension rust-analyzer from within VS Code

  3. Check requisites and setup CodeLLDB for your platform. As of v1.6, no further setup should be needed.

  4. Search and install the extension CodeLLDB from within VS Code

  5. The LLDB Debugger added the main menu item "Run" from where the debugger can be started. When debugging is started for the first time, you must select the environment (the debugger): select LLDB.

  6. When you select LLDB, a launch.json file will be opened, if not, open it, it's under .vscode folder

  7. Your launch.json should look like this:

    {
        // 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": "${workspaceRoot}/target/debug/hello_world",
                "args": [],
                "cwd": "${workspaceRoot}/target/debug/",
                "sourceLanguages": ["rust"]
            }
        ]
    }
    
  1. 汎用性を保ち、カーゴ フォルダー名に一致するバイナリのみをコンパイルする場合は、"program" キーの代わりに ${workspaceRootFolderName} 変数置換を使用できます。

     {
         "version": "0.2.0",
         "configurations": [
             {
                 "type": "lldb",
                 "request": "launch",
                 "name": "Debug",
                 "program": "${workspaceRoot}/target/debug/${workspaceRootFolderName}",
                 "args": [],
                 "cwd": "${workspaceRoot}/target/debug/",
                 "sourceLanguages": ["rust"]
             }
         ]
     }
    

Rust と VS Code に関するブログ投稿をいくつか紹介します。

おすすめ記事