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 2 times, most recently from ba335d5 to e8500c4 Compare September 19, 2025 00:35
…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 e8500c4 to 77f5a1f Compare September 20, 2025 11:47
@norio-nomura
Copy link
Contributor Author

fixed ltag violation

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 65fb74e into lima-vm:master Sep 22, 2025
36 checks passed
@norio-nomura norio-nomura deleted the add-hack-codesign-debugserver branch September 22, 2025 08:58
@norio-nomura
Copy link
Contributor Author

Thanks! 🙏🏻

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