Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1366551
  • 博文数量: 244
  • 博客积分: 3321
  • 博客等级: 中校
  • 技术积分: 2704
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-26 08:17
个人简介

微信公众号:杰夫弹弹看

文章分类

全部博文(244)

文章存档

2018年(4)

2017年(32)

2016年(25)

2015年(28)

2014年(27)

2013年(34)

2012年(25)

2011年(30)

2010年(39)

分类: C/C++

2015-10-08 12:47:07

Go官方没有指定的debugger, gdb因为不能很好的调试go程序,gdb对go的支持已经不再维护,参见

GDB does not understand Go programs well. The stack management, threading, and runtime contain aspects that differ enough from the execution model GDB expects that they can confuse the debugger, even when the program is compiled with gccgo. As a consequence, although GDB can be useful in some situations, it is not a reliable debugger for Go programs, particularly heavily concurrent ones. Moreover, it is not a priority for the Go project to address these issues, which are difficult. In short, the instructions below should be taken only as a guide to how to use GDB when it works, not as a guarantee of success.

In time, a more Go-centric debugging architecture may be required.


IRC问了一个go developer, 推荐 delve 或者使用fmt.Println() 
下面尝试使用delve,

1. Go Env 安装
确保你本地的环境已经安装了Go并且配置GOPATH,参见上一篇我的Go Env Setup

2. Delve 安装
$ git clone 

$ go get github.com/peterh/liner
$ go get github.com/spf13/cobra
$ go get golang.org/x/sys/unix
$ go get gopkg.in/yaml.v2


上面的get命令是安装相应的package。这事因为在make install的会报错,提示上面的package找不到

$ make install


3. 调试Go程序
$ dlv exec hello

(dlv) break hello.go:6

(dlv) continue
> main.main() ./hello.go:6
    
     1:     package main
     2:    
     3:     import "fmt"
     4:    
     5:     func main() {
=> 6:         i := 12
     7:         j := 13
     8:         t := i + j
     9:         fmt.Printf("hello, world\n")
    10:         fmt.Println(i, j, t)
    11:     }

(dlv) n

(dlv) print i
1


参考:


阅读(1110) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~