zoukankan      html  css  js  c++  java
  • GO语言调试利器dlv快速上手

     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)]
  • 相关阅读:
    Mysql初始化root密码和允许远程访问
    windows下nodejs express安装及入门网站,视频资料,开源项目介绍
    python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码
    python3.4学习笔记(二十五) Python 调用mysql redis实例代码
    python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法
    python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码
    python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字
    python3.4学习笔记(二十一) python实现指定字符串补全空格、前面填充0的方法
    python3.4学习笔记(二十) python strip()函数 去空格 函数的用法
    python3.4学习笔记(十九) 同一台机器同时安装 python2.7 和 python3.4的解决方法
  • 原文地址:https://www.cnblogs.com/dream397/p/14277763.html
Copyright © 2011-2022 走看看