增加 GDB 远程调试 Golang.

Signed-off-by: chen.yang <chen.yang@yuzhen-iot.com>
This commit is contained in:
chen.yang 2021-11-02 23:58:00 +08:00
parent 608f1bb9d9
commit e8914930a3
2 changed files with 45 additions and 2 deletions

View File

@ -3,11 +3,17 @@
## 1.基本指令
```bash
# 设置调试目标文件(解决找不到符号或找不到文件问题)
(gdb) file <debug targe file>
# 开启/关闭伪图形窗口
(gdb) tui enable/disable
# 设置参数
(gdb) r <arg 1> <arg 2> ...
# 查看各级函数调用及参数
(gdb) backtrace
(gdb) bt
# 切换调用栈
(gdb) f <n>
# 退出 gdb 调试环境
(gdb) quit
(gdb) q
@ -22,14 +28,17 @@
# 删除断点
(gdb) delete [breakpoints num] [range...]
(gdb) d [breakpoints num] [range...]
# 查看断点信息(breakpoints num)
(gdb) info breakpoints
(gdb) info b
# 禁用断点
(gdb) dis <breakpoints num>
# 清除全部断点
(gdb) clear
# 删除所选定的环境中所有的断点
(gdb) clear <location>
```
可通过 info breakpoints 获取 breakpoints num 等断点信息。
## 3.执行控制
```bash

View File

@ -0,0 +1,34 @@
# GDB 远程调试 Golang
## Target
```bash
gdbserver :<port> <program name>
# 如 gdbserver :889 demo-go
```
## Host
```bash
arm-linux-gnueabihf-gdb
# 如: target remote 192.168.1.100:8899
(gdb) target remote <remote ip>:<remote port>
(gdb) set language go
# 如: file /host/path/to/demo-go
(gdb) file <debug targe file>
(gdb) b <file>:<line>
(gdb) b <package>.<function>
# 查看调用栈
(gdb) bt
# 切换调用栈
(gdb) f <n>
# 查看 goroutine
(gdb) info goroutines
(gdb) goroutines <n> bt
```
GDB 调试 Golang 无法查看 string、slice 等类型。
## 外部参考资料
1. [Golang 程序调试工具介绍(gdb vs dlv)](https://blog.csdn.net/dianfu2892/article/details/101466591)