Golang現在GDB
效果很好
下面是一個例子golang應用gdbtest
- gdbtest/
- main.go
看看下面的例子main.go
package main
import "fmt"
type MyStruct struct {
x string
i int
f float64
}
func main() {
x := "abc"
i := 3
fmt.Println(i)
fmt.Println(x)
ms := &MyStruct{
x: "cba",
i: 10,
f: 11.10335,
}
fmt.Println(ms)
}
保存,爲爲主。去。然後用下面的gcflag
標誌進行編譯。
go build -gcflags "-N"
與新建golang應用
gdb gdbtest
# or
gdb <PROJECT_NAME>
打開GDB你現在有GDB的完全控制。例如,添加一個斷點與br <linenumber>
命令,然後用run
(gdb) br 22
Breakpoint 1 at 0x2311: file /go/src/github.com/cevaris/gdbtest/main.go, line 22.
(gdb) run
Starting program: /go/src/github.com/cevaris/gdbtest/gdbtest
3
abc
Breakpoint 1, main.main() at /go/src/github.com/cevaris/gdbtest/main.go:22
22 fmt.Println(ms)
(gdb)
執行的應用程序現在可以打印所有的局部變量
(gdb) info locals
i = 3
ms = 0x20819e020
x = 0xdb1d0 "abc"
即便可以訪問指針
(gdb) p ms
$1 = (struct main.MyStruct *) 0x20819e020
(gdb) p *ms
$2 = {x = 0xdb870 "cba", i = 10, f = 11.103350000000001}
謝謝,有什麼選擇,而不是GDB? – python 2014-09-02 15:20:47
有沒有其他的選擇 - 看看[這裏](http://stackoverflow.com/questions/16492509/does-any-golang-interactive-debugger-exist/23387017#23387017) – metakeule 2014-09-02 17:05:22
我試過去了1.4.rc2它似乎與gdb一起工作。 – 2014-12-10 02:40:37