LoginSignup
5
5

More than 1 year has passed since last update.

MacでVSCodeを使ってC言語のデバッグする方法

Last updated at Posted at 2020-02-25

はじめに

Macでのみ動作確認済みです。
コンパイルして、デバッグが終了したときに、作成したファイルを消去するように設定しています。

ファイルを作成する

mkdir .vscode && \
touch .vscode/tasks.json && \
touch .vscode/launch.json

拡張機能 CodeLLDBを入れる

CodeLLDB - Visual Studio Marketplace
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb

ファイルの編集

tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "c_build",
            "command": "gcc",
            "args": [
                "-g",
                "${file}",
            ],
            "group": "build", 
            "presentation": {
                "reveal": "never"
            }
        },
        {
            "type": "shell",
            "label": "rm_file",
            "command": "rm",
            "args": [
                "-rf",
                "a.out",
                "a.out.dSYM",
            ],
            "group": "build",
            "presentation": {
                "reveal": "never"
            }

        }
    ]
}
launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "c_debug",
            "type": "lldb",
            "request": "launch",
            "program": "${fileDirname}/a.out",
            "args": [""],
            "cwd": "${fileDirname}",
            "preLaunchTask": "c_build",
            "postDebugTask": "rm_file"
        }
    ]
}

コンパイル方法

  • ⌘ + Shift + b
  • F5

デバッグ

ブレークポイントを設定してから
メニューの「デバッグ」から「デバッグの開始」でデバッグがスタートします。

参考

tasks.jsonの設定について詳しく
Tasks in Visual Studio Code

launch.jsonの設定について詳しく
Debugging in Visual Studio Code

5
5
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
5
5