Error in breakpoint condition

2020-07-10 05:28发布

问题:

I've set a breakpoint with the condition...

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

This works fine.

However, when I try to add another breakpoint with the condition...

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

I get the error...

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

Do I need to escape the pound sign or something?

回答1:

There's a bug with the expression parser and an NSString literal containing non-ASCII characters.

(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

There is already a bug reported filed with http://bugreport.apple.com/ about this issue.

Non-ASCII C string literals are handled correctly so it is possible to work around this, e.g.

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


回答2:

I don't know why the breakpoints have still such a limited compiler support, but anyway, to fix your problem, it should be sufficient to cast the return type of each method you call like this:

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

With this your code should pause if the string doesn't contain the '£' symbol or any other non-ASCII character. As it appears that the LLDB compiler has problems non-ASCII characters you may want to convert the strings first using that encoding. In the mean while I'm looking for a way to avoid this if possible…