LoginSignup
1
1

More than 3 years have passed since last update.

VSCode MacのVSCodeでC言語のデバッグ環境を作成する

Last updated at Posted at 2020-12-02

拡張機能を入れる

CodeLLDB - Visual Studio Marketplace

ワークスペースの.vscodeディレクトリに以下のファイルを設定

私は実行ファイルを参照することはないので、実行ファイルをゴミ箱フォルダに生成するように設定しています。

/Users/user/.Trash/${fileBasenameNoExtension}の部分はuserディレクトリのパスを各環境に合わせて変更する必要があります。

実行時のファイル

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "c_debug",
            "type": "lldb",
            "request": "launch",
            "program": "/Users/user/.Trash/${fileBasenameNoExtension}",
            "args": [],
            "cwd": "${fileDirname}",
            "preLaunchTask": "c_build"
        }
    ]
}

コンパイル時のファイル

tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "c_build",
            "command": "gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "/Users/user/.Trash/${fileBasenameNoExtension}"
            ],
            "group": "build"
        }
    ]
}

ショートカット

ワークスペースで以下のコマンドを流してください。

各ファイルのインデントはshift + alt + Fで整えて使ってください。

mkdir .vscode && \
echo '{"version": "0.2.0","configurations": [{"name": "c_debug","type": "lldb","request": "launch","program": "/Users/user/.Trash/${fileBasenameNoExtension}","args": [],"cwd": "${fileDirname}","preLaunchTask": "c_build"}]}' > .vscode/launch.json && \
echo '{"version": "2.0.0","tasks": [{"type": "shell","label": "c_build","command": "gcc","args": ["-g","${file}","-o","/Users/user/.Trash/${fileBasenameNoExtension}"],"group": "build"}]}' > .vscode/tasks.json

おまけ

設定をカスタマイズしたい場合は以下の記事を参考にしてみてください。

VSCode デバッグの設定等で使用する定義済み変数のリスト - Qiita

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1