Skip to content

Instantly share code, notes, and snippets.

@francesco-plt
Created March 13, 2023 15:16
Show Gist options
  • Save francesco-plt/0d63cf68183372c09941e81bda55ec6e to your computer and use it in GitHub Desktop.
Save francesco-plt/0d63cf68183372c09941e81bda55ec6e to your computer and use it in GitHub Desktop.
Setup to debug C files on macOS using vscode and lldb
  • tasks.json:
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "Build C",
            "command": "gcc",
            "args": [
                "-Wall",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "absolute"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}
  • launch.json:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "miDebuggerPath": "/Users/francesco/.vscode/extensions/ms-vscode.cpptools-1.14.3-darwin-arm64/debugAdapters/lldb-mi/bin/lldb-mi",
            "logging": {
                    "trace": true,
                    "engineLogging": true,
                    "traceResponse": true
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build C"
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment