Rust, いいですね。現代の知見と技術に基づいて C++ を再設計したという感じがします。
Visual Studio Code を使ってブレークポイントを張ったり、変数の中身をみたりできるようにしてみましょう。

環境

    • Rust 1.55.0 (stable)

 

    • Visual Studio Code 1.60.2

 

    macOS Bit Sur 11.6

Rust のインストール

$ curl https://sh.rustup.rs -sSf | sh

インストールオプションは 1 の default でよいです。

Current installation options:


   default host triple: aarch64-apple-darwin
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

インストーラが終了したら、

$ source $HOME/.cargo/env

で $PATH を更新します。

Rust の標準ライブラリのソースコードもインストールしておきます。デバッガで見られるようになります。

$ rustup component add rust-src

LLDB のインストール

LLDB をインストールします。すでに Xcode がインストールされていれば不要です。

$ xcode-select --install

Installing on MacOS

Visual Studio Code プラグインのインストール

スクリーンショット 2018-09-22 14.14.43.png

プロジェクトの設定

cargo で適当にプロジェクトを作って開きます。

$ cargo new hello_world

初回は rls をインストールするか聞かれるのインストールします。

スクリーンショット 2018-09-22 14.19.26.png

Debug -> Start Debugging しようとすると使用するデバッガを聞かれるので LLDB を選択します。

スクリーンショット 2018-09-22 14.19.56.png

すると launch.json が作られるので次のように sourceMap の設定を追加します。これで先ほどインストールした Rust の標準ライブラリのソースコードも見られるようになります。

            "sourceMap": {
                "/rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/": "${env:HOME}/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/"
            }

c8dfcfe046a7680554bf4eb612bad840e7631c4b の部分は rustc –version –verbose で表示される Rust 自体の commit-hash です。

スクリーンショット 2021-10-03 1.53.42.png

これでデバッグ実行できるようになるはずです。

スクリーンショット 2018-09-22 14.35.17.png
广告
将在 10 秒后关闭
bannerAds