Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and use temp NSRange in lldb?

NSRange is just a C struct. I want to create a temporary one in lldb in Xcode at a breakpoint.

Specifically for use in NSArray method objectAtIndex:inRange:

This does not work.

(lldb) expr NSRange $tmpRange = (NSRange){0,4}
(lldb) expr $tmpRange
(NSRange) $tmpRange = location=0, length=4
(lldb) expr -o -- [items indexOfObject:item4 inRange:$tmpRange]
error: no matching constructor for initialization of 'NSRange' (aka '_NSRange')
error: 1 errors parsing expression

My code has an NSRange var named badRange at the breakpoint, and passing that one in works. Thus:

(lldb) expr -o -- [items indexOfObject:item4 inRange:badRange]
0x7fffffffffffffff
(lldb) expr badRange
(NSRange) $1 = location=0, length=3

What is going on?

Thanks.

like image 243
Jeff Avatar asked Apr 23 '15 23:04

Jeff


1 Answers

Creating a NSRange in the debugger works fine when working in a OS X project but it doesn't for iOS projects. The reason it doesn't work on iOS is that even though Foundation provides the header file in which the struct is declared, it doesn't expose any corresponding symbol. Basically, on iOS, NSRange is just a forward declaration and I do not know the real symbol for the implementation.

like image 164
Dalzhim Avatar answered Oct 28 '22 08:10

Dalzhim