xcode 在 LLDB 调试器中显示变量属性的值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11386147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:28:25  来源:igfitidea点击:

Display the value of a variable property in LLDB debugger?

xcodelldb

提问by Snowman

I'm using a breakpoint with Action "Log Message", and I want to print the row of an NSIndexPath. So I tried: cell row @indexPath.row@but nothing gets printed. I also tried using a debugger command: expr (void)NSLog(@"indexPath row:%i", indexPath.row)but I get an error: error: property 'row' not found on object of type 'NSIndexPath *'

我正在使用带有操作“日志消息”的断点,并且我想打印 NSIndexPath 的行。所以我试过:cell row @indexPath.row@但没有打印出来。我也尝试使用调试器命令:expr (void)NSLog(@"indexPath row:%i", indexPath.row)但出现错误:error: property 'row' not found on object of type 'NSIndexPath *'

What am I doing wrong?

我究竟做错了什么?

回答by Jason Coco

The dot syntax is just syntactic sugar added by the compiler. I've always disagreed with adding it to Objective-C, but some people love it. What you have to remember is that these dots are getting converted into method calls by the compiler, so when you message something directly, like in the debugger, you must use the actual method call. Try rewriting your expression:

点语法只是编译器添加的语法糖。我一直不同意将它添加到 Objective-C,但有些人喜欢它。您必须记住的是,这些点会被编译器转换为方法调用,因此当您直接发送消息时,例如在调试器中,您必须使用实际的方法调用。尝试重写您的表达式:

expr (void)NSLog(@"indexPath row: %ld", (long int)[indexPath row])

I'm not sure if the debugger's basic log method will execute method calls like this, so you may have to use the expression type.

我不确定调试器的基本日志方法是否会执行这样的方法调用,因此您可能必须使用表达式类型。

回答by Mike M

I think this is a special case. The code below will work, but only if rowis initialised to some value.

我认为这是一个特例。下面的代码将起作用,但前提row是初始化为某个值。

(lldb) print (NSInteger)[indexPath row]

I think this might be related to the fact that the row property is an extension of NSIndexPath in UIKit and is implemented as a category on that class.

我认为这可能与 row 属性是 UIKit 中 NSIndexPath 的扩展并作为该类的类别实现的事实有关。

回答by Steven Kramer

Try to set this summary format in Xcodes variable view:

尝试在 Xcodes 变量视图中设置此摘要格式:

section:{(int)[$VAR section]},row:{(int)[$VAR row]}