Skip to content

Commit abbc487

Browse files
authored
Merge pull request #2651 from norio-nomura/improve-debugging-with-dlv-dap
Improve debugging with `dlv dap` (in VSCode, for example)
2 parents 996b340 + 9c75559 commit abbc487

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

hack/toolexec-for-codesign.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
3+
# This script is used to wrap the compiler and linker commands in the build
4+
# process. It captures the output of the command and logs it to a file.
5+
# The script's primary purpose is codesigning the output of the linker command
6+
# with the entitlements file if it exists.
7+
# If the OS is macOS, the result of the command is 0, the entitlements file
8+
# exists, and codesign is available, sign the output of the linker command with
9+
# the entitlements file.
10+
#
11+
# Usage:
12+
# go build -toolexec hack/toolexec-to-codesign.sh
13+
14+
repository_root="$(dirname "$(dirname "$0")")"
15+
logfile="${repository_root}/.toolexec-to-codesign.log"
16+
17+
echo $$: cmd: "$@" >>"${logfile}"
18+
19+
output="$("$@")"
20+
result=$?
21+
22+
echo $$: output: "${output}" >>"${logfile}"
23+
24+
entitlements="${repository_root}/vz.entitlements"
25+
26+
# If the OS is macOS, the result of the command is 0, the entitlements file
27+
# exists, and codesign is available, sign the output of the linker command.
28+
if OS=$(uname -s) && [ "${OS}" = "Darwin" ] && [ "${result}" -eq 0 ] && [ -f "${entitlements}" ] && command -v codesign >/dev/null 2>&1; then
29+
# Check if the command is a linker command.
30+
case "$1" in
31+
*link)
32+
shift
33+
# Find a parameter that is a output file.
34+
while [ $# -gt 1 ]; do
35+
case "$1" in
36+
-o)
37+
# If the output file is a executable, sign it with the entitlements file.
38+
if [ -x "$2" ]; then
39+
codesign_output="$(codesign -v --entitlements "${entitlements}" -s - "$2" 2>&1)"
40+
echo "$$: ${codesign_output}" >>"${logfile}"
41+
fi
42+
break
43+
;;
44+
*) shift ;;
45+
esac
46+
done
47+
;;
48+
*) ;;
49+
esac
50+
fi
51+
52+
# Print the output of the command and exit with the result of the command.
53+
echo "${output}"
54+
exit "${result}"

pkg/usrlocalsharelima/usrlocalsharelima.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"runtime"
1010

1111
"github.com/lima-vm/lima/pkg/limayaml"
12+
"github.com/sirupsen/logrus"
1213
)
1314

1415
func Dir() (string, error) {
@@ -49,6 +50,15 @@ func Dir() (string, error) {
4950
filepath.Join(selfDirDir, "share/lima/lima-guestagent."+ostype+"-"+arch),
5051
// TODO: support custom path
5152
}
53+
if logrus.GetLevel() == logrus.DebugLevel {
54+
// candidate 2: lauched by `~/go/bin/dlv dap`
55+
// - self: ${workspaceFolder}/cmd/limactl/__debug_bin_XXXXXX
56+
// - agent: ${workspaceFolder}/_output/share/lima/lima-guestagent.Linux-x86_64
57+
// - dir: ${workspaceFolder}/_output/share/lima
58+
candidateForDebugBuild := filepath.Join(filepath.Dir(selfDirDir), "_output/share/lima/lima-guestagent."+ostype+"-"+arch)
59+
gaCandidates = append(gaCandidates, candidateForDebugBuild)
60+
logrus.Infof("debug build detected, adding more guest agent candidates: %v", candidateForDebugBuild)
61+
}
5262
for _, gaCandidate := range gaCandidates {
5363
if _, err := os.Stat(gaCandidate); err == nil {
5464
return filepath.Dir(gaCandidate), nil

0 commit comments

Comments
 (0)