golang 的调试比较麻烦,debug stop into 无法跳转到自己写的代码,但是能够跳转到系统提供的代码。
以下是简单的测试代码:
package mainimport (
"fmt"
)func main() {
i := 5
even(i)
b := 1
fmt.Printf("Is %d even? %v\n", i, b)
}func even(i int) bool {
a := 1
b := a + 1
b = b + 1
return i%2 == 0
}
这个情况太诡异了,网上到处是对golang gdb的吐槽。详情可以看这里:
http://grokbase.com/t/gg/golang-nuts/1443r0vch8/go-nuts-debugging-in-go-seems-to-be-a-very-difficult-task-to-accomplish
不过好在最后有人提供了LiteIDE里面设置的方式。
1 - Open your project in LiteIDE 2 - Select "Build" menu and under it select "Build Configuration..." 3 - A dialog shows up. Select "Custom" tab. It contains a list of key/value pairs 4 - Double click the space reserved for the value of "BUILDARGS" 5 - write -gcflags "-N -l" 6 - close the dialog by clicking Ok button 7 - rebuild your project (Ctrl+B) 8 - press F5 to start debugging 9 - put some breakpoints wherever you wish 10 - press f5 again to reach the first breakpoint
解决方案:
1 - 打开LiteIDE Build设置 2 - 修改BUILDARGS 变量,添加参数 -gcflags "-N -l" 注意这里有引号 3 - 保存后即可 4 - enjoy it
有疑问加站长微信联系(非本文作者)