Skip to content

Conversation

@norio-nomura
Copy link
Contributor

macOS Tahoe 26.0 does not allow the debug target of dlv dap to use the com.apple.security.virtualization entitlement. See: #2651 (comment)

But macOS Tahoe 26.0 allows the precompiled binary target of dlv exec to use the entitlement. This adds the DEBUG flag to build binaries with debug information for use by dlv exec.

Configuration files for VSCode working on macOS Tahoe 26.0 launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "exec hostagent for input instance",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            // Use integratedTerminal to stop using ctrl+C
            "console": "integratedTerminal",
            "program": "${workspaceFolder}/_output/bin/limactl",
            "env": {
                "LIMA_SSH_OVER_VSOCK": "false",
                "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",
                "--progress",
                "${input:targetInstance}"
            ],
            "preLaunchTask": "prepare launching hostagent for target instance",
            "postDebugTask": "clean up after stopping hostagent for target instance",
        },
    ],
    "inputs": [
        {
            "id": "targetInstance",
            "type": "promptString",
            "description": "Input target instance parameter for `limactl` command",
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "prepare launching hostagent for target instance",
            "dependsOn":[
                "execute: make CONFIG_GUESTAGENT_COMPRESS=n DEBUG=1",
                "execute: rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            ]
        },
        {
            "label": "clean up after stopping hostagent for target instance",
            "dependsOn":[
                "execute: rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            ]
        },
        {
            "label": "execute: make CONFIG_GUESTAGENT_COMPRESS=n DEBUG=1",
            "type": "shell",
            "command": "make CONFIG_GUESTAGENT_COMPRESS=n DEBUG=1",
            "presentation": {
                "close": true,
                "reveal": "always"
            },
        },
        {
            "label": "execute: rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            "type": "shell",
            "command": "rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            "presentation": {
                "close": true,
                "reveal": "silent"
            },
        }
    ],
    "inputs": [
        {
            "id": "targetInstance",
            "type": "promptString",
            "description": "Input <instance> for `rm -f <LIMA_HOME>/<instance>/ha.pid`",
        }
    ]
}

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a DEBUG flag to the Makefile that enables building binaries with debug information for use with dlv exec on macOS Tahoe 26.0. This addresses a compatibility issue where dlv dap cannot use certain entitlements on the new macOS version, but dlv exec with precompiled binaries can.

  • Introduces conditional debug build support via DEBUG=1
  • Adds GCFLAGS configuration for debug builds to disable optimizations and preserve debugging symbols
  • Updates build variable extraction to handle the new GCFLAGS parameter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@norio-nomura
Copy link
Contributor Author

I also made a review request to copilot by mistake.

@echo
@echo '- PREFIX (directory) : Installation prefix (default: /usr/local)'
@echo '- KEEP_SYMBOLS (1 or 0) : Whether to keep symbols (default: 0)'
@echo '- DEBUG (1 or 0) : Whether to build with debug information (default: 0)'
Copy link
Member

Choose a reason for hiding this comment

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

Probably this should be documented in https://lima-vm.io/docs/dev/ ? Maybe create the /docs/dev/debug page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I were to write a document on debugging in Visual Studio Code, I’d like to improve how ha.pid is handled to reduce the need for preLaunchTask and postDebugTask.

@norio-nomura norio-nomura force-pushed the makefile-add-debug-flag branch from aac904a to 6c44513 Compare September 17, 2025 04:13
…tion for use by `dlv exec`.

macOS Tahoe 26.0 does not allow the debug target of `dlv dap` to use the `com.apple.security.virtualization` entitlement.
See: lima-vm#2651 (comment)

But macOS Tahoe 26.0 allows the precompiled binary target of `dlv exec` to use the entitlement.
This adds the `DEBUG` flag to build binaries with debug information for use by `dlv exec`.

### Configuration files for VSCode working on macOS Tahoe 26.0
`launch.json`:
```jsonc
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "exec hostagent for input instance",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            // Use integratedTerminal to stop using ctrl+C
            "console": "integratedTerminal",
            "program": "${workspaceFolder}/_output/bin/limactl",
            "env": {
                "LIMA_SSH_OVER_VSOCK": "false",
                "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",
                "--progress",
                "${input:targetInstance}"
            ],
            "preLaunchTask": "prepare launching hostagent for target instance",
            "postDebugTask": "clean up after stopping hostagent for target instance",
        },
    ],
    "inputs": [
        {
            "id": "targetInstance",
            "type": "promptString",
            "description": "Input target instance parameter for `limactl` command",
        }
    ]
}
```

`tasks.json`:
```jsonc
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "prepare launching hostagent for target instance",
            "dependsOn":[
                "execute: make CONFIG_GUESTAGENT_COMPRESS=n DEBUG=1",
                "execute: rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            ]
        },
        {
            "label": "clean up after stopping hostagent for target instance",
            "dependsOn":[
                "execute: rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            ]
        },
        {
            "label": "execute: make CONFIG_GUESTAGENT_COMPRESS=n DEBUG=1",
            "type": "shell",
            "command": "make CONFIG_GUESTAGENT_COMPRESS=n DEBUG=1",
            "presentation": {
                "close": true,
                "reveal": "always"
            },
        },
        {
            "label": "execute: rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            "type": "shell",
            "command": "rm -f ${userHome}/.lima/${input:targetInstance}/ha.pid",
            "presentation": {
                "close": true,
                "reveal": "silent"
            },
        }
    ],
    "inputs": [
        {
            "id": "targetInstance",
            "type": "promptString",
            "description": "Input <instance> for `rm -f <LIMA_HOME>/<instance>/ha.pid`",
        }
    ]
}
```

Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
@norio-nomura norio-nomura force-pushed the makefile-add-debug-flag branch from 6c44513 to 4b7f04c Compare September 17, 2025 04:25
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 added this to the v2.0.0 milestone Sep 17, 2025
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Sep 17, 2025
…ha.pid`

Sometimes, after the `limactl hostagent` process stops (e.g., due to a SIGKILL), the `ha.pid` file remains.
This change checks if the process with the given PID is still running.
If not, the `ha.pid` file is ignored, simplifying debugging by reducing cleanup steps to remove `ha.pid`.

see: lima-vm#4044 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
@AkihiroSuda AkihiroSuda merged commit 16ec1dd into lima-vm:master Sep 17, 2025
62 of 63 checks passed
@norio-nomura norio-nomura deleted the makefile-add-debug-flag branch September 17, 2025 07:48
@norio-nomura
Copy link
Contributor Author

Thanks! 🙏🏻

@norio-nomura
Copy link
Contributor Author

norio-nomura commented Sep 18, 2025

I found a better solution than using "mode": "exec" and make DEBUG=1.
https://github.com/go-delve/delve/blob/master/Documentation/usage/README.md#environment-variables

  • $DELVE_DEBUGSERVER_PATH is used to locate the debugserver executable on macOS.

By using this, the debugserver can be overriden by a script that performs codesign on the debug target before launching debugserver. I tested this, and it works as expected with the "mode": "debug" parameter.

I'll open a PR that adding the script hack/debugserver-with-codesign.sh hack/codesign/debugserver

@norio-nomura
Copy link
Contributor Author

I'll open a PR that adding the script hack/debugserver-with-codesign.sh hack/codesign/debugserver

opened #4052

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