如何在本地作用域变量上设置持久性和条件观察点? [英] How do I set persistent and conditional watchpoints on locally scoped variables?
问题描述
-
如果我为当前范围的本地变量设置了一个观察点,那么它将在退出范围时自动删除。有什么方法可以设置一次,并保持它自动活跃,每当进入相同的范围?
-
是否有设置条件观察点,如
观察var1 if var1 == 0
?在我的情况下,条件不起作用。每当var1
的值发生变化时,gdb停止运行,而不是直到var1 == 0
为真。我的gdb是GNU gdb 6.8-debian。 我同意戴夫然而,按照你的要求,你可以使用GDB的 If I set a watchpoint for a variable local to the current scope, it will be auto deleted when going out of the scope. Is there any way to set it once and keep it auto alive whenever entering the same scope?
Is there anyway to set conditional watchpoint, like
watch var1 if var1==0
? In my case, the condition does't work. gdb stops whenevervar1
's value is changed, instead of untillvar1 == 0
is true. My gdb is GNU gdb 6.8-debian.
命令
命令来设置GDB命令的列表,以便在命中断点时执行。我认为这非常有用。 我建议您将GDB命令写入文件,以便它们易于编辑,并且易于使用源文件重新加载
命令。或者你可以指定要加载到GDB命令行的命令文件或使用.gdbinit自动加载。
一个很好的使用命令
:
假设我有一个被许多其他函数调用的函数 format
。我想打破它,但只有在函数 do_step_3
被调用后。
break do_step_3
命令
中断格式
继续
结束
你可以用这个来解决你的问题,例如:
break func
命令
watch var
continue
end
I agree with Dave that a conditional breakpoint is the way to go.
However, to do what you asked, you can use GDB's commands
command to set a list of GDB commands to execute whenever a breakpoint is hit. I find this incredibly useful.
I suggest writing your GDB commands into a file so that they are easy to edit and easy to reload with the source
command. Or you can specify command files to load on the GDB command line or use .gdbinit to make them load automatically.
An example of a good use of commands
:
Suppose that I have a function format
that is called by a lot of other functions. I want to break on it, but only after function do_step_3
has been called.
break do_step_3
commands
break format
continue
end
You could use this for your problem with something like:
break func
commands
watch var
continue
end
这篇关于如何在本地作用域变量上设置持久性和条件观察点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!