首页 > 解决方案 > 是否可以指示 GDB 从目标异步获取变量值?

问题描述

printf()通过分配“打印变量值然后继续”代码来放置断点来实现该功能:

break main.c:18
commands
print myVar
cont
end

到目前为止,这工作得很好。但是,AFAIU,它需要与目标(在我的例子中是一个微控制器)进行多次通信:

  1. 当断点被击中时,微控制器发送信号
  2. GDB 立即要求myVar
  3. MCU发送myVar
  4. GDB 指示 MCU 继续

这些步骤会导致明显的抖动,因此 MCU 上的应用程序表现得非常奇怪。

有没有机会告诉 GDB 一次性完成上述步骤,例如:“告诉我myVar值,然后继续而不等待任何进一步的指示。”?

标签: gdb

解决方案


AFAIU,它需要与目标进行多次沟通

实际上在 GDB 和目标之间交换的数据包要多得多(GDB 远程协议非常健谈)。您可以使用set debug remote on.

您正在寻找的是追踪

> For each tracepoint, you can specify, in advance, some arbitrary set
> of data that you want the target to collect in the trace buffer when
> it hits that tracepoint. The collected data can include registers,
> local variables, or global data. Later, you can use GDB commands to
> examine the values these data had at the time the tracepoint was hit.

更新:

当我发布tstart时,GDB 给出error: Target does not support this command.

显然您使用的是 MCU 以外gdbserver的东西(您没有告诉我们 GDB 的远程端有什么),并且您的远程端不支持跟踪。

这可能是一个gdbserver太旧的实例,或者可能是远程调试存根没有实现这部分协议。

如果是前者,您可以将其更新gdbserver到较新的版本。如果是后者,则您无能为力(除了自己实现跟踪支持)。


推荐阅读