调试windows服务breakpoint_使用delve调试Golang程序

d1d1f1a1d42e19947d98d01c63a5a784.png

delve是一款专门针对Golang程序调试而开发的命令行调试器,该工具功能强大,简单易用。

本文从安装开始,使用一个实际的Golang程序调试例子,学习一下delve的主要调试方式及常用调试命令。

本文所使用的是Windows环境。

1 安装

使用go get命令安装构建delve。

$ go get -u github.com/go-delve/delve/cmd/dlv

其会在$GOPATH/bin下生成二进制可执行文件dlv.exe,将$GOPATH/bin添加到PATH环境变量即可在任意目录使用dlv。

2 主要调试方式

键入dlv help可以看到dlv的使用帮助文档。

$ dlv helpDelve is a source level debugger for Go programs.Delve enables you to interact with your program by controlling the execution of the process,evaluating variables, and providing information of thread / goroutine state, CPU register state and more.The goal of this tool is to provide a simple yet powerful interface for debugging Go programs.Pass flags to the program you are debugging using `--`, for example:`dlv exec ./hello -- server --config conf/config.toml`Usage: dlv [command]Available Commands: attach Attach to running process and begin debugging. connect Connect to a headless debug server. core Examine a core dump. debug Compile and begin debugging main package in current directory, or the package specified. exec Execute a precompiled binary, and begin a debug session. help Help about any command run Deprecated command. Use 'debug' instead. test Compile test binary and begin debugging program. trace Compile and begin tracing program. version Prints version.Flags: ...

下面我们会结合一个实际的例子看一下主要的几种调试方式。

我们就以Golang官方的例子github.com/golang/example/hello着手吧。

$ go get -u github.com/golang/example/hello

如上命令会将github.com/golan

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值