From 6a92511a08664b8baf214606724709a58464ed61 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Sat, 16 Mar 2013 01:18:00 +0000 Subject: [PATCH] NS(Mutable)IndexSet formatter moves from Python to C++ llvm-svn: 177217 --- lldb/examples/summaries/cocoa/NSIndexSet.py | 3 +- .../DataFormatters/CXXFormatterFunctions.h | 3 + .../DataFormatters/CXXFormatterFunctions.cpp | 78 +++++++++++++++++++ lldb/source/DataFormatters/FormatManager.cpp | 4 +- 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/lldb/examples/summaries/cocoa/NSIndexSet.py b/lldb/examples/summaries/cocoa/NSIndexSet.py index a1656fe90085..011d58dd773d 100644 --- a/lldb/examples/summaries/cocoa/NSIndexSet.py +++ b/lldb/examples/summaries/cocoa/NSIndexSet.py @@ -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 NS(Mutable)IndexSet +# example summary provider for NS(Mutable)IndexSet +# the real summary is now C++ code built into LLDB import lldb import ctypes import lldb.runtime.objc.objc_runtime diff --git a/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h b/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h index 8ba709efa389..8c18db2f5825 100644 --- a/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h +++ b/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h @@ -80,6 +80,9 @@ namespace lldb_private { bool NSDictionarySummaryProvider (ValueObject& valobj, Stream& stream); + bool + NSIndexSetSummaryProvider (ValueObject& valobj, Stream& stream); + bool NSArraySummaryProvider (ValueObject& valobj, Stream& stream); diff --git a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp index 89e156d8869f..dfd64b24f4d5 100644 --- a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp +++ b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp @@ -911,6 +911,84 @@ lldb_private::formatters::CFBinaryHeapSummaryProvider (ValueObject& valobj, Stre return true; } +bool +lldb_private::formatters::NSIndexSetSummaryProvider (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 count = 0; + + do { + if (!strcmp(class_name,"NSIndexSet") || !strcmp(class_name,"NSMutableIndexSet")) + { + Error error; + uint32_t mode = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr+ptr_size, 4, 0, error); + if (error.Fail()) + return false; + // this means the set is empty - count = 0 + if ((mode & 1) == 1) + { + count = 0; + break; + } + if ((mode & 2) == 2) + mode = 1; // this means the set only has one range + else + mode = 2; // this means the set has multiple ranges + if (mode == 1) + { + count = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr+3*ptr_size, ptr_size, 0, error); + if (error.Fail()) + return false; + } + else + { + // read a pointer to the data at 2*ptr_size + count = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr+2*ptr_size, ptr_size, 0, error); + if (error.Fail()) + return false; + // read the data at 2*ptr_size from the first location + count = process_sp->ReadUnsignedIntegerFromMemory(count+2*ptr_size, ptr_size, 0, error); + if (error.Fail()) + return false; + } + } + else + { + if (!ExtractValueFromObjCExpression(valobj, "unsigned long long int", "count", count)) + return false; + } + } while (false); + stream.Printf("%llu index%s", + count, + (count == 1 ? "" : "es")); + return true; +} + bool lldb_private::formatters::NSNumberSummaryProvider (ValueObject& valobj, Stream& stream) { diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index afc88d4160cb..aaf9cce1abf7 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -989,8 +989,8 @@ FormatManager::LoadObjCFormatters() AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSDate.CFAbsoluteTime_SummaryProvider", ConstString("CFAbsoluteTime"), appkit_flags); appkit_flags.SetDontShowValue(false); - AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSIndexSet.NSIndexSet_SummaryProvider", ConstString("NSIndexSet"), appkit_flags); - AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSIndexSet.NSIndexSet_SummaryProvider", ConstString("NSMutableIndexSet"), appkit_flags); + AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSIndexSetSummaryProvider, "NSIndexSet summary provider", ConstString("NSIndexSet"), appkit_flags); + AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSIndexSetSummaryProvider, "NSIndexSet summary provider", ConstString("NSMutableIndexSet"), appkit_flags); AddStringSummary(appkit_category_sp, "@\"${var.month%d}/${var.day%d}/${var.year%d} ${var.hour%d}:${var.minute%d}:${var.second}\"",