前置要求

-ldflags-w -s
# file alert-sd-engine
alert-sd-engine: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

使用方式

funcs
funcs
(dlv) funcs VmSvc
devops/alert-sd-engine/pkg.(*Monitor).createVmSvcScrape
devops/alert-sd-engine/pkg.(*Monitor).deleteVmSvcScrape
devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape
devops/alert-sd-engine/pkg.(*Monitor).isVmSvcScrapeExist
devops/alert-sd-engine/pkg.(*Monitor).updateVmSvcScrape
devops/alert-sd-engine/pkg.createVmSvcScrape
devops/alert-sd-engine/pkg.deleteVmSvcScrape
devops/alert-sd-engine/pkg.getVmSvcScrape
devops/alert-sd-engine/pkg.updateVmSvcScrape

使用break(b)打断点

funcsbreak
(dlv) break devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape

当然也可以使用如下方式将断点打到文件的某一行

(dlv) b engine.go:196
breakpoints
(dlv) breakpoints
Breakpoint runtime-fatal-throw (enabled) at 0x4345e0 for runtime.throw() /usr/local/go/src/runtime/panic.go:1188 (0)
Breakpoint unrecovered-panic (enabled) at 0x434940 for runtime.fatalpanic() /usr/local/go/src/runtime/panic.go:1271 (0)
        print runtime.curg._panic.arg
Breakpoint 2 (enabled) at 0x1399452 for devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape() .alert-sd-engine/pkg/engine.go:195 (0)
Breakpoint 4 (enabled) at 0x1399479 for devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape() ./alert-sd-engine/pkg/engine.go:196 (0)
clear
clear
clearall
goroutines
(dlv) goroutines
  Goroutine 1 - User: /usr/local/go/src/net/fd_unix.go:173 net.(*netFD).accept (0x5f4f55) [IO wait]
  Goroutine 2 - User: /usr/local/go/src/runtime/proc.go:367 runtime.gopark (0x4370f6) [force gc (idle) 455958h37m56.413188346s]
  Goroutine 3 - User: /usr/local/go/src/runtime/proc.go:367 runtime.gopark (0x4370f6) [GC sweep wait]
  Goroutine 4 - User: /usr/local/go/src/runtime/proc.go:367 runtime.gopark (0x4370f6) [GC scavenge wait]
goroutine
stack(bt)goroutine
(dlv) goroutine 1 stack
 0  0x00000000004370f6 in runtime.gopark
    at /usr/local/go/src/runtime/proc.go:367
 1  0x000000000042f7fe in runtime.netpollblock
    at /usr/local/go/src/runtime/netpoll.go:445
 2  0x000000000045efa9 in internal/poll.runtime_pollWait
    at /usr/local/go/src/runtime/netpoll.go:229
frameupdown
attach
attach
locals-v
(dlv) locals -v req
req = devops/alert-sd-engine/pkg.Req {
        Base: devops/alert-sd-engine/pkg.commData {
                Env: 0,
                ClusterName: "",
                DualActive: false,
                Namespace: "",
                Name: "",
                Endpoints: []devops/alert-sd-engine/pkg.Endpoint len: 0, cap: 0, nil,},
        Selector: struct { Appid string "json:\"appId,omitempty\"" } {Appid: ""},}

更多参见官方文档