Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: display properties of Apple framework classes via LLDB script or otherwise

Through various resources I found that you can create custom descriptions and even custom object summaries in LLDB. I'm also aware that I can do "Add Expression" in order to display the value of a property for a Apple framework class that the debugger hides from us.

What I want is to display the framework class object as if the source code were available for it.

A picture says more than words ... what I have so far:


enter image description here


As you can see I have a SKLabelNode named _label in scope. I managed to add a custom summary string ("these are words") next to SKNode via Python scripting following the tutorials here and here.

I can also see the _label.fontName and _label.text but that's only because I right-clicked and did "Add Expression" manually for each property.

My questions:

  1. Is it possible (and if so how) to add an object's properties to its tree view via Python LLDB scripts? What I want is the _label object to expand and then always display its fontName, text and other properties like I have done by manually adding the expressions. Or in other words: it ought to behave as if full source code were available for that class.

  2. Alternatively: Is there a way to run "Add Expression" from the script so that I can create an alias that will quickly add multiple expressions? Perhaps one where I can add the object in question as a reference, for example command addCustomExpressionsWithObject _label.

I accept alternative solutions as well. For example if I could write proxy classes for each SK*Node class and somehow get LLDB to display the contents of a node's corresponding proxy class, that would also work. Whatever gets the job done, and preferably in a way that's automated (once implemented).


In general, how hard can it be to have the LLDB debugger display the (documented!) properties of a class from an Apple framework?

In particular for Sprite Kit we get no info on any SK*Node object whatsoever and I can't believe this hasn't bugged other developers using other Apple frameworks as hard as it bugs me. I hope there's a way to "fix" this but the little info I can find makes me think it's either not possible or I'm insane for wanting to see more details about Apple class objects.

PS: Yes, I've also looked into and customized Xcode 5.1's QuickLook functionality. I created a SpriteKit+QuickLook repository with QuickLook/debugDescriptions for some Sprite Kit classes but it's still not satisfactory as it serves only as a full class dump (better than nothing though).

like image 899
LearnCocos2D Avatar asked Dec 01 '25 02:12

LearnCocos2D


1 Answers

If you can run an expression that returns you the value of those properties, you can add a synthetic children provider to your SKLabelNode that has the result of evaluating each of those properties as a child of the LabelNode itself

More details on all of this are at the LLDB official website: http://lldb.llvm.org/varformats.html

Be warned, however: now whenever you stop in Xcode, no matter how corrupt your program state is, LLDB will try to run those expressions. That won't bring down the debugger in an ideal world, but it might certainly cause weird side effects in your inferior if those properties are not just reading some field

Also be warned that performance won't be anything exciting. At every stop or step where an SKLabelNode is involved, LLDB will run the code to compute the value of those properties (assuming your SKLabelNode is expanded, and the children visible, that is)

tl;dr there's a reason why the debugger does not show those properties by default - if you truly care, make a synthetic child provider that runs appropriate expressions

like image 82
Enrico Granata Avatar answered Dec 02 '25 19:12

Enrico Granata