[Lldb-commits] [lldb] r177213 - Converting more data formatters to C++ - NSBundle, CFBinaryHeap, NSMachPort and NSNotification

Enrico Granata egranata at apple.com
Fri Mar 15 17:50:25 PDT 2013


Author: enrico
Date: Fri Mar 15 19:50:25 2013
New Revision: 177213

URL: http://llvm.org/viewvc/llvm-project?rev=177213&view=rev
Log:
Converting more data formatters to C++ - NSBundle, CFBinaryHeap, NSMachPort and NSNotification

Modified:
    lldb/trunk/examples/summaries/cocoa/CFBag.py
    lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py
    lldb/trunk/examples/summaries/cocoa/NSBundle.py
    lldb/trunk/examples/summaries/cocoa/NSMachPort.py
    lldb/trunk/examples/summaries/cocoa/NSNotification.py
    lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h
    lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp
    lldb/trunk/source/DataFormatters/FormatManager.cpp

Modified: lldb/trunk/examples/summaries/cocoa/CFBag.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFBag.py?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFBag.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFBag.py Fri Mar 15 19:50:25 2013
@@ -5,7 +5,8 @@ part of The LLVM Compiler Infrastructure
 This file is distributed under the University of Illinois Open Source
 License. See LICENSE.TXT for details.
 """
-# summary provider for CFBag
+# example summary provider for CFBag
+# the real summary is now C++ code built into LLDB
 import lldb
 import ctypes
 import lldb.runtime.objc.objc_runtime

Modified: lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py (original)
+++ lldb/trunk/examples/summaries/cocoa/CFBinaryHeap.py Fri Mar 15 19:50:25 2013
@@ -5,7 +5,8 @@ part of The LLVM Compiler Infrastructure
 This file is distributed under the University of Illinois Open Source
 License. See LICENSE.TXT for details.
 """
-# summary provider for CFBinaryHeap
+# example summary provider for CFBinaryHeap
+# the real summary is now C++ code built into LLDB
 import lldb
 import ctypes
 import lldb.runtime.objc.objc_runtime

Modified: lldb/trunk/examples/summaries/cocoa/NSBundle.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSBundle.py?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSBundle.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSBundle.py Fri Mar 15 19:50:25 2013
@@ -5,7 +5,8 @@ part of The LLVM Compiler Infrastructure
 This file is distributed under the University of Illinois Open Source
 License. See LICENSE.TXT for details.
 """
-# summary provider for NSBundle
+# example summary provider for NSBundle
+# the real summary is now C++ code built into LLDB
 import lldb
 import ctypes
 import lldb.runtime.objc.objc_runtime

Modified: lldb/trunk/examples/summaries/cocoa/NSMachPort.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSMachPort.py?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSMachPort.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSMachPort.py Fri Mar 15 19:50:25 2013
@@ -5,7 +5,8 @@ part of The LLVM Compiler Infrastructure
 This file is distributed under the University of Illinois Open Source
 License. See LICENSE.TXT for details.
 """
-# summary provider for NSData
+# example summary provider for NSMachPort
+# the real summary is now C++ code built into LLDB
 import lldb
 import ctypes
 import lldb.runtime.objc.objc_runtime

