po in LLDB with swift

János picture János · Jul 16, 2014 · Viewed 14.1k times · Source

How can I plot out variable's value in a Swift App with LLDB?

Earlier it was like po variable_name

Now I usually get some nasty error, like:

(lldb) po a
error: <EXPR>:11:5: error: use of unresolved identifier '$__lldb_injected_self'
    $__lldb_injected_self.$__lldb_wrapped_expr_2(     
    ^

Answer

Enrico Granata picture Enrico Granata · Jul 17, 2014

That error sounds like it might be because DWARF is not telling LLDB where to find your "self" object. Given the nature of Swift, LLDB needs to know the type of self in order to be able to inject an expression inside your local scope One way to find out if that is your problem is to do at the LLDB prompt:

(lldb) frame variable -L self

You are probably going to not see a location for it. Worth filing a bug report for, just to track your specific repro case

Anyway, to get to the bulk of your question. In Swift, there is no language-sanctioned mechanism for "print description" like for ObjC, so while you can type "po self", unless self is an Objective-C type, you will pretty much see the same thing that "p self" or even "frame variable self" would tell you - which is entirely based on the LLDB data formatters mechanism. If you want to hook into that to customize the way your Swift objects look, the obligatory reference is: http://lldb.llvm.org/varformats.html