如何基于对象字符串属性在Xcode中设置条件断点? [英] How to set a conditional breakpoint in Xcode based on an object string property?

查看:269
本文介绍了如何基于对象字符串属性在Xcode中设置条件断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望调试器在达到特定的字符串匹配时能够中断.例如,我可能会遇到这样的情况:

I'm looking to be able to have the debugger break when it reaches a particular string match. As an example, I might have something like this:

Foo myObj = [self gimmeObj];

myObj可能具有一个称为name的属性.我希望调试器在以下情况下停止执行任务:

myObj might have a property called name. I want the debugger to stop on the assignment when

[myObj.name isEqualToString:@"Bar"];

如何在Xcode中设置条件断点来做到这一点?

How can I set my conditional breakpoint in Xcode to do that?

推荐答案

您可以通过正常设置断点来在Xcode中设置条件断点,然后按住Control键单击并选择Edit Breakpoint(选择Run-> Show->断点).

You can set a conditional break point in Xcode by setting the breakpoint normally, then control-click on it and select Edit Breakpoint (choose Run -> Show -> Breakpoints).

在断点条目中,有一个条件"列.

In the breakpoint entry, there is a Condition column.

现在,要记住一些要考虑的问题.首先,gdb不了解点语法,因此必须使用[myObj name](除非name是ivar)代替myObj.name.

Now, there are several issues to keep in mind for the condition. Firstly, gdb does not understand dot syntax, so instead of myObj.name, you must use [myObj name] (unless name is an ivar).

接下来,与gdb中的大多数表达式一样,您必须告诉它返回结果的类型,即"BOOL".因此,将条件设置为:

Next, as with most expressions in gdb, you must tell it the type of return result, namely "BOOL". So set a condition like:

(BOOL)[[myObj name] isEqualToString:@"Bar"]

通常,通过临时添加类似以下代码的代码实际上更容易做到这一点:

Often it is actually easier to just do this in code by temporarily adding code like:

if ( [myObj.name isEqualToString:@"Bar"] ) {
    NSLog( @"here" );
}

,然后在NSLog上设置断点.然后,您的条件可以任意复杂,而不必担心gdb可以解析和不能解析的内容.

and then setting the break point on the NSLog. Then your condition can be arbitrarily complex without having to worry about what gdb can and can't parse.

这篇关于如何基于对象字符串属性在Xcode中设置条件断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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