跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

debugserver

113 行 · 4.0 KB历史下载
1#!/bin/bash
2
3# SPDX-FileCopyrightText: Copyright The Lima Authors
4# SPDX-License-Identifier: Apache-2.0
5
6# # `hack/codesign/debugserver`
7#
8# This script wraps the LLDB `debugserver` to `codesign` the target executable.
9# This is needed for [Delve](https://github.com/go-delve/delve) to work properly
10# on macOS with the virtualization framework.
11#
12# ## How to use this script with Delve
13#
14# ### Use `DELVE_DEBUGSERVER_PATH` environment variable
15#
16# Override `debugserver` by setting the `DELVE_DEBUGSERVER_PATH` environment variable.
17# Ref: [Environment variables - Using Delve](https://github.com/go-delve/delve/blob/master/Documentation/usage/README.md#environment-variables)
18#
19# e.g. in `.vscode/launch.json`:
20# ```jsonc
21# {
22# "version": "0.2.0",
23# "configurations": [
24# {
25# "name": "hostagent for input instance",
26# "type": "go",
27# "request": "launch",
28# "mode": "debug",
29# // Use integratedTerminal to stop using ctrl+C
30# "console": "integratedTerminal",
31# "program": "${workspaceFolder}/cmd/limactl",
32# "buildFlags": [
33# "-ldflags=-X github.com/lima-vm/lima/pkg/version.Version=2.0.0-alpha.0",
34# ],
35# "env": {
36# "CGO_ENABLED": "1",
37# "DELVE_DEBUGSERVER_PATH": "${workspaceFolder}/hack/codesign/debugserver",
38# "LIMA_SSH_PORT_FORWARDER": "true",
39# },
40# "cwd": "${userHome}/.lima/${input:targetInstance}",
41# "args": [
42# "--debug",
43# "hostagent",
44# "--pidfile", "ha.pid",
45# "--socket", "ha.sock",
46# "--guestagent", "${workspaceFolder}/_output/share/lima/lima-guestagent.Linux-aarch64",
47# "${input:targetInstance}"
48# ],
49# },
50# ],
51# "inputs": [
52# {
53# "id": "targetInstance",
54# "type": "promptString",
55# "description": "Input target instance parameter for `limactl` command",
56# }
57# ]
58# }
59# ```
60#
61# ### Override `debugserver` in the PATH
62#
63# You can also override the `debugserver` in the PATH environment variable.
64#
65# e.g. in `.vscode/launch.json`:
66# ```diff
67# "env": {
68# "CGO_ENABLED": "1",
69# - "DELVE_DEBUGSERVER_PATH": "${workspaceFolder}/hack/codesign/debugserver",
70# + "PATH": "${workspaceFolder}/hack/codesign:${env:PATH}",
71# },
72# ```
73
74set -eu -o pipefail
75
76script_dir="$(dirname "$0")"
77
78# Codesign the target executable if vz.entitlements exists
79entitlements="${script_dir}/../../vz.entitlements"
80if [ -f "${entitlements}" ]; then
81 prev_arg=
82 for arg in "$@"; do
83 # find the target executable in the args next to "--"
84 if [ "${prev_arg}" = "--" ]; then
85 codesign --entitlements "${entitlements}" --force -s - -v "${arg}" || {
86 echo "error: codesign failed" >&2
87 exit 1
88 }
89 break
90 fi
91 prev_arg="${arg}"
92 done
93fi
94
95# Simulate how Delve locates debugserver
96# https://github.com/go-delve/delve/blob/65a6830eb7f0b882e0c52df0ef9585945ed55470/pkg/proc/gdbserial/gdbserver.go#L103-L129
97# 1. PATH (in this script, excluding the directory of this script to avoid recursion)
98candidate_paths="$(echo "${PATH}" | tr ':' '\n' | grep --fixed-strings --invert-match --line-regexp "${script_dir}" | paste -sd: -)"
99# 2. CommandLineTools LLDB path
100CLT_path="/Library/Developer/CommandLineTools"
101candidate_paths="${candidate_paths}:${CLT_path}/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/"
102# 3. Xcode LLDB path (if Xcode is installed)
103if developer_dir=$(xcode-select --print-path 2>/dev/null) && [ "${developer_dir}" != "${CLT_path}" ]; then
104 # Xcode is installed
105 candidate_paths="${candidate_paths}:${developer_dir}/../SharedFrameworks/LLDB.framework/Versions/A/Resources/"
106fi
107# Find debugserver in the candidate paths
108debugserver=$(PATH="${candidate_paths}" command -v debugserver) || {
109 echo "error: debugserver not found" >&2
110 exit 1
111}
112# Execute debugserver with the original arguments
113exec "${debugserver}" "$@"