如果类中的实例变量的值发生变化,如何触发断点? [英] How do I have a breakpoint get triggered if an instance variable in the class has its value changed?

查看:96
本文介绍了如果类中的实例变量的值发生变化,如何触发断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个变量, self.position ,如何在Xcode改变其值时使其断开(许多方法可能会改变它)。

Say I have a variable, self.position, how do I get Xcode to break whenever it changes its value (a number of methods could change it).

推荐答案

条件中断:


  1. Cmd +选项点击断点

  2. 像这样添加休息条件:

为了在每个场合打破价值的变化:


  1. 实现琐碎的setter(为了清洁代码而使用getter) 。

  2. 向setter添加断点。

如果你想看看是谁调用了setter - 只需查看堆栈跟踪中的下一行(在我的示例中为viewDidLoad):

If you want to see who invoked the setter - just look at the next line in the stack trace (viewDidLoad in my example):

更新:

添加一个wat chpoint


  1. 在任何地方中断,以便显示(lldb)提示在控制台中

  2. 键入 watchpoint set variable _position (将_position替换为您想要观看的iVar)

  3. 记下为新创建的观察点分配的观察点编号。

  4. 修改条件中断的观察点:观察点修改-c_position < 0.51 其中引号中的表达式是条件,最后的数字是您在#3中记下的观察点编号。

  5. 继续运行。你'只要值与条件匹配就会中断,并且您将能够检查堆栈帧以了解调用的来源。

  1. Break anywhere so that the (lldb) prompt shows up in the console
  2. Type in watchpoint set variable _position (replace _position with an iVar you want to watch)
  3. Make a note of the assigned watchpoint number to your newly created watchpoint.
  4. Modify the watchpoint for conditional breaking: watchpoint modify -c "_position < 0.5" 1 where the expression in quotes is the condition and the number at the end is the watchpoint number you noted in #3.
  5. Continue running. You'll break whenever the value matches the condition and you'll be able to inspect the stack frame to understand where the call came from.

这篇关于如果类中的实例变量的值发生变化,如何触发断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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