【问题标题】:Error in breakpoint condition断点条件错误
【发布时间】:2013-06-16 01:29:43
【问题描述】:

我已经设置了条件断点...

[event.name isEqualToString:@"Some Name"]

这很好用。

但是,当我尝试使用条件添加另一个断点时...

[part.name isEqualToString:@"Some Value With A Pound Sign £"]

我得到了错误...

Internal error [IRForTarget]: An Objective-C constant string's string initializer is not an array
Stopped due to an error evaluating condition of breakpoint

我需要转义井号吗?

【问题讨论】:

  • 如果我删除£不会产生错误...但它也不会暂停。
  • 试试[part.name rangeOfString:@"Some Value With A Pound Sign"].location != NSNotFound; 除非您专门寻找井号,否则您必须使用不同的编码查看字符串。
  • 这看起来像是 LLDB 中的错误(编码问题),您应该向 Apple 报告。
  • @Putz1103 我试过了,但得到了...Stopped due to an error evaluating condition of breakpoint 12.1: "[part.name rangeOfString:@"Search String"].location != NSNotFound;" error: 'rangeOfString:' has unknown return type; cast the call to its declared return type error: 1 errors parsing expression
  • @Fogmeister 我已经尝试过同样的事情,并在该行设置了一个断点,但我没有发现任何此类错误。我的代码: if ([self.strCheck isEqualToString:@"Some Value With A Pound Sign £"]) { NSLog(@"get"); } else { NSLog(@"not"); }

标签: ios objective-c xcode breakpoints lldb


【解决方案1】:

表达式解析器和包含非 ASCII 字符的 NSString 文字存在错误。

(lldb) po @"u"
$9 = 0x00007fff7debe5e0 u
(lldb) po @"ü"
Internal error [IRForTarget]: An Objective-C constant string's string initializer is not an array
error: warning: expression result unused
error: The expression could not be prepared to run in the target

已经向http://bugreport.apple.com/ 提交了关于此问题的错误报告。

非 ASCII C 字符串文字被正确处理,因此可以解决这个问题,例如

(lldb) po [NSString stringWithUTF8String:"ü"]
$11 = 0x000000010010b040 ü

【讨论】:

    【解决方案2】:

    我不知道为什么断点仍然有如此有限的编译器支持,但无论如何,要解决您的问题,像这样转换您调用的每个方法的返回类型就足够了:

    (BOOL)[(NSString *)[part name] isEqualToString:@"some string"]
    

    如果字符串不包含“£”符号或任何其他非 ASCII 字符,您的代码应该暂停。看起来 LLDB 编译器存在非 ASCII 字符问题,您可能希望首先使用该编码转换字符串。与此同时,我正在寻找一种尽可能避免这种情况的方法……

    【讨论】:

    • 如果“某些字符串”包含非 ASCII 字符,则会出现问题。转换为 NSString * 对我的测试用例没有帮助。
    • 不,对我也没有帮助。对不起。
    • 哦,是的,我注意到了。好吧,当没有非 ASCII 字符时,至少他的代码应该暂停。让我们尝试找到解决方案!
    • 太棒了!这解决了我的条件断点问题!
    猜你喜欢
    • 1970-01-01
    • 2011-02-14
    • 2012-07-02
    • 1970-01-01
    • 2016-02-17
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多