go 远程调试dlv

简介: go 远程调试dlv

安装go环境

wget https://dl.google.com/go/go1.18.4.linux-amd64.tar.gz

 tar -zxvf go1.18.4.linux-amd64.tar.gz -C /usr/local/lib/

 ln -s /usr/local/lib/go/bin/* /usr/bin/

# 可选配置
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

go version

安装dlv

go install github.com/go-delve/delve/cmd/dlv@latest
ln -s /root/go/bin/dlv /usr/local/bin/dlv

查看dlv版本

[root@lys-mysql go]# dlv version
Delve Debugger
Version: 1.9.1
Build: $Id: d81b9fd12bfa603f3cf7a4bc842398bd61c42940 $

添加debug方案

修改为远程调试

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Connect to server",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "remotePath": "/root/go/src/hello",
            "port": 2345,
            "host": "10.6.8.248"
        }
    ]
}

启动服务层

[root@lys-mysql-ha0826001 hello]# dlv debug hello.go  --headless --listen ":2345" --log --api-version 2
API server listening at: [::]:2345
2022-08-29T15:09:09+08:00 warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2022-08-29T15:09:09+08:00 info layer=debugger launching process with args: [/root/go/src/hello/__debug_bin]
2022-08-29T15:09:17+08:00 info layer=debugger created breakpoint: &api.Breakpoint{ID:1, Name:"", Addr:0x498106, Addrs:[]uint64{0x498106}, File:"/root/go/src/hello/hello.go", Line:10, FunctionName:"main.main", Cond:"", HitCond:"", HitCondPerG:false, Tracepoint:false, TraceReturn:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(0xc0003ee330), LoadLocals:(*api.LoadConfig)(0xc0003ee390), WatchExpr:"", WatchType:0x0, VerboseDescr:[]string(nil), HitCount:map[string]uint64{}, TotalHitCount:0x0, Disabled:false, UserData:interface {}(nil)}
2022-08-29T15:09:17+08:00 info layer=debugger created breakpoint: &api.Breakpoint{ID:2, Name:"", Addr:0x498125, Addrs:[]uint64{0x498125}, File:"/root/go/src/hello/hello.go", Line:13, FunctionName:"main.main", Cond:"", HitCond:"", HitCondPerG:false, Tracepoint:false, TraceReturn:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(0xc0005267e0), LoadLocals:(*api.LoadConfig)(0xc000526810), WatchExpr:"", WatchType:0x0, VerboseDescr:[]string(nil), HitCount:map[string]uint64{}, TotalHitCount:0x0, Disabled:false, UserData:interface {}(nil)}
2022-08-29T15:09:17+08:00 info layer=debugger created breakpoint: &api.Breakpoint{ID:3, Name:"", Addr:0x498132, Addrs:[]uint64{0x498132}, File:"/root/go/src/hello/hello.go", Line:14, FunctionName:"main.main", Cond:"", HitCond:"", HitCondPerG:false, Tracepoint:false, TraceReturn:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(0xc0003ee630), LoadLocals:(*api.LoadConfig)(0xc0003ee690), WatchExpr:"", WatchType:0x0, VerboseDescr:[]string(nil), HitCount:map[string]uint64{}, TotalHitCount:0x0, Disabled:false, UserData:interface {}(nil)}
2022-08-29T15:09:17+08:00 debug layer=debugger continuing
2022-08-29T15:09:25+08:00 debug layer=debugger continuing
2022-08-29T15:09:27+08:00 debug layer=debugger continuing
2022-08-29T15:09:29+08:00 debug layer=debugger continuing
3 + 2 = 5
2022-08-29T15:09:29+08:00 debug layer=debugger continuing
2022-08-29T15:09:29+08:00 debug layer=debugger detaching

相关文章
|
Linux 测试技术 网络安全
嘿,Go开发时我是如何远程调试的
嘿,Go开发时我是如何远程调试的
1366 0
嘿,Go开发时我是如何远程调试的
|
8天前
|
Go
Go 语言循环语句
在不少实际问题中有许多具有规律性的重复操作,因此在程序中就需要重复执行某些语句。
17 1
|
7天前
|
Go 开发者
探索Go语言的并发之美
在Go语言的世界里,"并发"不仅仅是一个特性,它是一种哲学。本文将带你领略Go语言中goroutine和channel的魔力,揭示如何通过Go的并发机制来构建高效、可靠的系统。我们将通过一个简单的示例,展示如何利用Go的并发特性来解决实际问题,让你的程序像Go一样,轻盈而强大。
|
8天前
|
JSON Go API
使用Go语言和Gin框架构建RESTful API:GET与POST请求示例
使用Go语言和Gin框架构建RESTful API:GET与POST请求示例
|
8天前
|
Go
go语言创建字典
go语言创建字典
|
9天前
|
安全 Go 数据处理
探索Go语言的并发之美:Goroutines与Channels
在Go语言的世界里,"并发"不仅仅是一个概念,它是一种生活的方式。本文将带你领略Go语言中Goroutines和Channels的魔力,它们是如何让并发编程变得既简单又高效。我们将通过一个简单的示例,展示如何使用这些工具来构建一个高性能的网络服务。
|
9天前
|
关系型数据库 Go 数据处理
高效数据迁移:使用Go语言优化ETL流程
在本文中,我们将探索Go语言在处理大规模数据迁移任务中的独特优势,以及如何通过Go语言的并发特性来优化数据提取、转换和加载(ETL)流程。不同于其他摘要,本文不仅展示了Go语言在ETL过程中的应用,还提供了实用的代码示例和性能对比分析。
|
10天前
|
Go 定位技术 索引
Go 语言Map(集合) | 19
Go 语言Map(集合) | 19
|
10天前
|
Go
go语言注释,标识符 | 17
go语言注释,标识符 | 17
|
8天前
|
NoSQL Go API
go语言操作Redis
go语言操作Redis
下一篇
无影云桌面