GO语言调试利器dlv快速上手

摘要:
https://www.cnblogs.com/realjimmy/p/13418508.html1、dlv的安装1)下载dlvgitclonehttps://github.com/go-delve/delve.git$GOPATH/src/github。com、go digit或gogetgithub。com/derekparker/indige/cmd/dlvroot@cloud :

 https://www.cnblogs.com/realjimmy/p/13418508.html

 
 
一、dlv的安装

1)下载dlv

git clone https://github.com/go-delve/delve.git $GOPATH/src/github.com/go-delve/delve

或者 go get github.com/derekparker/delve/cmd/dlv

root@cloud:~# go version
go version go1.14.10 linux/arm64

2)安装

cd $GOPATH/src/github.com/go-delve/delve

make install

root@cloud:~/delve# make install -j $(nproc)
go install "-ldflags=-X main.Build=1b2357092c8fee7406988d8191f71059700c5399" github.com/go-delve/delve/cmd/dlv
root@cloud:~/delve# dlv -h
Delve 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`
(dlv) bp
Breakpoint runtime-fatal-throw at 0x429a0 for runtime.fatalthrow() GOROOT/src/runtime/panic.go:1162 (0)
Breakpoint unrecovered-panic at 0x42a00 for runtime.fatalpanic() GOROOT/src/runtime/panic.go:1189 (0)
        print runtime.curg._panic.arg
Breakpoint 1 at 0x3edc70 for gvisor.dev/gvisor/pkg/sentry/mm.(*MemoryManager).MMap() pkg/sentry/mm/syscalls.go:75 (1)
(dlv) clear 1
Breakpoint 1 cleared at 0x3edc70 for gvisor.dev/gvisor/pkg/sentry/mm.(*MemoryManager).MMap() pkg/sentry/mm/syscalls.go:75
(dlv) bp
Breakpoint runtime-fatal-throw at 0x429a0 for runtime.fatalthrow() GOROOT/src/runtime/panic.go:1162 (0)
Breakpoint unrecovered-panic at 0x42a00 for runtime.fatalpanic() GOROOT/src/runtime/panic.go:1189 (0)
        print runtime.curg._panic.arg
(dlv) quit
Would you like to kill the process? [Y/n] n
root@cloud:~/delve# 
dlv和golang
root@cloud:~/delve# dlv -h

Command 'dlv' not found, did you mean:

  command 'ddv' from deb ncbi-tools-x11
  command 'delv' from deb dnsutils
  command 'dav' from deb dav-text
  command 'lv' from deb lv
  command 'dlg' from deb pccts
  command 'dll' from deb brickos

Try: apt install <deb name>

root@cloud:~/delve# source ~/hyper/go_source 
root@cloud:~/delve# dlv -h
Delve 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`
查看协程
(dlv) goroutines
Goroutine 1 - User: GOROOT/src/runtime/sema.go:56 sync.runtime_Semacquire (0x73ac8) [semacquire]
Goroutine 2 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [force gc (idle)]
Goroutine 3 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC sweep wait]
Goroutine 4 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC scavenge wait]
Goroutine 5 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 6 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 7 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 8 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 9 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 10 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 11 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 12 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 13 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]
Goroutine 14 - User: GOROOT/src/runtime/proc.go:307 runtime.gopark (0x450c0) [GC worker (idle)]

免责声明:文章转载自《GO语言调试利器dlv快速上手》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇自动化测试报告allure 并集成到Jenkins 分布式配置Java程序员必备后台前端框架--Layui【从入门到实战】(二)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

WF Workflow 状态机工作流 开发

概述 工作流是对业务流程的建模,当我们设计工作流的时候,我们首先要分析业务处理过程中要经历的步骤。然后,我们就可以利用WF创建工作流模型来模拟业务的处理过程。 我们知道,WF包含两种类型的工作流:顺序工作流和状态机工作流。顺序工作流提供了一系列有组织的步骤,一般情况下,步骤是逐一执行的。可能有的步骤需要等待某些事件的发生才可以继续执行,但通常情况下顺序工作...

go语言 robfig/cron包 实现定时 调用

package main import ( "github.com/robfig/cron" "time" "fmt" "os" log "github.com/cihub/seelog" ) var ( ttt int ) const ( logFilePath = "hard/log/test/t...

【Go语言系列】在VsCode中配置Go的开发环境

一、为什么选VSCode 这个系列的初宗是带领公司的PHPer转Go,在正式写这篇博文前,咱们先说说Go有哪些主流的IDE 1、GoLand(收费) JetBrains出品必属精品,除了贵没有其它缺点,如果你用这款IDE,我只想说出门右转,不送!~~~~ 2、LiteIDE(免费)LiteIDE是一个简单的开源IDE。值得注意的是,它是Go语言2012年正...

《ArcGIS Runtime SDK for Android开发笔记》——离在线一体化技术:离线矢量数据下载

1、前言 1.1、环境准备: ArcGIS for Desktop 10.4.1(10.2.1以上版本即可) ArcGIS for Server 10.4.1 (10.2.1以上版本即可) PostgreSQL、Microsoft SQL Server、或 Oracle 设置企业级地理数据库。 1.2、发布具有同步能力的FeatureService服...

eclipse server Runtime Environment 环境配置

需要在Eclipse中调试或运行Servlet程序需要新建Server,但是遇到了无法新建的问题,这是因为Server Runtime Environment没有配置的问题。 如果确定了加入了tomcat创建web项目时候选择相应的tomcat版本如图 那么下次打开就是默认了. 2.不确定安装tomcat 点击Window->Pre...

基于docker安装superset

    检查是否已安装docker(docker version)root@VM-32-248-ubuntu:~# docker versionClient: Version:      1.13.1 API version:  1.26 Go version:   go1.6.2 Git commit:   092cba3 Built:        T...