(gdb) l main.main #查看源代码代码
(gdb) b 50 #设置断点
(gdb) info b #查看断点信息
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000002239 in main.main at /Users/kenshin/workspace/gogo/test.go:50
(gdb) run #运行,直到触发断点中断
(gdb) n #继续执行下一行
(gdb) s #进入函数/方法
(gdb) info locals #查看局部变量ma
err = {tab = 0x0, data = 0xc2000bdfc0}
(gdb) info args #查看参数
s = 0xc2000b6f00
addr = "0.0.0.0:8000"
(gdb) help info
(gdb) p addr #打印变量
$6 = "0.0.0.0:8000"
(gdb) c #继续执行,直到下一个断点
(gdb) whatis s #查看变量类型
type = struct github.com/hoisie/web.Server *
(gdb) where/bt #查看堆栈信息,判断函数调用关系
#0 net.resolveInternetAddr (net="udp4") at /usr/local/go/src/pkg/net/ipsock.go:164
#1 in net.ResolveUDPAddr (net="udp4") at /usr/local/go/src/pkg/net/udpsock.go:45
#2 in main.SocketListen (ip="127.0.0.1") at /Users/kenshin/workspace/gor/test.go:13
(gdb) up #回到上一层调用函数
#0 in net.ResolveUDPAddr (net="udp4") at /usr/local/go/src/pkg/net/udpsock.go:45
#1 in main.SocketListen (ip="127.ma0.0.1") at /Users/kenshin/workspace/gor/test.go:13
(gdb) down #再进入下一层函数
#0 net.resolveInternetAddr (net="udp4") at /usr/local/go/src/pkg/net/ipsock.go:164
#1 in net.ResolveUDPAddr (net="udp4") at /usr/local/go/src/pkg/net/udpsock.go:45
#2 in main.SocketListen (ip="127.0.0.1") at /Users/kenshin/workspace/gor/test.go:13
(gdb) shell #输入shell,可以进入到shell,输入exit退出shell回到gdb环境
bash-3.2# exit
(gdb) p r # r string := "process"
$16 = {str = 0x2f0170 "process", len = 7}
(gdb) p r-> #可以通过`TAB`获得一些提示
len str
(gdb) p r->str
$17 = (uint8 *) 0x2f0170 "process"
(gdb) l main.main #查看源代码代码
(gdb) b 50 #设置断点
(gdb) info b #查看断点信息
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000002239 in main.main at /Users/kenshin/workspace/gogo/test.go:50
(gdb) run #运行,直到触发断点中断
(gdb) n #继续执行下一行
(gdb) s #进入函数/方法
(gdb) info locals #查看局部变量ma
err = {tab = 0x0, data = 0xc2000bdfc0}
(gdb) info args #查看参数
s = 0xc2000b6f00
addr = "0.0.0.0:8000"
(gdb) help info
(gdb) p addr #打印变量
$6 = "0.0.0.0:8000"
(gdb) c #继续执行,直到下一个断点
(gdb) whatis s #查看变量类型
type = struct github.com/hoisie/web.Server *
(gdb) where/bt #查看堆栈信息,判断函数调用关系
#0 net.resolveInternetAddr (net="udp4") at /usr/local/go/src/pkg/net/ipsock.go:164
#1 in net.ResolveUDPAddr (net="udp4") at /usr/local/go/src/pkg/net/udpsock.go:45
#2 in main.SocketListen (ip="127.0.0.1") at /Users/kenshin/workspace/gor/test.go:13
(gdb) up #回到上一层调用函数
#0 in net.ResolveUDPAddr (net="udp4") at /usr/local/go/src/pkg/net/udpsock.go:45
#1 in main.SocketListen (ip="127.ma0.0.1") at /Users/kenshin/workspace/gor/test.go:13
(gdb) down #再进入下一层函数
#0 net.resolveInternetAddr (net="udp4") at /usr/local/go/src/pkg/net/ipsock.go:164
#1 in net.ResolveUDPAddr (net="udp4") at /usr/local/go/src/pkg/net/udpsock.go:45
#2 in main.SocketListen (ip="127.0.0.1") at /Users/kenshin/workspace/gor/test.go:13
(gdb) shell #输入shell,可以进入到shell,输入exit退出shell回到gdb环境
bash-3.2# exit
(gdb) p r # r string := "process"
$16 = {str = 0x2f0170 "process", len = 7}
(gdb) p r-> #可以通过`TAB`获得一些提示
len str
(gdb) p r->str
$17 = (uint8 *) 0x2f0170 "process"