We usually use
po to print object description, which does the same job as
Alias the command
We can also use
command alias to custom it. like
command alias my_po expression --object-description
Custom the output
We can add
debugDescription to custom the output when using
Others jobs po can do
What LLDB does behind the
p is a alias of `expression
The result of LLDB is given a increasing name, such as
Dynamic type resolution
In Swift, the static representation of a type in the source code and the dynamic type at the runtime, aren’t necessarily the same. For example, a variable might be declared using a protocol of this type. In this example, the static type of
Activity. But at runtime, the variable will have an instance of type
Tripwhich is the dynamic time. If we print the value of
cruise, we get back an object of type
Tripbecause LLDB retell results metadata to display the most accurate type for a given variable at a given program point. This is what we call
dynamic type resolution.
With the p-command, dynamic type resolution is
only performed on the result of the
This happens because if you remember, LLDB compiles code where running p and the only type it sees is the one in your source code, the static one. It’s the same thing as typing the expression
cruise.name in your source code. The static compiler will reject it with an error.
If you want to evaluate the expression without errors, you need to first cast the object explicitly to its dynamic type and then access the field on the result. This is true both for the debugger and your source code.
“p” Under the Hood
After it performed
dynamic type resolution on the result, LLDB passes the resulting object to the
formatter subsystem which is the part of LLDB responsible for printing a human readable description of objects.
- The output of
vis exactly the same as
pas it also relies on the formatter we just described.
vis just an alias we introduced in Xcode 10.2 for the
- The v-command doesn’t compile and execute code at all which makes it very fast.
v under the hood
po vs p vs v
scan qr code and share this article