I'm writing an iOS app and I need help using the built-in Xcode debugger. Suppose I have an object called HomeViewController
that has three properties
我正在编写一个iOS应用程序,我需要使用内置的Xcode调试器的帮助。假设我有一个叫做HomeViewController的对象它有三个属性
@property (nonatomic) BOOL finished;
@property (nonatomic, strong) NSArray *myArray;
@property (nonatomic, strong) NSString *myName;
@synthesize finished = _finished, myArray = _myArray, myName = _myName;
Suppose I have a breakpoint in this class. How would I view the contents of these properties? I've tried things such as po myName
, print myName
and print [self myName]
but I can't figure out how to do this. I've tried using LLDB but I keep getting the same error that this person encountered (lldb fails to print variable values with "error: reference to 'id' is ambiguous") . The accepted answer to this question was, LLDB is broken and that I should just use GDB; however, I refuse to accept that something so fundamental is broken.
假设我在这个类中有一个断点。如何查看这些属性的内容?我尝试过一些东西,比如po myName, print myName和print [self myName],但是我不知道怎么做。我尝试过使用LLDB,但是我一直得到这个人遇到的相同的错误(LLDB未能打印带有“error:对‘id’的引用是不明确的”的变量值)。这个问题的公认答案是,LLDB已经坏了,我应该使用GDB;然而,我拒绝接受这样一个根本性的东西被打破的事实。
Nevertheless, I've also tried using GDB with similar commands as above; however, I can't get GDB to work either. Help please
尽管如此,我也尝试过使用GDB来执行上面类似的命令;但是,我也不能让GDB工作。请帮忙
2 个解决方案
#1
23
Once you place a breakpoint, run, and the program stops at the breakpoint, hover your cursor over the variable/value you want to see like this:
一旦您放置了一个断点,运行,程序在断点处停止,将光标悬停在您希望看到的变量/值上,如下所示:
You could also place an NSLog(@"%@", yourLabel.text);
to view the contents of that label/other object type.
您还可以放置一个NSLog(@“%@”,您的标签。text);查看该标签/其他对象类型的内容。
One other option is to run GDB in the console like this:
另一个选项是在控制台中运行GDB,如下所示:
gdb
attach <your process name>
And then use the po
(print-object) command to view the value of a variable like this:
然后使用po (print-object)命令来查看这样一个变量的值:
po variableName
To view the value of primitive types (int
, float
, long
, double
, char
, etc.), you can just use the print
command while running GDB in the console like this:
要查看基本类型的值(int、float、long、double、char等),可以在控制台运行GDB时使用print命令:
print yourPrimitiveVariable
Hope this helps!
希望这可以帮助!
EDIT:
编辑:
With the po
command, you can print out the value of an object using both the property name (self.myProperty
) or the ivar name (possibly _myProperty
). I demonstrate this here:
使用po命令,您可以使用属性名(self.myProperty)或ivar名称(可能是_myProperty)打印出对象的值。我在这里证明这一点:
#2
2
Try with following expression in debug area to print object,
尝试在debug区域使用以下表达式来打印对象,
p self.view.bounds.size.width
or use,
或使用,
po self.view
p - Print is only uses to print normal/simple values while, po - Print Object works same as NSLog to print value of an object
p - Print仅用于打印普通/简单的值,而po - Print对象的工作方式与NSLog相同,用于打印对象的值
#1
23
Once you place a breakpoint, run, and the program stops at the breakpoint, hover your cursor over the variable/value you want to see like this:
一旦您放置了一个断点,运行,程序在断点处停止,将光标悬停在您希望看到的变量/值上,如下所示:
You could also place an NSLog(@"%@", yourLabel.text);
to view the contents of that label/other object type.
您还可以放置一个NSLog(@“%@”,您的标签。text);查看该标签/其他对象类型的内容。
One other option is to run GDB in the console like this:
另一个选项是在控制台中运行GDB,如下所示:
gdb
attach <your process name>
And then use the po
(print-object) command to view the value of a variable like this:
然后使用po (print-object)命令来查看这样一个变量的值:
po variableName
To view the value of primitive types (int
, float
, long
, double
, char
, etc.), you can just use the print
command while running GDB in the console like this:
要查看基本类型的值(int、float、long、double、char等),可以在控制台运行GDB时使用print命令:
print yourPrimitiveVariable
Hope this helps!
希望这可以帮助!
EDIT:
编辑:
With the po
command, you can print out the value of an object using both the property name (self.myProperty
) or the ivar name (possibly _myProperty
). I demonstrate this here:
使用po命令,您可以使用属性名(self.myProperty)或ivar名称(可能是_myProperty)打印出对象的值。我在这里证明这一点:
#2
2
Try with following expression in debug area to print object,
尝试在debug区域使用以下表达式来打印对象,
p self.view.bounds.size.width
or use,
或使用,
po self.view
p - Print is only uses to print normal/simple values while, po - Print Object works same as NSLog to print value of an object
p - Print仅用于打印普通/简单的值,而po - Print对象的工作方式与NSLog相同,用于打印对象的值