要一致观察并偶尔检查gdb当前帧之外的变量 [英] Want to watch consistently and examine occasionally the variable outside the current frame in gdb
问题描述
var
的变量。我设置了一个观察点。然后我输入另一个名为 func()
的函数。目前,观察点可能会被删除,因此我无法访问该变量。任何方法都可以随时保持观察点?另外,我知道我可以使用类似的语法print main :: var
打印出变量的值。但这还不够。任何好主意?
gdb的奇怪之处在于 watch
尝试尊重表达的所有组成部分的范围。因此,如果您监视var
,并且 var
超出范围,则移除观察点。这也适用于更复杂表达式的元素,例如 watch a + b
。
这有一个理由,当然,在某种程度上有点酷 - 但它很少是你真正想要的。根据我的经验,更为正常的做法是不去关心范围,只想看一些内存。
为此,请将 -location
添加到 watch
命令。这将会执行你更常用的操作 - 只需要表达式引用的内存。因此, watch -location var
。
Say I define a variable named var
in the main function. And the I set a watchpoint to it. Then I enter another function called func()
. At this time, the watchpoints may be deleted so that I have no access to that variable. Any method to make to possible to always keep the watchpoint whenever you are?
Also, I know I can use syntax like print main::var
to print out the value of the variable. But that is not sufficient enough. Any good idea?
An oddity of gdb is that watch
tries to respect the scope of all the constituent parts of the expression. So, if you watch var
, and var
goes out of scope, the watchpoint is removed. This applies to the elements of a more complicated expression as well, like watch a + b
.
This has a justification, of course, and is sort of cool in a way -- but it is rarely what you actually want. It's far more normal, in my experience, not to care about the scope and to just want to watch some bit of memory.
To do this, pass -location
to the watch
command. This will do what you more commonly want to do -- just want the memory referred to by the expression. So, watch -location var
.
这篇关于要一致观察并偶尔检查gdb当前帧之外的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!