【vscode】vscode远程调试

使用Delve调试时将参数传递给可执行文件

在有main.go的地方执行:

1
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build  -gcflags="all=-N -l"
1
go build -gcflags="all=-N -l"

会生成二进制文件

Add -- to tell dlv that all subsequent arguments should be passed verbatim to the binary, without trying to parse them:

1
dlv --listen=:5432 exec /mypath/binary -- --config=config.toml

2023.02.13 下载编译更新dlv

github地址:https://github.com/go-delve/delve/releases

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
[root@ningan ~]# wget https://github.com/go-delve/delve/archive/refs/tags/v1.20.0.tar.gz
[root@ningan ~]# mkdir dlv
[root@ningan ~]# mv v1.20.0.tar.gz dlv
[root@ningan ~]# cd dlv
[root@ningan dlv]# ll
total 8980
drwxr-xr-x 2 root root 4096 Feb 13 10:19 ./
drwx------ 56 root root 4096 Feb 13 10:19 ../
-rw-r--r-- 1 root root 9184679 Feb 13 10:18 v1.20.0.tar.gz


[root@ningan dlv]# tar -zxvf v1.20.0.tar.gz
[root@ningan dlv]# ll
total 8984
drwxr-xr-x 3 root root 4096 Feb 13 10:19 ./
drwx------ 56 root root 4096 Feb 13 10:19 ../
drwxrwxr-x 11 root root 4096 Dec 9 02:34 delve-1.20.0/
-rw-r--r-- 1 root root 9184679 Feb 13 10:18 v1.20.0.tar.gz


[root@ningan delve-1.20.0]# ll
total 168
drwxrwxr-x 11 root root 4096 Dec 9 02:34 ./
drwxr-xr-x 3 root root 4096 Feb 13 10:19 ../
drwxrwxr-x 2 root root 4096 Dec 9 02:34 assets/
-rw-rw-r-- 1 root root 44712 Dec 9 02:34 CHANGELOG.md
-rw-rw-r-- 1 root root 157 Dec 9 02:34 .cirrus.yml
drwxrwxr-x 3 root root 4096 Dec 9 02:34 cmd/
-rw-rw-r-- 1 root root 2440 Dec 9 02:34 CONTRIBUTING.md
-rw-rw-r-- 1 root root 248 Dec 9 02:34 .deepsource.toml
drwxrwxr-x 7 root root 4096 Dec 9 02:34 Documentation/
drwxrwxr-x 18 root root 4096 Dec 9 02:34 _fixtures/
-rw-rw-r-- 1 root root 29 Dec 9 02:34 .gitattributes
-rw-rw-r-- 1 root root 111 Dec 9 02:34 .gitignore
-rw-rw-r-- 1 root root 868 Dec 9 02:34 go.mod
-rw-rw-r-- 1 root root 40428 Dec 9 02:34 go.sum
-rw-rw-r-- 1 root root 640 Dec 9 02:34 ISSUE_TEMPLATE.md
-rw-rw-r-- 1 root root 1079 Dec 9 02:34 LICENSE
-rw-rw-r-- 1 root root 970 Dec 9 02:34 Makefile
drwxrwxr-x 13 root root 4096 Dec 9 02:34 pkg/
-rw-rw-r-- 1 root root 1632 Dec 9 02:34 README.md
drwxrwxr-x 2 root root 4096 Dec 9 02:34 _scripts/
drwxrwxr-x 10 root root 4096 Dec 9 02:34 service/
drwxrwxr-x 2 root root 4096 Dec 9 02:34 .teamcity/
drwxrwxr-x 6 root root 4096 Dec 9 02:34 vendor/

[root@ningan delve-1.20.0]# cat Makefile
.DEFAULT_GOAL=test

SHELL := /bin/bash
GO_SRC := $(shell find . -type f -not -path './_fixtures/*' -not -path './vendor/*' -not -path './_scripts/*' -not -path './localtests/*' -name '*.go')

check-cert:
@go run _scripts/make.go check-cert

build: $(GO_SRC)
@go run _scripts/make.go build

