如何根据对象字符串属性在 Xcode 中设置条件断点? [英] How to set a conditional breakpoint in Xcode based on an object string property?
问题描述
我希望能够在达到特定字符串匹配时让调试器中断.例如,我可能有这样的事情:
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] 代替 myObj.name(除非 name 是一个 ivar).
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屋!