golang 调试篇 一、go delve 使用

本文介绍了如何在Golang中使用Delve进行调试,包括安装过程和各种调试命令,如`debug`、`attach`、`exec`等,帮助开发者更有效地调试Go程序。
摘要由CSDN通过智能技术生成

一、安装  参考文档 https://github.com/go-delve/delve/blob/master/Documentation/installation/linux/install.md

二、使用

  1. go build hello.go 生成二进制文件 hello
dlv exec ./hello -- server --config conf/config.toml
break main.go:52

(dlv) break main.go:52
Breakpoint 1 set at 0x109b901 for main.main() ./main.go:52

(dlv) bp
Breakpoint runtime-fatal-throw at 0x1028450 for runtime.fatalthrow() /usr/local/go/src/runtime/panic.go:663 (0)
Breakpoint unrecovered-panic at 0x10284c0 for runtime.fatalpanic() /usr/local/go/src/runtime/panic.go:690 (0)
	print runtime.curg._panic.arg
Breakpoint 1 at 0x109b901 for main.main() ./main.go:52 (0)


(dlv) c
> main.main() ./main.go:52 (hits goroutine(1):1 total:1) (PC: 0x109b901)
Warning: debugging optimized function
    47:		return n
    48:	}
    49:	
    50:	func main() {
    51:		// Create the network
=>  52:		net := NewGreetingApp()
    53:		// We need a channel to talk to it
    54:		in := make(chan string)
    55:		net.SetInPort("In", in)
    56:		// Run the net
    57:		wait := goflow.Run(net)

(dlv) b +2     //偏移量2加断点
Breakpoint 2 set at 0x109b90f for main.main() ./main.go:54

(dlv) next    //下一个断点
> main.main() ./main.go:54 (hits goroutine(1):1 total:1) (PC: 0x109b90f)
Warning: debugging optimized function
    49:	
    50:	func main() {
    51:		// Create the network
    52:		net := NewGreetingApp()
    53:		// We need a channel to talk to it
=>  54:		in := make(chan string)
    55:		net.SetInPort("In", in)
    56:		// Run the net
    57:		wait := goflow.Run(net)
    58:		// Now we can send some names and see what happens
    59:		in <- "John"

(dlv) n
> main.main() ./main.go:55 (PC: 0x10c1d82)
    50:	func main() {
    51:		// Create the network
    52:		net := NewGreetingApp()
    53:		// We need a channel to talk to it
    54:		in := make(chan string)
=>  55:		net.SetInPort("In", in)
    56:		// Run the net
    57:		wait := goflow.Run(net)
    58:		// Now we can send some names and see what happens
    59:		in <- "John"
    60:		in <- "Boris"

(dlv) p in  //打印变量
chan string {
	qcount: 0,
	dataqsiz: 0,
	buf: *[0]string [],
	elemsize: 16,
	closed: 0,
	elemtype: *runtime._type {
		size: 16,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值