截获 GDB 与 OpenOCD/GDB Server 之间的数据

旧城等待, 2024-04-18 08:30 143阅读 0赞

截获 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:

  1. socat -v -d -lf proxy.log TCP4-LISTEN:3334,reuseaddr,fork,su=nobody TCP4:localhost:3333
  • -v 将传输的数据以文本的形式打印到 stderr

截获的部分数据经换行整理后如下所示,包含收发的时间戳和数据长度等:

  1. > 2019/09/04 08:26:33.584773 length=142 from=0 to=141
  2. +$qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+#df
  3. < 2019/09/04 08:26:33.587760 length=1 from=0 to=0
  4. +
  5. < 2019/09/04 08:26:33.993189 length=1 from=1 to=1
  6. +
  7. < 2019/09/04 08:26:34.738053 length=116 from=2 to=117
  8. $PacketSize=3fff;qXfer:memory-map:read+;qXfer:features:read+;qXfer:threads:read+;QStartNoAckMode+;vContSupported+#a3
  9. > 2019/09/04 08:26:34.738793 length=20 from=142 to=161
  10. +$vMustReplyEmpty#3a
  11. < 2019/09/04 08:26:34.739236 length=5 from=118 to=122
  12. +$#00
  13. > 2019/09/04 08:26:34.739393 length=20 from=162 to=181
  14. +$QStartNoAckMode#b0
  15. < 2019/09/04 08:26:34.739845 length=7 from=123 to=129
  16. +$OK#9a
  17. > 2019/09/04 08:26:34.740056 length=8 from=182 to=189
  18. +$Hg0#df
  19. < 2019/09/04 08:26:34.751903 length=6 from=130 to=135
  20. $OK#9a

截获串口数据

3334 端口和串口之间插入 socat,gdb 连接 3334 端口,通过 socat 转发到串口,socat 可以打印收发的数据。

  1. socat -v -d OPEN:/dev/ttyACM0 TCP4-LISTEN:3334,fork
  • -v 将收发的数据打印出来
  • OPEN:/dev/ttyACM0 要在 TCP4-LISTEN:3334 的前面,如果调换次序会发生错误:Permission denied

参考

socat man page

用 GDB 的 remotelogfile

打开 GDB ,在执行 target remote ... 命令之前,配置好 remotelogfile 变量,GDB 会将与 OpenOCD 的交互数据写入 remotelogfile 指定的文件内。

  1. set remotelogfile remote.log
  2. target remote ...

GDB 记录的日志文件时这个样子的:

  1. c n
  2. w $vCont?#49
  3. r $#00
  4. w $Hc0#db
  5. r $OK#9a
  6. w $s#73
  7. r <Timeout: 0 seconds>$S02#b5
  8. w $g#67
  9. r $0000000001...#50
  10. r $#00
  11. w $m0,2#fb
  12. r $6f00#fc
  13. w $m2,2#fd
  14. r $c015#f9
  15. c c
  16. w $c#63
  17. r <Timeout: 0 seconds>
  18. w \x03
  19. r $S02#b5
  20. w $g#67
  21. r $0000000001...#c5
  22. w $qL1200000000000000000#50
  23. r $#00
  24. w $m0,2#fb
  25. r $6f00#fc
  26. w $m2,2#fd
  27. r $c015#f9
  28. c q
  29. w $vKill;a410#33
  30. r $#00
  31. w $k#6b

对比

socat 会记录数据收发的时间戳;但加入 socat 后,速度会变慢。
remotelogfile 不仅把收发的数据记录下来,还把命令也记录了下来。

发表评论

表情:
评论列表 (有 0 条评论,143人围观)

还没有评论,来说两句吧...

相关阅读