Modified: lldb/trunk/examples/summaries/cocoa/NSNotification.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/cocoa/NSNotification.py?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/cocoa/NSNotification.py (original)
+++ lldb/trunk/examples/summaries/cocoa/NSNotification.py Fri Mar 15 19:50:25 2013
@@ -5,7 +5,8 @@ part of The LLVM Compiler Infrastructure
 This file is distributed under the University of Illinois Open Source
 License. See LICENSE.TXT for details.
 """
-# summary provider for class NSNotification
+# example summary provider for NSNotification
+# the real summary is now C++ code built into LLDB
 import lldb.runtime.objc.objc_runtime
 import lldb.formatters.metrics
 import CFString

Modified: lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h Fri Mar 15 19:50:25 2013
@@ -95,9 +95,18 @@ namespace lldb_private {
         NSNumberSummaryProvider (ValueObject& valobj, Stream& stream);
 
         bool
+        NSNotificationSummaryProvider (ValueObject& valobj, Stream& stream);
+        
+        bool
+        NSMachPortSummaryProvider (ValueObject& valobj, Stream& stream);
+        
+        bool
         CFBagSummaryProvider (ValueObject& valobj, Stream& stream);
         
         bool
+        CFBinaryHeapSummaryProvider (ValueObject& valobj, Stream& stream);
+        
+        bool
         NSBundleSummaryProvider (ValueObject& valobj, Stream& stream);
         
         bool

Modified: lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp (original)
+++ lldb/trunk/source/DataFormatters/CXXFormatterFunctions.cpp Fri Mar 15 19:50:25 2013
@@ -688,6 +688,102 @@ lldb_private::formatters::NSBundleSummar
 }
 
 bool
+lldb_private::formatters::NSNotificationSummaryProvider (ValueObject& valobj, Stream& stream)
+{
+    ProcessSP process_sp = valobj.GetProcessSP();
+    if (!process_sp)
+        return false;
+    
+    ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
+    
+    if (!runtime)
+        return false;
+    
+    ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
+    
+    if (!descriptor.get() || !descriptor->IsValid())
+        return false;
+    
+    uint32_t ptr_size = process_sp->GetAddressByteSize();
+    
+    lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
+    
+    if (!valobj_addr)
+        return false;
+    
+    const char* class_name = descriptor->GetClassName().GetCString();
+    
+    if (!class_name || !*class_name)
+        return false;
+    
+    if (!strcmp(class_name,"NSConcreteNotification"))
+    {
+        uint64_t offset = ptr_size;
+        ClangASTType type(valobj.GetClangAST(),valobj.GetClangType());
+        ValueObjectSP text(valobj.GetSyntheticChildAtOffset(offset, type, true));
+        StreamString summary_stream;
+        bool was_nsstring_ok = NSStringSummaryProvider(*text.get(), summary_stream);
+        if (was_nsstring_ok && summary_stream.GetSize() > 0)
+        {
+            stream.Printf("%s",summary_stream.GetData());
+            return true;
+        }
+    }
+    // this is either an unknown subclass or an NSBundle that comes from [NSBundle mainBundle]
+    // which is encoded differently and needs to be handled by running code
+    return ExtractSummaryFromObjCExpression(valobj, "NSString*", "name", stream);
+}
+
+bool
+lldb_private::formatters::NSMachPortSummaryProvider (ValueObject& valobj, Stream& stream)
+{
+    ProcessSP process_sp = valobj.GetProcessSP();
+    if (!process_sp)
+        return false;
+    
+    ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
+    
+    if (!runtime)
+        return false;
+    
+    ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
+    
+    if (!descriptor.get() || !descriptor->IsValid())
+        return false;
+    
+    uint32_t ptr_size = process_sp->GetAddressByteSize();
+    
+    lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
+    
+    if (!valobj_addr)
+        return false;
+    
+    const char* class_name = descriptor->GetClassName().GetCString();
+    
+    if (!class_name || !*class_name)
+        return false;
+    
+    uint64_t port_number = 0;
+    
+    do
+    {
+        if (!strcmp(class_name,"NSMachPort"))
+        {
+            uint64_t offset = (ptr_size == 4 ? 12 : 20);
+            Error error;
+            port_number = process_sp->ReadUnsignedIntegerFromMemory(offset+valobj_addr, 4, 0, error);
+            if (error.Success())
+                break;
+        }
+        if (!ExtractValueFromObjCExpression(valobj, "int", "machPort", port_number))
+            return false;
+    } while (false);
+    
+    stream.Printf("mach port: %u",(uint32_t)(port_number & 0x00000000FFFFFFFF));
+    return true;
+}
+
+bool
 lldb_private::formatters::CFBagSummaryProvider (ValueObject& valobj, Stream& stream)
 {
     ProcessSP process_sp = valobj.GetProcessSP();
@@ -726,7 +822,6 @@ lldb_private::formatters::CFBagSummaryPr
     
     if (is_type_ok == false)
     {
-//        num_children_vo = self.valobj.CreateValueFromExpression("count","(int)CFBagGetCount(" + stream.GetData() + " )")
         StackFrameSP frame_sp(valobj.GetFrameSP());
         if (!frame_sp)
             return false;
@@ -751,6 +846,70 @@ lldb_private::formatters::CFBagSummaryPr
                   count,(count == 1 ? "" : "s"));
     return true;
 }
+
+bool
+lldb_private::formatters::CFBinaryHeapSummaryProvider (ValueObject& valobj, Stream& stream)
+{
+    ProcessSP process_sp = valobj.GetProcessSP();
+    if (!process_sp)
+        return false;
+    
+    ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
+    
+    if (!runtime)
+        return false;
+    
+    ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
+    
+    if (!descriptor.get() || !descriptor->IsValid())
+        return false;
+    
+    uint32_t ptr_size = process_sp->GetAddressByteSize();
+    
+    lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
+    
+    if (!valobj_addr)
+        return false;
+    
+    uint32_t count = 0;
+    
+    bool is_type_ok = false; // check to see if this is a CFBinaryHeap we know about
+    if (descriptor->IsCFType())
+    {
+        ConstString type_name(valobj.GetTypeName());
+        if (type_name == ConstString("__CFBinaryHeap") || type_name == ConstString("const struct __CFBinaryHeap"))
+        {
+            if (valobj.IsPointerType())
+                is_type_ok = true;
+        }
+    }
+    
+    if (is_type_ok == false)
+    {
+        StackFrameSP frame_sp(valobj.GetFrameSP());
+        if (!frame_sp)
+            return false;
+        ValueObjectSP count_sp;
+        StreamString expr;
+        expr.Printf("(int)CFBinaryHeapGetCount((void*)0x%" PRIx64 ")",valobj.GetPointerValue());
+        if (process_sp->GetTarget().EvaluateExpression(expr.GetData(), frame_sp.get(), count_sp) != eExecutionCompleted)
+            return false;
+        if (!count_sp)
+            return false;
+        count = count_sp->GetValueAsUnsigned(0);
+    }
+    else
+    {
+        uint32_t offset = 2*ptr_size;
+        Error error;
+        count = process_sp->ReadUnsignedIntegerFromMemory(offset, 4, 0, error);
+        if (error.Fail())
+            return false;
+    }
+    stream.Printf("@\"%u item%s\"",
+                  count,(count == 1 ? "" : "s"));
+    return true;
+}
 
 bool
 lldb_private::formatters::NSNumberSummaryProvider (ValueObject& valobj, Stream& stream)

Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=177213&r1=177212&r2=177213&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Fri Mar 15 19:50:25 2013
@@ -926,8 +926,8 @@ FormatManager::LoadObjCFormatters()
     AddCXXSummary(appkit_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("const struct __CFBag"), appkit_flags);
     AddCXXSummary(appkit_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("CFMutableBagRef"), appkit_flags);
     
-    AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.CFBinaryHeap.CFBinaryHeap_SummaryProvider", ConstString("CFBinaryHeapRef"), appkit_flags);
-    AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.CFBinaryHeap.CFBinaryHeap_SummaryProvider", ConstString("__CFBinaryHeap"), appkit_flags);
+    AddCXXSummary(appkit_category_sp,lldb_private::formatters::CFBinaryHeapSummaryProvider, "CFBinaryHeap summary provider", ConstString("CFBinaryHeapRef"), appkit_flags);
+    AddCXXSummary(appkit_category_sp,lldb_private::formatters::CFBinaryHeapSummaryProvider, "CFBinaryHeap summary provider", ConstString("__CFBinaryHeap"), appkit_flags);
 
     AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSString"), appkit_flags);
     AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("CFStringRef"), appkit_flags);
@@ -952,10 +952,10 @@ FormatManager::LoadObjCFormatters()
     AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDataSummaryProvider<true>, "NSData summary provider", ConstString("CFDataRef"), appkit_flags);
     AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDataSummaryProvider<true>, "NSData summary provider", ConstString("CFMutableDataRef"), appkit_flags);
 
-    AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSMachPort.NSMachPort_SummaryProvider", ConstString("NSMachPort"), appkit_flags);
-    
-    AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSNotification.NSNotification_SummaryProvider", ConstString("NSNotification"), appkit_flags);
-    AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSNotification.NSNotification_SummaryProvider", ConstString("NSConcreteNotification"), appkit_flags);
+    AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSMachPortSummaryProvider, "NSMachPort summary provider", ConstString("NSMachPort"), appkit_flags);
+
+    AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNotificationSummaryProvider, "NSNotification summary provider", ConstString("NSNotification"), appkit_flags);
+    AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNotificationSummaryProvider, "NSNotification summary provider", ConstString("NSConcreteNotification"), appkit_flags);
 
     AddStringSummary(appkit_category_sp, "domain: ${var._domain} - code: ${var._code}", ConstString("NSError"), appkit_flags);
     AddStringSummary(appkit_category_sp,"name:${var.name%S} reason:${var.reason%S}",ConstString("NSException"),appkit_flags);





More information about the lldb-commits mailing list