编译应用
go build -gcflags "-N -l"
运行GDB
gdb demo -d '$GOROOT'
如果报下面的错误,是因为 MacOS 运行 GDB 需要给 GDB 程序签名,操作步骤
Unable to find Mach task port for process-id 40764: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
给指定方法设置断点
b github.com/demo/pkg.(*St).Fn
打印全局变量
需要加引号
p 'github.com/demo/pkg.Default'
查看断点
info breakpoints
暂停断点
disable 1
启用断点
enable 1