0%

Use gdb to debuuging golang program

好久沒寫文章了,把之前看到的資料記一記。馬有失蹄,人有錯手,在怎麼宣告不用Debugger的Programming language,可能也需要gdb搭配使用,這邊紀錄一下如何用gdb來幫助golan除錯。
範例程式

1
2
3
4
5
6
7
8
9
10
11
12
package main

import (
"fmt"
)

func main() {
for i := 0; i < 5; i++ {
fmt.Println("Loop")
}
fmt.Println("Done")
}

編譯時間入debuu info

1
$ go build -gcflags "-N -l" test.go

積著就可以照

1
2
$ gdb test
$ b main.main

之後就能夠像之前一樣使用gdb了

Reference

Debugging Go Code with GDB
– [Debugging Go (golang) programs with gdb ]http://thornydev.blogspot.tw/2014/01/debugging-go-golang-programs-with-gdb.html)
Introduction to Go Debugging with GDB
Using the gdb debugger with Go