Nicolas Noben

Zig: configure Visual Studio Code on macOS to get breakpoints on Apple Silicon (M chips)

vscode, zig, lldb, llvm, gdb, breakpoints, apple, debugging

2023-12-16

Breakpoints on Apple Silicon

As there is no current support for gdb on macOS Silicon (M1/M2…), we can use lldb to debug Zig programs in VSCode.

Install CodeLLDB in VSCode

The key is to use lldb instead of gdb, which comes with XCode (you might need to install xcode tools first).

Follow the CodeLLDB reference here

in a local .vscode folder:

Create a tasks.json config

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "zig build",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Create/update a launch.json config

Here is an example launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/zig-out/bin/<yourbinaryname>",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "build"
        }
    ]
}

And that’s it, you should be able to set up breakpoints and hit them when you launch.

I’m learning Zig, and I don’t know much about it yet, but everything appears to work. Watching locals, stack trace and view on the current variables all appear correct.

HTH.