7

I have a question about the "Show Summaries" feature in Xcode which this guys is talking about.

Currently, I implement description and debugDescription in my Objective-C classes to that I can just type po myObject to get a quick view of the content and this saves me time.

However, I want to know if there's a way to get this to show in this "Show Summaries" thing. Kind of like when of have an NSString, it just shows you the string in Content pane without further effort from you.

And I do this for my own objects too? This would save me so much time :)

Thanks folks.

Edit Thanks to Martin R's comment I managed to get what I wanted :) Link

Community
  • 1
  • 1
OLL
  • 655
  • 5
  • 20
  • 1
    You need some Python scripting. This website shows how it works: http://stavash.wordpress.com/2013/01/06/advanced-issues-creating-custom-lldb-object-summaries/ – Martin R May 31 '13 at 11:53
  • Spot on! I'll give that a try and update this thread if it works (or doesn't). – OLL May 31 '13 at 12:03
  • I just remembered that I used the "custom summary" as an example in my answer to a different question here: http://stackoverflow.com/questions/14159070/when-is-lldb-init-module-called, so that might perhaps help as well. – Martin R May 31 '13 at 13:31
  • @OLL: You should post your solution as an answer, it is easy to miss you edit. – Guillaume Algis Jun 06 '13 at 21:05
  • Noted.. sorry about that - I'll do that next time :) – OLL Jun 16 '13 at 11:46

1 Answers1

1

Basically you could use a python script like this one right below to get any custom summary associated to any object

# filename : customSummaries.py
import lldb

def someClass_summary(valueObject, dictionary):
    # get properties from object
    ivar1 = valueObject.GetChildMemberWithName('_ivar')
    ivar2 = valueObject.GetChildMemberWithName('_ivar2')

    # convert values into python intrinsics
    error = lldb.SBError()
    var1 = ivar1.GetData().GetFloat(error, 0)
    var2 = ivar2.GetData().GetDouble(error, 0)

    # string generation we're gonna use for the summaries
    valueRepr1 = str(var1)
    valueRepr2 = str(var2)

    return 'value1= ' + valueRepr1 + ', value2= ' + valueRepr2  

# this function gets called by the lldb as this script is imported
def __lldb_init_module(debugger, dict):

# this adds automatically your summaries as the script gets imported
debugger.HandleCommand('type summary add Class -F customSummaries.someClass_summary')

To load the custom summaries while the lldb is running you should import the script above by running command script import /path/to/customSummaries.py and that's all.

HepaKKes
  • 1,555
  • 13
  • 22