如何在本地范围的变量上设置持久和条件观察点? [英] How do I set persistent and conditional watchpoints on locally scoped variables?

查看:13
本文介绍了如何在本地范围的变量上设置持久和条件观察点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 如果我为当前作用域的局部变量设置了观察点,它会在超出作用域时被自动删除.有什么方法可以设置一次并在进入相同范围时使其自动保持活动状态?

  1. 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?

是否可以设置条件观察点,例如 watch var1 if var1==0?在我的情况下,条件不起作用.每当 var1 的值更改时,gdb 就会停止,而不是直到 var1 == 0 为真.我的 gdb 是 GNU gdb 6.8-debian.

Is there anyway to set conditional watchpoint, like watch var1 if var1==0? In my case, the condition does't work. gdb stops whenever var1's value is changed, instead of untill var1 == 0 is true. My gdb is GNU gdb 6.8-debian.

推荐答案

我同意 Dave 的观点,条件断点是可行的方法.

I agree with Dave that a conditional breakpoint is the way to go.

但是,按照您的要求,您可以使用 GDB 的 commands 命令设置 GDB 命令列表,以便在遇到断点时执行.我觉得这非常有用.

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.

我建议将您的 GDB 命令写入一个文件,以便使用 source 命令轻松编辑和重新加载它们.或者您可以指定要在 GDB 命令行上加载的命令文件或使用 .gdbinit 使其自动加载.

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.

commands的良好使用示例:
假设我有一个函数 format 被许多其他函数调用.我想打破它,但只有在函数 do_step_3 被调用之后.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