简体   繁体   English

如何在lldb中创建和使用temp NSRange?

[英]How to create and use temp NSRange in lldb?

NSRange is just a C struct. NSRange只是一个C结构。 I want to create a temporary one in lldb in Xcode at a breakpoint. 我想在断点处在Xcode中的lldb中创建一个临时的。

Specifically for use in NSArray method objectAtIndex:inRange: 特别适用于NSArray方法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. 我的代码在断点处有一个名为badRange的NSRange var,并将其传递给了。 Thus: 从而:

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

What is going on? 到底是怎么回事?

Thanks. 谢谢。

Creating a NSRange in the debugger works fine when working in a OS X project but it doesn't for iOS projects. 在OS X项目中工作时,在调试器中创建NSRange可以正常工作,但不适用于iOS项目。 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. 它在iOS上不起作用的原因是,即使Foundation提供了声明结构的头文件,它也不会公开任何相应的符号。 Basically, on iOS, NSRange is just a forward declaration and I do not know the real symbol for the implementation. 基本上,在iOS上,NSRange只是一个前向声明,我不知道实现的真实符号。

I needed to create an NSRange recently whilst trying to debug some code and came across this thread. 我最近需要创建一个NSRange,同时尝试调试一些代码并遇到这个线程。 It is currently possible to do this for iOS projects using Xcode 8.3.2 with the following syntax. 目前可以使用Xcode 8.3.2使用以下语法对iOS项目执行此操作。

po [@"test words here" stringByReplacingOccurrencesOfString:@"\\s" withString:@"" options:1024 range:(NSRange){0,15}]

This also works: 这也有效:

expr NSRange $tmpRange = (NSRange){0,15}
po [@"test words here" stringByReplacingOccurrencesOfString:@"\\s" withString:@"" options:1024 range:(NSRange)$tmpRange]

Not sure when this was fixed (or if it ever was, as leaving off (NSRange) on the second example results in the same error), but it works now. 不知道什么时候修复(或者如果它曾经是,因为在第二个例子中留下(NSRange)会导致相同的错误),但它现在有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM