NS(Mutable)IndexSet formatter moves from Python to C++

llvm-svn: 177217
This commit is contained in:
Enrico Granata 2013-03-16 01:18:00 +00:00
parent 7a007bfbad
commit 6a92511a08
4 changed files with 85 additions and 3 deletions

View File

@ -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

View File

@ -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);

View File

@ -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)
{

View File

@ -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}\"",