截获 GDB 与 OpenOCD/GDB Server 之间的数据
可以用 socat ,也可以用 GDB 的 remotelogfile 截获 GDB 与 OpenOCD 之间的数据。
https://blog.csdn.net/zoomdy/article/details/100531857
zoomdy at 163 dot com
用 socat
截获 TCP 连接的数据
在 GDB 和 OpenOCD 之间插入 socat,OpenOCD 默认监听端口 3333,GDB 连接端口 3334,socat 连接端口 3334 和 3333:
socat -v -d -lf proxy.log TCP4-LISTEN:3334,reuseaddr,fork,su=nobody TCP4:localhost:3333
- -v 将传输的数据以文本的形式打印到 stderr
截获的部分数据经换行整理后如下所示,包含收发的时间戳和数据长度等:
> 2019/09/04 08:26:33.584773 length=142 from=0 to=141
+$qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+#df
< 2019/09/04 08:26:33.587760 length=1 from=0 to=0
+
< 2019/09/04 08:26:33.993189 length=1 from=1 to=1
+
< 2019/09/04 08:26:34.738053 length=116 from=2 to=117
$PacketSize=3fff;qXfer:memory-map:read+;qXfer:features:read+;qXfer:threads:read+;QStartNoAckMode+;vContSupported+#a3
> 2019/09/04 08:26:34.738793 length=20 from=142 to=161
+$vMustReplyEmpty#3a
< 2019/09/04 08:26:34.739236 length=5 from=118 to=122
+$#00
> 2019/09/04 08:26:34.739393 length=20 from=162 to=181
+$QStartNoAckMode#b0
< 2019/09/04 08:26:34.739845 length=7 from=123 to=129
+$OK#9a
> 2019/09/04 08:26:34.740056 length=8 from=182 to=189
+$Hg0#df
< 2019/09/04 08:26:34.751903 length=6 from=130 to=135
$OK#9a
截获串口数据
3334 端口和串口之间插入 socat,gdb 连接 3334 端口,通过 socat 转发到串口,socat 可以打印收发的数据。
socat -v -d OPEN:/dev/ttyACM0 TCP4-LISTEN:3334,fork
-v
将收发的数据打印出来OPEN:/dev/ttyACM0
要在TCP4-LISTEN:3334
的前面,如果调换次序会发生错误:Permission denied
参考
用 GDB 的 remotelogfile
打开 GDB ,在执行 target remote ...
命令之前,配置好 remotelogfile
变量,GDB 会将与 OpenOCD 的交互数据写入 remotelogfile
指定的文件内。
set remotelogfile remote.log
target remote ...
GDB 记录的日志文件时这个样子的:
c n
w $vCont?#49
r $#00
w $Hc0#db
r $OK#9a
w $s#73
r <Timeout: 0 seconds>$S02#b5
w $g#67
r $0000000001...#50
r $#00
w $m0,2#fb
r $6f00#fc
w $m2,2#fd
r $c015#f9
c c
w $c#63
r <Timeout: 0 seconds>
w \x03
r $S02#b5
w $g#67
r $0000000001...#c5
w $qL1200000000000000000#50
r $#00
w $m0,2#fb
r $6f00#fc
w $m2,2#fd
r $c015#f9
c q
w $vKill;a410#33
r $#00
w $k#6b
对比
socat 会记录数据收发的时间戳;但加入 socat 后,速度会变慢。
remotelogfile 不仅把收发的数据记录下来,还把命令也记录了下来。