Skip to content

Conversation

norio-nomura
Copy link
Contributor

@norio-nomura norio-nomura commented Sep 18, 2025

hack/codesign/debugserver

This script wraps the LLDB debugserver to codesign the target executable. This is needed for Delve to work properly on macOS with the virtualization framework.

How to use this script with Delve

Use DELVE_DEBUGSERVER_PATH environment variable

Override debugserver by setting the DELVE_DEBUGSERVER_PATH environment variable.
Ref: Environment variables - Using Delve

e.g. in .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "hostagent for input instance",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            // Use integratedTerminal to stop using ctrl+C
            "console": "integratedTerminal",
            "program": "${workspaceFolder}/cmd/limactl",
            "buildFlags": [
                "-ldflags=-X github.com/lima-vm/lima/pkg/version.Version=2.0.0-alpha.0",
            ],
            "env": {
                "CGO_ENABLED": "1",
                "DELVE_DEBUGSERVER_PATH": "${workspaceFolder}/hack/codesign/debugserver",
                "LIMA_SSH_PORT_FORWARDER": "true",
            },
            "cwd": "${userHome}/.lima/${input:targetInstance}",
            "args": [
                "--debug",
                "hostagent",
                "--pidfile", "ha.pid",
                "--socket", "ha.sock",
                "--guestagent", "${workspaceFolder}/_output/share/lima/lima-guestagent.Linux-aarch64",
                "${input:targetInstance}"
            ],
		},
    ],
    "inputs": [
        {
            "id": "targetInstance",
            "type": "promptString",
            "description": "Input target instance parameter for `limactl` command",
        }
    ]
}

Override debugserver in the PATH

You can also override the debugserver in the PATH environment variable.

e.g. in .vscode/launch.json:

             "env": {
                 "CGO_ENABLED": "1",
-                "DELVE_DEBUGSERVER_PATH": "${workspaceFolder}/hack/codesign/debugserver",
+                "PATH": "${workspaceFolder}/hack/codesign:${env:PATH}",
             },

@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Sep 19, 2025
@norio-nomura norio-nomura force-pushed the add-hack-codesign-debugserver branch from 5afc6ea to ba335d5 Compare September 19, 2025 00:32
…design the target executable.

# `hack/codesign/debugserver`

This script wraps the LLDB `debugserver` to `codesign` the target executable.
This is needed for [Delve](https://github.com/go-delve/delve) to work properly
on macOS with the virtualization framework.

## How to use this script with Delve

### Use `DELVE_DEBUGSERVER_PATH` environment variable

Override `debugserver` by setting the `DELVE_DEBUGSERVER_PATH` environment variable.
Ref: [Environment variables - Using Delve](https://github.com/go-delve/delve/blob/master/Documentation/usage/README.md#environment-variables)

e.g. in `.vscode/launch.json`:
```jsonc
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "hostagent for input instance",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            // Use integratedTerminal to stop using ctrl+C
            "console": "integratedTerminal",
            "program": "${workspaceFolder}/cmd/limactl",
            "buildFlags": [
                "-ldflags=-X github.com/lima-vm/lima/pkg/version.Version=2.0.0-alpha.0",
            ],
            "env": {
                "CGO_ENABLED": "1",
                "DELVE_DEBUGSERVER_PATH": "${workspaceFolder}/hack/codesign/debugserver",
                "LIMA_SSH_PORT_FORWARDER": "true",
            },
            "cwd": "${userHome}/.lima/${input:targetInstance}",
            "args": [
                "--debug",
                "hostagent",
                "--pidfile", "ha.pid",
                "--socket", "ha.sock",
                "--guestagent", "${workspaceFolder}/_output/share/lima/lima-guestagent.Linux-aarch64",
                "${input:targetInstance}"
            ],
		},
    ],
    "inputs": [
        {
            "id": "targetInstance",
            "type": "promptString",
            "description": "Input target instance parameter for `limactl` command",
        }
    ]
}
```

### Override `debugserver` in the PATH

You can also override the `debugserver` in the PATH environment variable.

e.g. in `.vscode/launch.json`:
```diff
             "env": {
                 "CGO_ENABLED": "1",
-                "DELVE_DEBUGSERVER_PATH": "${workspaceFolder}/hack/codesign/debugserver",
+                "PATH": "${workspaceFolder}/hack/codesign:${env:PATH}",
             },
```

Signed-off-by: Norio Nomura <[email protected]>
@norio-nomura norio-nomura force-pushed the add-hack-codesign-debugserver branch from ba335d5 to e8500c4 Compare September 19, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants