Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "p" and "po" in Xcode's LLDB debugger?

Example: I write the following string in my old project and a new, clear one:

UIInterfaceOrientation k = [UIApplication sharedApplication].statusBarOrientation;

Console input/output for a clear project:

(lldb) po k
UIInterfaceOrientationLandscapeLeft

And something awful in my old project if I write "po k" - a list of useless integers.

Additionally, I can't print most of the objects in the new project.

like image 668
Vyachaslav Gerchicov Avatar asked Mar 02 '15 09:03

Vyachaslav Gerchicov


People also ask

What is PO in LLDB?

If you do a quick help po in the LLDB console, you'll find po is actually a shorthand expression for expression -O -- . The -O arugment is used to print the object's description.

What does po mean in Xcode?

"po" means something like "print object".

What is PO command?

The po command (a.k.a. expr --O -- ) does everything that p does, but instead of printing the result, if the result is a pointer to an ObjC object, it calls that object's "description" method, and prints the string returned by that method(*).

What does LLDB stand for?

LLDB (low-level debugger) is part of LLVM The LLVM compiler (low level virtual machine) creates programming languages. LLDB is Apple's “from the ground up” replacement for GDB. The LLDB debugger is analogous to GDB: (The GNU Project Debugger).


2 Answers

I don't know what is going on in your case, but just so folks are clear on the difference between po & p:

The p command (a.k.a. expr --) takes the arguments it is given, compiles them as though they were a source code expression written in the context of the current frame, executes the result - either by running an interpreter on the result of the compilation if that is possible, or by JITing the result of the compilation, inserting it into the target program, and running it there. Then it prints the result of the evaluation.

The po command (a.k.a. expr --O --) does everything that p does, but instead of printing the result, if the result is a pointer to an ObjC object, it calls that object's "description" method, and prints the string returned by that method(*). Similarly, if the result is a CF object, it will call CFShow and print the result of that. If both these attempts fail, it will go ahead and print the result as p would have.

So po is mostly like p. But you can get some weird results if you use po on things that it aren't actually objects. For instance, ObjC has a optimization (tagged pointers) that represent the contents of some objects (e.g. NSNumbers) in the object pointer. There isn't a "real" object, just a cooked pointer. So if you try to po an integer that just happens to look like a tagged pointer, you'll get the description of some probably unrelated ObjC object, not the value of the integer.

And of course, po is doing a lot more work, so unless you really want some object's description of itself, p is more efficient.

  • Actually, it calls debugDescription, if that exists, and falls back to description if it doesn't...
like image 94
Jim Ingham Avatar answered Oct 12 '22 10:10

Jim Ingham


p = print

po = print object

p prints value of primitive variable or value of a reference

po try to call -description for that object and print returned string

like image 20
3 revs Avatar answered Oct 12 '22 09:10

3 revs