install: $(GO_SRC)
@go run _scripts/make.go install

uninstall:
@go run _scripts/make.go uninstall

test: vet
@go run _scripts/make.go test

vet:
@go vet $$(go list ./... | grep -v native)

test-proc-run:
@go run _scripts/make.go test -s proc -r $(RUN)

test-integration-run:
@go run _scripts/make.go test -s service/test -r $(RUN)

vendor:
@go run _scripts/make.go vendor

build-ebpf-image:
./pkg/proc/internal/ebpf/build/build-ebpf-builder-img.sh

build-ebpf-object: build-ebpf-image
./pkg/proc/internal/ebpf/build/build-ebpf-objects.sh

.PHONY: vendor test-integration-run test-proc-run test check-cert install build vet uninstall build-ebpf-image build-ebpf-object
[root@ningan delve-1.20.0]#



[root@ningan delve-1.20.0]# go run _scripts/make.go build
2023/02/13 10:20:28 error getting build SHA via git: %!w(*exec.ExitError=&{0xc0001980c0 []})
go build -ldflags "-extldflags -static" -ldflags= github.com/go-delve/delve/cmd/dlv

[root@ningan delve-1.20.0]# ll
total 17440
drwxrwxr-x 11 root root 4096 Feb 13 10:20 ./
drwxr-xr-x 3 root root 4096 Feb 13 10:19 ../
drwxrwxr-x 2 root root 4096 Dec 9 02:34 assets/
-rw-rw-r-- 1 root root 44712 Dec 9 02:34 CHANGELOG.md
-rw-rw-r-- 1 root root 157 Dec 9 02:34 .cirrus.yml
drwxrwxr-x 3 root root 4096 Dec 9 02:34 cmd/
-rw-rw-r-- 1 root root 2440 Dec 9 02:34 CONTRIBUTING.md
-rw-rw-r-- 1 root root 248 Dec 9 02:34 .deepsource.toml
-rwxr-xr-x 1 root root 17683376 Feb 13 10:20 dlv*
drwxrwxr-x 7 root root 4096 Dec 9 02:34 Documentation/
drwxrwxr-x 18 root root 4096 Dec 9 02:34 _fixtures/
-rw-rw-r-- 1 root root 29 Dec 9 02:34 .gitattributes
-rw-rw-r-- 1 root root 111 Dec 9 02:34 .gitignore
-rw-rw-r-- 1 root root 868 Dec 9 02:34 go.mod
-rw-rw-r-- 1 root root 40428 Dec 9 02:34 go.sum
-rw-rw-r-- 1 root root 640 Dec 9 02:34 ISSUE_TEMPLATE.md
-rw-rw-r-- 1 root root 1079 Dec 9 02:34 LICENSE
-rw-rw-r-- 1 root root 970 Dec 9 02:34 Makefile
drwxrwxr-x 13 root root 4096 Dec 9 02:34 pkg/
-rw-rw-r-- 1 root root 1632 Dec 9 02:34 README.md
drwxrwxr-x 2 root root 4096 Dec 9 02:34 _scripts/
drwxrwxr-x 10 root root 4096 Dec 9 02:34 service/
drwxrwxr-x 2 root root 4096 Dec 9 02:34 .teamcity/
drwxrwxr-x 6 root root 4096 Dec 9 02:34 vendor/
[root@ningan delve-1.20.0]#

[root@ningan delve-1.20.0]# ./dlv version
Delve Debugger
Version: 1.20.0
Build: $Id: 8ec46ee3d275c276b8e7465d69a23399e0e14789 $

2023.02.24 编译dlv arm版

1
go run _scripts/make.go build --GOARCH arm64

参考

远程调试你的代码(重要)

使用Delve调试时将参数传递给可执行文件

Go gcflags/ldflags 的说明

真香预警,这个VSCODE可视化调试Go程序的方式,比直接用 dlv 命令香多了


【vscode】vscode远程调试
http://example.com/2022/07/23/software/【vscode】vscode远程调试/
作者
ningan123
发布于
2022年7月23日
许可协议