forked from OSchip/llvm-project
NSSet formatter is now C++ code
Split some NS* formatters in their own source files Refactored a utility function for the C++ formatters to use Fixed the skip-summary test case to be explicit about requiring libstdc++ for operation llvm-svn: 175323
This commit is contained in:
parent
e9434778f7
commit
f615b80d08
|
@ -28,6 +28,12 @@ namespace lldb_private {
|
|||
const char* selector,
|
||||
uint64_t &value);
|
||||
|
||||
bool
|
||||
ExtractSummaryFromObjCExpression (ValueObject &valobj,
|
||||
const char* target_type,
|
||||
const char* selector,
|
||||
Stream &stream);
|
||||
|
||||
lldb::ValueObjectSP
|
||||
CallSelectorOnObject (ValueObject &valobj,
|
||||
const char* return_type,
|
||||
|
@ -40,6 +46,9 @@ namespace lldb_private {
|
|||
const char* selector,
|
||||
const char* key);
|
||||
|
||||
size_t
|
||||
ExtractIndexFromString (const char* item_name);
|
||||
|
||||
bool
|
||||
Char16StringSummaryProvider (ValueObject& valobj, Stream& stream); // char16_t* and unichar*
|
||||
|
||||
|
@ -71,6 +80,10 @@ namespace lldb_private {
|
|||
bool
|
||||
NSArraySummaryProvider (ValueObject& valobj, Stream& stream);
|
||||
|
||||
template<bool cf_style>
|
||||
bool
|
||||
NSSetSummaryProvider (ValueObject& valobj, Stream& stream);
|
||||
|
||||
template<bool needs_at>
|
||||
bool
|
||||
NSDataSummaryProvider (ValueObject& valobj, Stream& stream);
|
||||
|
|
|
@ -547,6 +547,9 @@
|
|||
94CB257116B0A4270059775D /* TypeSummary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94CB256E16B0A4260059775D /* TypeSummary.cpp */; };
|
||||
94CB257216B0A4270059775D /* TypeSynthetic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94CB256F16B0A4270059775D /* TypeSynthetic.cpp */; };
|
||||
94CB257416B1D3880059775D /* FormatCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94CB257316B1D3870059775D /* FormatCache.cpp */; };
|
||||
94D6A0AA16CEB55F00833B6E /* NSArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D6A0A716CEB55F00833B6E /* NSArray.cpp */; };
|
||||
94D6A0AB16CEB55F00833B6E /* NSDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D6A0A816CEB55F00833B6E /* NSDictionary.cpp */; };
|
||||
94D6A0AC16CEB55F00833B6E /* NSSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D6A0A916CEB55F00833B6E /* NSSet.cpp */; };
|
||||
94EA1D5C15E6C9B400D4171A /* PythonDataObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94EA1D5B15E6C9B400D4171A /* PythonDataObjects.cpp */; };
|
||||
94FA3DE01405D50400833217 /* ValueObjectConstResultChild.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94FA3DDF1405D50300833217 /* ValueObjectConstResultChild.cpp */; };
|
||||
9A19A6AF1163BBB200E0D453 /* SBValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A19A6A51163BB7E00E0D453 /* SBValue.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
|
@ -1583,6 +1586,9 @@
|
|||
94CB256F16B0A4270059775D /* TypeSynthetic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypeSynthetic.cpp; path = source/DataFormatters/TypeSynthetic.cpp; sourceTree = "<group>"; };
|
||||
94CB257316B1D3870059775D /* FormatCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FormatCache.cpp; path = source/DataFormatters/FormatCache.cpp; sourceTree = "<group>"; };
|
||||
94CB257516B1D3910059775D /* FormatCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FormatCache.h; path = include/lldb/DataFormatters/FormatCache.h; sourceTree = "<group>"; };
|
||||
94D6A0A716CEB55F00833B6E /* NSArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSArray.cpp; path = source/DataFormatters/NSArray.cpp; sourceTree = "<group>"; };
|
||||
94D6A0A816CEB55F00833B6E /* NSDictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSDictionary.cpp; path = source/DataFormatters/NSDictionary.cpp; sourceTree = "<group>"; };
|
||||
94D6A0A916CEB55F00833B6E /* NSSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSSet.cpp; path = source/DataFormatters/NSSet.cpp; sourceTree = "<group>"; };
|
||||
94E367CC140C4EC4001C7A5A /* modify-python-lldb.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = "modify-python-lldb.py"; sourceTree = "<group>"; };
|
||||
94E367CE140C4EEA001C7A5A /* python-typemaps.swig */ = {isa = PBXFileReference; lastKnownFileType = text; path = "python-typemaps.swig"; sourceTree = "<group>"; };
|
||||
94EA1D5A15E6C99B00D4171A /* PythonDataObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PythonDataObjects.h; path = include/lldb/Interpreter/PythonDataObjects.h; sourceTree = "<group>"; };
|
||||
|
@ -3352,6 +3358,9 @@
|
|||
94CB256216B069800059775D /* FormatManager.h */,
|
||||
94CB255A16B069770059775D /* FormatManager.cpp */,
|
||||
94CB256316B069800059775D /* FormatNavigator.h */,
|
||||
94D6A0A716CEB55F00833B6E /* NSArray.cpp */,
|
||||
94D6A0A816CEB55F00833B6E /* NSDictionary.cpp */,
|
||||
94D6A0A916CEB55F00833B6E /* NSSet.cpp */,
|
||||
94CB256816B096F90059775D /* TypeCategory.h */,
|
||||
94CB256416B096F10059775D /* TypeCategory.cpp */,
|
||||
94CB256916B096FA0059775D /* TypeCategoryMap.h */,
|
||||
|
@ -3955,6 +3964,7 @@
|
|||
2689006B13353E0E00698AC0 /* IRForTarget.cpp in Sources */,
|
||||
2689006D13353E0E00698AC0 /* RecordingMemoryManager.cpp in Sources */,
|
||||
2689006E13353E1A00698AC0 /* File.cpp in Sources */,
|
||||
94D6A0AB16CEB55F00833B6E /* NSDictionary.cpp in Sources */,
|
||||
2689006F13353E1A00698AC0 /* FileSpec.cpp in Sources */,
|
||||
2689007013353E1A00698AC0 /* Condition.cpp in Sources */,
|
||||
2689007113353E1A00698AC0 /* Host.cpp in Sources */,
|
||||
|
@ -4089,6 +4099,7 @@
|
|||
2689011113353E8200698AC0 /* StringExtractor.cpp in Sources */,
|
||||
2689011213353E8200698AC0 /* StringExtractorGDBRemote.cpp in Sources */,
|
||||
2689011313353E8200698AC0 /* PseudoTerminal.cpp in Sources */,
|
||||
94D6A0AA16CEB55F00833B6E /* NSArray.cpp in Sources */,
|
||||
26B1FCC21338115F002886E2 /* Host.mm in Sources */,
|
||||
26744EF11338317700EF765A /* GDBRemoteCommunicationClient.cpp in Sources */,
|
||||
26744EF31338317700EF765A /* GDBRemoteCommunicationServer.cpp in Sources */,
|
||||
|
@ -4199,6 +4210,7 @@
|
|||
26491E3E15E1DB9F00CBFFC2 /* OptionValueRegex.cpp in Sources */,
|
||||
2697A39315E404B1003E682C /* OptionValueArch.cpp in Sources */,
|
||||
94EA1D5C15E6C9B400D4171A /* PythonDataObjects.cpp in Sources */,
|
||||
94D6A0AC16CEB55F00833B6E /* NSSet.cpp in Sources */,
|
||||
2698699B15E6CBD0002415FF /* OperatingSystemPython.cpp in Sources */,
|
||||
947A1D641616476B0017C8D1 /* CommandObjectPlugin.cpp in Sources */,
|
||||
262ED0081631FA3A00879631 /* OptionGroupString.cpp in Sources */,
|
||||
|
|
|
@ -61,6 +61,41 @@ lldb_private::formatters::ExtractValueFromObjCExpression (ValueObject &valobj,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::ExtractSummaryFromObjCExpression (ValueObject &valobj,
|
||||
const char* target_type,
|
||||
const char* selector,
|
||||
Stream &stream)
|
||||
{
|
||||
if (!target_type || !*target_type)
|
||||
return false;
|
||||
if (!selector || !*selector)
|
||||
return false;
|
||||
StreamString expr;
|
||||
expr.Printf("(%s)[(id)0x%" PRIx64 "%s]",target_type,valobj.GetPointerValue(),selector);
|
||||
ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
|
||||
lldb::ValueObjectSP result_sp;
|
||||
Target* target = exe_ctx.GetTargetPtr();
|
||||
StackFrame* stack_frame = exe_ctx.GetFramePtr();
|
||||
if (!target || !stack_frame)
|
||||
return false;
|
||||
|
||||
EvaluateExpressionOptions options;
|
||||
options.SetCoerceToId(false)
|
||||
.SetUnwindOnError(true)
|
||||
.SetKeepInMemory(true)
|
||||
.SetUseDynamic(lldb::eDynamicCanRunTarget);
|
||||
|
||||
target->EvaluateExpression(expr.GetData(),
|
||||
stack_frame,
|
||||
result_sp,
|
||||
options);
|
||||
if (!result_sp)
|
||||
return false;
|
||||
stream.Printf("%s",result_sp->GetSummaryAsCString());
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::CallSelectorOnObject (ValueObject &valobj,
|
||||
const char* return_type,
|
||||
|
@ -522,142 +557,6 @@ lldb_private::formatters::LibcxxStringSummaryProvider (ValueObject& valobj, Stre
|
|||
return error.Success();
|
||||
}
|
||||
|
||||
template<bool name_entries>
|
||||
bool
|
||||
lldb_private::formatters::NSDictionarySummaryProvider (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();
|
||||
bool is_64bit = (ptr_size == 8);
|
||||
|
||||
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
|
||||
|
||||
if (!valobj_addr)
|
||||
return false;
|
||||
|
||||
uint64_t value = 0;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return false;
|
||||
|
||||
if (!strcmp(class_name,"__NSDictionaryI"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSDictionaryM"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSCFDictionary"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + (is_64bit ? 20 : 12), ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
if (is_64bit)
|
||||
value &= ~0x0f1f000000000000UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ExtractValueFromObjCExpression(valobj, "int", "count", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.Printf("%s%" PRIu64 " %s%s",
|
||||
(name_entries ? "@\"" : ""),
|
||||
value,
|
||||
(name_entries ? (value == 1 ? "entry" : "entries") : (value == 1 ? "key/value pair" : "key/value pairs")),
|
||||
(name_entries ? "\"" : ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArraySummaryProvider (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;
|
||||
|
||||
uint64_t value = 0;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return false;
|
||||
|
||||
if (!strcmp(class_name,"__NSArrayI"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSArrayM"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSCFArray"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + 2 * ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ExtractValueFromObjCExpression(valobj, "int", "count", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.Printf("@\"%" PRIu64 " object%s\"",
|
||||
value,
|
||||
value == 1 ? "" : "s");
|
||||
return true;
|
||||
}
|
||||
|
||||
template<bool needs_at>
|
||||
bool
|
||||
lldb_private::formatters::NSDataSummaryProvider (ValueObject& valobj, Stream& stream)
|
||||
|
@ -834,32 +733,7 @@ lldb_private::formatters::NSNumberSummaryProvider (ValueObject& valobj, Stream&
|
|||
}
|
||||
else
|
||||
{
|
||||
// similar to ExtractValueFromObjCExpression but uses summary instead of value
|
||||
StreamString expr_path_stream;
|
||||
valobj.GetExpressionPath(expr_path_stream, false);
|
||||
StreamString expr;
|
||||
expr.Printf("(NSString*)[%s stringValue]",expr_path_stream.GetData());
|
||||
ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
|
||||
lldb::ValueObjectSP result_sp;
|
||||
Target* target = exe_ctx.GetTargetPtr();
|
||||
StackFrame* stack_frame = exe_ctx.GetFramePtr();
|
||||
if (!target || !stack_frame)
|
||||
return false;
|
||||
|
||||
EvaluateExpressionOptions options;
|
||||
options.SetCoerceToId(false)
|
||||
.SetUnwindOnError(true)
|
||||
.SetKeepInMemory(true)
|
||||
.SetUseDynamic(lldb::eDynamicCanRunTarget);
|
||||
|
||||
target->EvaluateExpression(expr.GetData(),
|
||||
stack_frame,
|
||||
result_sp,
|
||||
options);
|
||||
if (!result_sp)
|
||||
return false;
|
||||
stream.Printf("%s",result_sp->GetSummaryAsCString());
|
||||
return true;
|
||||
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "stringValue", stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1109,32 +983,7 @@ lldb_private::formatters::NSURLSummaryProvider (ValueObject& valobj, Stream& str
|
|||
}
|
||||
else
|
||||
{
|
||||
// similar to ExtractValueFromObjCExpression but uses summary instead of value
|
||||
StreamString expr_path_stream;
|
||||
valobj.GetExpressionPath(expr_path_stream, false);
|
||||
StreamString expr;
|
||||
expr.Printf("(NSString*)[%s description]",expr_path_stream.GetData());
|
||||
ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
|
||||
lldb::ValueObjectSP result_sp;
|
||||
Target* target = exe_ctx.GetTargetPtr();
|
||||
StackFrame* stack_frame = exe_ctx.GetFramePtr();
|
||||
if (!target || !stack_frame)
|
||||
return false;
|
||||
|
||||
EvaluateExpressionOptions options;
|
||||
options.SetCoerceToId(false)
|
||||
.SetUnwindOnError(true)
|
||||
.SetKeepInMemory(true)
|
||||
.SetUseDynamic(lldb::eDynamicCanRunTarget);
|
||||
|
||||
target->EvaluateExpression(expr.GetData(),
|
||||
stack_frame,
|
||||
result_sp,
|
||||
options);
|
||||
if (!result_sp)
|
||||
return false;
|
||||
stream.Printf("%s",result_sp->GetSummaryAsCString());
|
||||
return true;
|
||||
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "description", stream);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1207,717 +1056,23 @@ lldb_private::formatters::ObjCSELSummaryProvider (ValueObject& valobj, Stream& s
|
|||
return true;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::NSArrayMSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_data_32(NULL),
|
||||
m_data_64(NULL)
|
||||
{
|
||||
if (valobj_sp)
|
||||
{
|
||||
m_id_type = ClangASTType(valobj_sp->GetClangAST(),valobj_sp->GetClangAST()->ObjCBuiltinIdTy.getAsOpaquePtr());
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
if (m_data_32)
|
||||
return m_data_32->_used;
|
||||
if (m_data_64)
|
||||
return m_data_64->_used;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
return lldb::ValueObjectSP();
|
||||
if (idx >= CalculateNumChildren())
|
||||
return lldb::ValueObjectSP();
|
||||
lldb::addr_t object_at_idx = (m_data_32 ? m_data_32->_data : m_data_64->_data);
|
||||
object_at_idx += (idx * m_ptr_size);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
lldb::ValueObjectSP retval_sp = ValueObject::CreateValueObjectFromAddress(idx_name.GetData(),
|
||||
object_at_idx,
|
||||
m_exe_ctx_ref,
|
||||
m_id_type);
|
||||
m_children.push_back(retval_sp);
|
||||
return retval_sp;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::Update()
|
||||
{
|
||||
m_children.clear();
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
m_ptr_size = 0;
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
if (m_ptr_size == 4)
|
||||
{
|
||||
m_data_32 = new DataDescriptor_32();
|
||||
process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data_64 = new DataDescriptor_64();
|
||||
process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error);
|
||||
}
|
||||
if (error.Fail())
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
ExtractIndexFromString (const char* item_name)
|
||||
lldb_private::formatters::ExtractIndexFromString (const char* item_name)
|
||||
{
|
||||
if (!item_name || !*item_name)
|
||||
return UINT32_MAX;
|
||||
if (*item_name != '[')
|
||||
return UINT32_MAX;
|
||||
item_name++;
|
||||
uint32_t idx = 0;
|
||||
while(*item_name)
|
||||
{
|
||||
char x = *item_name;
|
||||
if (x == ']')
|
||||
break;
|
||||
if (x < '0' || x > '9')
|
||||
return UINT32_MAX;
|
||||
idx = 10*idx + (x-'0');
|
||||
item_name++;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
char* endptr = NULL;
|
||||
unsigned long int idx = ::strtoul(item_name, &endptr, 0);
|
||||
if (idx == 0 && endptr == item_name)
|
||||
return UINT32_MAX;
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
if (idx == ULONG_MAX)
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::~NSArrayMSyntheticFrontEnd ()
|
||||
{
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::NSArrayISyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_items(0),
|
||||
m_data_ptr(0)
|
||||
{
|
||||
if (valobj_sp)
|
||||
{
|
||||
m_id_type = ClangASTType(valobj_sp->GetClangAST(),valobj_sp->GetClangAST()->ObjCBuiltinIdTy.getAsOpaquePtr());
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::~NSArrayISyntheticFrontEnd ()
|
||||
{
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
return m_items;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::Update()
|
||||
{
|
||||
m_ptr_size = 0;
|
||||
m_items = 0;
|
||||
m_data_ptr = 0;
|
||||
m_children.clear();
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
m_items = process_sp->ReadPointerFromMemory(data_location, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
m_data_ptr = data_location+m_ptr_size;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
if (idx >= CalculateNumChildren())
|
||||
return lldb::ValueObjectSP();
|
||||
lldb::addr_t object_at_idx = m_data_ptr;
|
||||
object_at_idx += (idx * m_ptr_size);
|
||||
ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
|
||||
if (!process_sp)
|
||||
return lldb::ValueObjectSP();
|
||||
Error error;
|
||||
object_at_idx = process_sp->ReadPointerFromMemory(object_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
StreamString expr;
|
||||
expr.Printf("(id)%" PRIu64,object_at_idx);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
lldb::ValueObjectSP retval_sp = ValueObject::CreateValueObjectFromExpression(idx_name.GetData(), expr.GetData(), m_exe_ctx_ref);
|
||||
m_children.push_back(retval_sp);
|
||||
return retval_sp;
|
||||
}
|
||||
|
||||
SyntheticChildrenFrontEnd* lldb_private::formatters::NSArraySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
|
||||
{
|
||||
lldb::ProcessSP process_sp (valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return NULL;
|
||||
ObjCLanguageRuntime *runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
|
||||
if (!runtime)
|
||||
return NULL;
|
||||
|
||||
if (!valobj_sp->IsPointerType())
|
||||
{
|
||||
Error error;
|
||||
valobj_sp = valobj_sp->AddressOf(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(*valobj_sp.get()));
|
||||
|
||||
if (!descriptor.get() || !descriptor->IsValid())
|
||||
return NULL;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return NULL;
|
||||
|
||||
if (!strcmp(class_name,"__NSArrayI"))
|
||||
{
|
||||
return (new NSArrayISyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSArrayM"))
|
||||
{
|
||||
return (new NSArrayMSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (new NSArrayCodeRunningSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::NSArrayCodeRunningSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get())
|
||||
{}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
uint64_t count = 0;
|
||||
if (ExtractValueFromObjCExpression(m_backend, "int", "count", count))
|
||||
return count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
lldb::ValueObjectSP valobj_sp = CallSelectorOnObject(m_backend,"id","objectAtIndex:",idx);
|
||||
if (valobj_sp)
|
||||
valobj_sp->SetName(ConstString(idx_name.GetData()));
|
||||
return valobj_sp;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::Update()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::~NSArrayCodeRunningSyntheticFrontEnd ()
|
||||
{}
|
||||
|
||||
SyntheticChildrenFrontEnd* lldb_private::formatters::NSDictionarySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
|
||||
{
|
||||
|
||||
lldb::ProcessSP process_sp (valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return NULL;
|
||||
ObjCLanguageRuntime *runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
|
||||
if (!runtime)
|
||||
return NULL;
|
||||
|
||||
if (!valobj_sp->IsPointerType())
|
||||
{
|
||||
Error error;
|
||||
valobj_sp = valobj_sp->AddressOf(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(*valobj_sp.get()));
|
||||
|
||||
if (!descriptor.get() || !descriptor->IsValid())
|
||||
return NULL;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return NULL;
|
||||
|
||||
if (!strcmp(class_name,"__NSDictionaryI"))
|
||||
{
|
||||
return (new NSDictionaryISyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSDictionaryM"))
|
||||
{
|
||||
return (new NSDictionaryMSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (new NSDictionaryCodeRunningSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::NSDictionaryCodeRunningSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get())
|
||||
{}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
uint64_t count = 0;
|
||||
if (ExtractValueFromObjCExpression(m_backend, "int", "count", count))
|
||||
return count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
StreamString valobj_expr_path;
|
||||
m_backend.GetExpressionPath(valobj_expr_path, false);
|
||||
StreamString key_fetcher_expr;
|
||||
key_fetcher_expr.Printf("(id)[(NSArray*)[%s allKeys] objectAtIndex:%zu]",valobj_expr_path.GetData(),idx);
|
||||
StreamString value_fetcher_expr;
|
||||
value_fetcher_expr.Printf("(id)[%s objectForKey:%s]",valobj_expr_path.GetData(),key_fetcher_expr.GetData());
|
||||
StreamString object_fetcher_expr;
|
||||
object_fetcher_expr.Printf("struct __lldb_autogen_nspair { id key; id value; } _lldb_valgen_item; _lldb_valgen_item.key = %s; _lldb_valgen_item.value = %s; _lldb_valgen_item;",key_fetcher_expr.GetData(),value_fetcher_expr.GetData());
|
||||
lldb::ValueObjectSP child_sp;
|
||||
m_backend.GetTargetSP()->EvaluateExpression(object_fetcher_expr.GetData(), m_backend.GetFrameSP().get(), child_sp,
|
||||
EvaluateExpressionOptions().SetKeepInMemory(true));
|
||||
if (child_sp)
|
||||
child_sp->SetName(ConstString(idx_name.GetData()));
|
||||
return child_sp;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::Update()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::~NSDictionaryCodeRunningSyntheticFrontEnd ()
|
||||
{}
|
||||
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::NSDictionaryISyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_data_32(NULL),
|
||||
m_data_64(NULL)
|
||||
{
|
||||
if (valobj_sp)
|
||||
Update();
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::~NSDictionaryISyntheticFrontEnd ()
|
||||
{
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
return 0;
|
||||
return (m_data_32 ? m_data_32->_used : m_data_64->_used);
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::Update()
|
||||
{
|
||||
m_children.clear();
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
m_ptr_size = 0;
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
if (m_ptr_size == 4)
|
||||
{
|
||||
m_data_32 = new DataDescriptor_32();
|
||||
process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data_64 = new DataDescriptor_64();
|
||||
process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error);
|
||||
}
|
||||
if (error.Fail())
|
||||
return false;
|
||||
m_data_ptr = data_location + m_ptr_size;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
uint32_t num_children = CalculateNumChildren();
|
||||
|
||||
if (idx >= num_children)
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
if (m_children.empty())
|
||||
{
|
||||
// do the scan phase
|
||||
lldb::addr_t key_at_idx = 0, val_at_idx = 0;
|
||||
|
||||
uint32_t tries = 0;
|
||||
uint32_t test_idx = 0;
|
||||
|
||||
while(tries < num_children)
|
||||
{
|
||||
key_at_idx = m_data_ptr + (2*test_idx * m_ptr_size);
|
||||
val_at_idx = key_at_idx + m_ptr_size;
|
||||
ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
|
||||
if (!process_sp)
|
||||
return lldb::ValueObjectSP();
|
||||
Error error;
|
||||
key_at_idx = process_sp->ReadPointerFromMemory(key_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
val_at_idx = process_sp->ReadPointerFromMemory(val_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
test_idx++;
|
||||
|
||||
if (!key_at_idx || !val_at_idx)
|
||||
continue;
|
||||
tries++;
|
||||
|
||||
DictionaryItemDescriptor descriptor = {key_at_idx,val_at_idx,lldb::ValueObjectSP()};
|
||||
|
||||
m_children.push_back(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (idx >= m_children.size()) // should never happen
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
DictionaryItemDescriptor &dict_item = m_children[idx];
|
||||
if (!dict_item.valobj_sp)
|
||||
{
|
||||
// make the new ValueObject
|
||||
StreamString expr;
|
||||
expr.Printf("struct __lldb_autogen_nspair { id key; id value; } _lldb_valgen_item; _lldb_valgen_item.key = (id)%" PRIu64 " ; _lldb_valgen_item.value = (id)%" PRIu64 "; _lldb_valgen_item;",dict_item.key_ptr,dict_item.val_ptr);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
dict_item.valobj_sp = ValueObject::CreateValueObjectFromExpression(idx_name.GetData(), expr.GetData(), m_exe_ctx_ref);
|
||||
}
|
||||
return dict_item.valobj_sp;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::NSDictionaryMSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_data_32(NULL),
|
||||
m_data_64(NULL)
|
||||
{
|
||||
if (valobj_sp)
|
||||
Update ();
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::~NSDictionaryMSyntheticFrontEnd ()
|
||||
{
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
return 0;
|
||||
return (m_data_32 ? m_data_32->_used : m_data_64->_used);
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::Update()
|
||||
{
|
||||
m_children.clear();
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
m_ptr_size = 0;
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
if (m_ptr_size == 4)
|
||||
{
|
||||
m_data_32 = new DataDescriptor_32();
|
||||
process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data_64 = new DataDescriptor_64();
|
||||
process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error);
|
||||
}
|
||||
if (error.Fail())
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
lldb::addr_t m_keys_ptr = (m_data_32 ? m_data_32->_keys_addr : m_data_64->_keys_addr);
|
||||
lldb::addr_t m_values_ptr = (m_data_32 ? m_data_32->_objs_addr : m_data_64->_objs_addr);
|
||||
|
||||
uint32_t num_children = CalculateNumChildren();
|
||||
|
||||
if (idx >= num_children)
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
if (m_children.empty())
|
||||
{
|
||||
// do the scan phase
|
||||
lldb::addr_t key_at_idx = 0, val_at_idx = 0;
|
||||
|
||||
uint32_t tries = 0;
|
||||
uint32_t test_idx = 0;
|
||||
|
||||
while(tries < num_children)
|
||||
{
|
||||
key_at_idx = m_keys_ptr + (test_idx * m_ptr_size);
|
||||
val_at_idx = m_values_ptr + (test_idx * m_ptr_size);;
|
||||
ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
|
||||
if (!process_sp)
|
||||
return lldb::ValueObjectSP();
|
||||
Error error;
|
||||
key_at_idx = process_sp->ReadPointerFromMemory(key_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
val_at_idx = process_sp->ReadPointerFromMemory(val_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
test_idx++;
|
||||
|
||||
if (!key_at_idx || !val_at_idx)
|
||||
continue;
|
||||
tries++;
|
||||
|
||||
DictionaryItemDescriptor descriptor = {key_at_idx,val_at_idx,lldb::ValueObjectSP()};
|
||||
|
||||
m_children.push_back(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (idx >= m_children.size()) // should never happen
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
DictionaryItemDescriptor &dict_item = m_children[idx];
|
||||
if (!dict_item.valobj_sp)
|
||||
{
|
||||
// make the new ValueObject
|
||||
StreamString expr;
|
||||
expr.Printf("struct __lldb_autogen_nspair { id key; id value; } _lldb_valgen_item; _lldb_valgen_item.key = (id)%" PRIu64 " ; _lldb_valgen_item.value = (id)%" PRIu64 "; _lldb_valgen_item;",dict_item.key_ptr,dict_item.val_ptr);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
dict_item.valobj_sp = ValueObject::CreateValueObjectFromExpression(idx_name.GetData(), expr.GetData(), m_exe_ctx_ref);
|
||||
}
|
||||
return dict_item.valobj_sp;
|
||||
}
|
||||
|
||||
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::LibcxxVectorBoolSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
|
@ -2234,12 +1389,6 @@ lldb_private::formatters::LibstdcppVectorBoolSyntheticFrontEndCreator (CXXSynthe
|
|||
return (new LibstdcppVectorBoolSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
|
||||
template bool
|
||||
lldb_private::formatters::NSDictionarySummaryProvider<true> (ValueObject&, Stream&) ;
|
||||
|
||||
template bool
|
||||
lldb_private::formatters::NSDictionarySummaryProvider<false> (ValueObject&, Stream&) ;
|
||||
|
||||
template bool
|
||||
lldb_private::formatters::NSDataSummaryProvider<true> (ValueObject&, Stream&) ;
|
||||
|
||||
|
|
|
@ -935,15 +935,14 @@ FormatManager::LoadObjCFormatters()
|
|||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::RuntimeSpecificDescriptionSummaryProvider, "NSTask summary provider", ConstString("NSTask"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::RuntimeSpecificDescriptionSummaryProvider, "NSValue summary provider", ConstString("NSValue"), appkit_flags);
|
||||
|
||||
|
||||
AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSSet.NSSet_SummaryProvider", ConstString("NSSet"), appkit_flags);
|
||||
AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSSet.NSSet_SummaryProvider2", ConstString("CFSetRef"), appkit_flags);
|
||||
AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSSet.NSSet_SummaryProvider2", ConstString("CFMutableSetRef"), appkit_flags);
|
||||
AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSSet.NSSet_SummaryProvider", ConstString("__NSCFSet"), appkit_flags);
|
||||
AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSSet.NSSet_SummaryProvider", ConstString("__NSSetI"), appkit_flags);
|
||||
AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSSet.NSSet_SummaryProvider", ConstString("__NSSetM"), appkit_flags);
|
||||
AddScriptSummary(appkit_category_sp, "lldb.formatters.objc.NSSet.NSSet_SummaryProvider", ConstString("NSCountedSet"), appkit_flags);
|
||||
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>, "NSSet summary", ConstString("NSSet"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSSetSummaryProvider<true>, "CFSetRef summary", ConstString("CFSetRef"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSSetSummaryProvider<true>, "CFMutableSetRef summary", ConstString("CFMutableSetRef"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>, "__NSCFSet summary", ConstString("__NSCFSet"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>, "__NSSetI summary", ConstString("__NSSetI"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>, "__NSSetM summary", ConstString("__NSSetM"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>, "NSCountedSet summary", ConstString("NSCountedSet"), appkit_flags);
|
||||
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSURLSummaryProvider, "NSURL summary provider", ConstString("NSURL"), appkit_flags);
|
||||
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSURLSummaryProvider, "NSURL summary provider", ConstString("CFURLRef"), appkit_flags);
|
||||
|
||||
|
|
|
@ -0,0 +1,386 @@
|
|||
//===-- NSArray.cpp ---------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/lldb-python.h"
|
||||
|
||||
#include "lldb/DataFormatters/CXXFormatterFunctions.h"
|
||||
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
|
||||
#include "lldb/Core/DataBufferHeap.h"
|
||||
#include "lldb/Core/Error.h"
|
||||
#include "lldb/Core/Stream.h"
|
||||
#include "lldb/Core/ValueObject.h"
|
||||
#include "lldb/Core/ValueObjectConstResult.h"
|
||||
#include "lldb/Host/Endian.h"
|
||||
#include "lldb/Symbol/ClangASTContext.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "lldb/Target/Target.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
using namespace lldb_private::formatters;
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArraySummaryProvider (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;
|
||||
|
||||
uint64_t value = 0;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return false;
|
||||
|
||||
if (!strcmp(class_name,"__NSArrayI"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSArrayM"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSCFArray"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + 2 * ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ExtractValueFromObjCExpression(valobj, "int", "count", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.Printf("@\"%" PRIu64 " object%s\"",
|
||||
value,
|
||||
value == 1 ? "" : "s");
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::NSArrayMSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_data_32(NULL),
|
||||
m_data_64(NULL)
|
||||
{
|
||||
if (valobj_sp)
|
||||
{
|
||||
m_id_type = ClangASTType(valobj_sp->GetClangAST(),valobj_sp->GetClangAST()->ObjCBuiltinIdTy.getAsOpaquePtr());
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
if (m_data_32)
|
||||
return m_data_32->_used;
|
||||
if (m_data_64)
|
||||
return m_data_64->_used;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
return lldb::ValueObjectSP();
|
||||
if (idx >= CalculateNumChildren())
|
||||
return lldb::ValueObjectSP();
|
||||
lldb::addr_t object_at_idx = (m_data_32 ? m_data_32->_data : m_data_64->_data);
|
||||
object_at_idx += (idx * m_ptr_size);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
lldb::ValueObjectSP retval_sp = ValueObject::CreateValueObjectFromAddress(idx_name.GetData(),
|
||||
object_at_idx,
|
||||
m_exe_ctx_ref,
|
||||
m_id_type);
|
||||
m_children.push_back(retval_sp);
|
||||
return retval_sp;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::Update()
|
||||
{
|
||||
m_children.clear();
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
m_ptr_size = 0;
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
if (m_ptr_size == 4)
|
||||
{
|
||||
m_data_32 = new DataDescriptor_32();
|
||||
process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data_64 = new DataDescriptor_64();
|
||||
process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error);
|
||||
}
|
||||
if (error.Fail())
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
return UINT32_MAX;
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayMSyntheticFrontEnd::~NSArrayMSyntheticFrontEnd ()
|
||||
{
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::NSArrayISyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_items(0),
|
||||
m_data_ptr(0)
|
||||
{
|
||||
if (valobj_sp)
|
||||
{
|
||||
m_id_type = ClangASTType(valobj_sp->GetClangAST(),valobj_sp->GetClangAST()->ObjCBuiltinIdTy.getAsOpaquePtr());
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::~NSArrayISyntheticFrontEnd ()
|
||||
{
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
return m_items;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::Update()
|
||||
{
|
||||
m_ptr_size = 0;
|
||||
m_items = 0;
|
||||
m_data_ptr = 0;
|
||||
m_children.clear();
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
m_items = process_sp->ReadPointerFromMemory(data_location, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
m_data_ptr = data_location+m_ptr_size;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSArrayISyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
if (idx >= CalculateNumChildren())
|
||||
return lldb::ValueObjectSP();
|
||||
lldb::addr_t object_at_idx = m_data_ptr;
|
||||
object_at_idx += (idx * m_ptr_size);
|
||||
ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
|
||||
if (!process_sp)
|
||||
return lldb::ValueObjectSP();
|
||||
Error error;
|
||||
object_at_idx = process_sp->ReadPointerFromMemory(object_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
StreamString expr;
|
||||
expr.Printf("(id)%" PRIu64,object_at_idx);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
lldb::ValueObjectSP retval_sp = ValueObject::CreateValueObjectFromExpression(idx_name.GetData(), expr.GetData(), m_exe_ctx_ref);
|
||||
m_children.push_back(retval_sp);
|
||||
return retval_sp;
|
||||
}
|
||||
|
||||
SyntheticChildrenFrontEnd* lldb_private::formatters::NSArraySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
|
||||
{
|
||||
lldb::ProcessSP process_sp (valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return NULL;
|
||||
ObjCLanguageRuntime *runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
|
||||
if (!runtime)
|
||||
return NULL;
|
||||
|
||||
if (!valobj_sp->IsPointerType())
|
||||
{
|
||||
Error error;
|
||||
valobj_sp = valobj_sp->AddressOf(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(*valobj_sp.get()));
|
||||
|
||||
if (!descriptor.get() || !descriptor->IsValid())
|
||||
return NULL;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return NULL;
|
||||
|
||||
if (!strcmp(class_name,"__NSArrayI"))
|
||||
{
|
||||
return (new NSArrayISyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSArrayM"))
|
||||
{
|
||||
return (new NSArrayMSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (new NSArrayCodeRunningSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::NSArrayCodeRunningSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get())
|
||||
{}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
uint64_t count = 0;
|
||||
if (ExtractValueFromObjCExpression(m_backend, "int", "count", count))
|
||||
return count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
lldb::ValueObjectSP valobj_sp = CallSelectorOnObject(m_backend,"id","objectAtIndex:",idx);
|
||||
if (valobj_sp)
|
||||
valobj_sp->SetName(ConstString(idx_name.GetData()));
|
||||
return valobj_sp;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::Update()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSArrayCodeRunningSyntheticFrontEnd::~NSArrayCodeRunningSyntheticFrontEnd ()
|
||||
{}
|
|
@ -0,0 +1,501 @@
|
|||
//===-- NSDictionary.cpp ------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/lldb-python.h"
|
||||
|
||||
#include "lldb/DataFormatters/CXXFormatterFunctions.h"
|
||||
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
|
||||
#include "lldb/Core/DataBufferHeap.h"
|
||||
#include "lldb/Core/Error.h"
|
||||
#include "lldb/Core/Stream.h"
|
||||
#include "lldb/Core/ValueObject.h"
|
||||
#include "lldb/Core/ValueObjectConstResult.h"
|
||||
#include "lldb/Host/Endian.h"
|
||||
#include "lldb/Symbol/ClangASTContext.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "lldb/Target/Target.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
using namespace lldb_private::formatters;
|
||||
|
||||
template<bool name_entries>
|
||||
bool
|
||||
lldb_private::formatters::NSDictionarySummaryProvider (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();
|
||||
bool is_64bit = (ptr_size == 8);
|
||||
|
||||
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
|
||||
|
||||
if (!valobj_addr)
|
||||
return false;
|
||||
|
||||
uint64_t value = 0;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return false;
|
||||
|
||||
if (!strcmp(class_name,"__NSDictionaryI"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSDictionaryM"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSCFDictionary"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + (is_64bit ? 20 : 12), ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
if (is_64bit)
|
||||
value &= ~0x0f1f000000000000UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ExtractValueFromObjCExpression(valobj, "int", "count", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.Printf("%s%" PRIu64 " %s%s",
|
||||
(name_entries ? "@\"" : ""),
|
||||
value,
|
||||
(name_entries ? (value == 1 ? "entry" : "entries") : (value == 1 ? "key/value pair" : "key/value pairs")),
|
||||
(name_entries ? "\"" : ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
SyntheticChildrenFrontEnd* lldb_private::formatters::NSDictionarySyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
|
||||
{
|
||||
|
||||
lldb::ProcessSP process_sp (valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return NULL;
|
||||
ObjCLanguageRuntime *runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
|
||||
if (!runtime)
|
||||
return NULL;
|
||||
|
||||
if (!valobj_sp->IsPointerType())
|
||||
{
|
||||
Error error;
|
||||
valobj_sp = valobj_sp->AddressOf(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(*valobj_sp.get()));
|
||||
|
||||
if (!descriptor.get() || !descriptor->IsValid())
|
||||
return NULL;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return NULL;
|
||||
|
||||
if (!strcmp(class_name,"__NSDictionaryI"))
|
||||
{
|
||||
return (new NSDictionaryISyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSDictionaryM"))
|
||||
{
|
||||
return (new NSDictionaryMSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (new NSDictionaryCodeRunningSyntheticFrontEnd(valobj_sp));
|
||||
}
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::NSDictionaryCodeRunningSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get())
|
||||
{}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
uint64_t count = 0;
|
||||
if (ExtractValueFromObjCExpression(m_backend, "int", "count", count))
|
||||
return count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
StreamString valobj_expr_path;
|
||||
m_backend.GetExpressionPath(valobj_expr_path, false);
|
||||
StreamString key_fetcher_expr;
|
||||
key_fetcher_expr.Printf("(id)[(NSArray*)[%s allKeys] objectAtIndex:%zu]",valobj_expr_path.GetData(),idx);
|
||||
StreamString value_fetcher_expr;
|
||||
value_fetcher_expr.Printf("(id)[%s objectForKey:%s]",valobj_expr_path.GetData(),key_fetcher_expr.GetData());
|
||||
StreamString object_fetcher_expr;
|
||||
object_fetcher_expr.Printf("struct __lldb_autogen_nspair { id key; id value; } _lldb_valgen_item; _lldb_valgen_item.key = %s; _lldb_valgen_item.value = %s; _lldb_valgen_item;",key_fetcher_expr.GetData(),value_fetcher_expr.GetData());
|
||||
lldb::ValueObjectSP child_sp;
|
||||
m_backend.GetTargetSP()->EvaluateExpression(object_fetcher_expr.GetData(), m_backend.GetFrameSP().get(), child_sp,
|
||||
EvaluateExpressionOptions().SetKeepInMemory(true));
|
||||
if (child_sp)
|
||||
child_sp->SetName(ConstString(idx_name.GetData()));
|
||||
return child_sp;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::Update()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryCodeRunningSyntheticFrontEnd::~NSDictionaryCodeRunningSyntheticFrontEnd ()
|
||||
{}
|
||||
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::NSDictionaryISyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_data_32(NULL),
|
||||
m_data_64(NULL)
|
||||
{
|
||||
if (valobj_sp)
|
||||
Update();
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::~NSDictionaryISyntheticFrontEnd ()
|
||||
{
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
return 0;
|
||||
return (m_data_32 ? m_data_32->_used : m_data_64->_used);
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::Update()
|
||||
{
|
||||
m_children.clear();
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
m_ptr_size = 0;
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
if (m_ptr_size == 4)
|
||||
{
|
||||
m_data_32 = new DataDescriptor_32();
|
||||
process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data_64 = new DataDescriptor_64();
|
||||
process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error);
|
||||
}
|
||||
if (error.Fail())
|
||||
return false;
|
||||
m_data_ptr = data_location + m_ptr_size;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSDictionaryISyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
uint32_t num_children = CalculateNumChildren();
|
||||
|
||||
if (idx >= num_children)
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
if (m_children.empty())
|
||||
{
|
||||
// do the scan phase
|
||||
lldb::addr_t key_at_idx = 0, val_at_idx = 0;
|
||||
|
||||
uint32_t tries = 0;
|
||||
uint32_t test_idx = 0;
|
||||
|
||||
while(tries < num_children)
|
||||
{
|
||||
key_at_idx = m_data_ptr + (2*test_idx * m_ptr_size);
|
||||
val_at_idx = key_at_idx + m_ptr_size;
|
||||
ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
|
||||
if (!process_sp)
|
||||
return lldb::ValueObjectSP();
|
||||
Error error;
|
||||
key_at_idx = process_sp->ReadPointerFromMemory(key_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
val_at_idx = process_sp->ReadPointerFromMemory(val_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
test_idx++;
|
||||
|
||||
if (!key_at_idx || !val_at_idx)
|
||||
continue;
|
||||
tries++;
|
||||
|
||||
DictionaryItemDescriptor descriptor = {key_at_idx,val_at_idx,lldb::ValueObjectSP()};
|
||||
|
||||
m_children.push_back(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (idx >= m_children.size()) // should never happen
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
DictionaryItemDescriptor &dict_item = m_children[idx];
|
||||
if (!dict_item.valobj_sp)
|
||||
{
|
||||
// make the new ValueObject
|
||||
StreamString expr;
|
||||
expr.Printf("struct __lldb_autogen_nspair { id key; id value; } _lldb_valgen_item; _lldb_valgen_item.key = (id)%" PRIu64 " ; _lldb_valgen_item.value = (id)%" PRIu64 "; _lldb_valgen_item;",dict_item.key_ptr,dict_item.val_ptr);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
dict_item.valobj_sp = ValueObject::CreateValueObjectFromExpression(idx_name.GetData(), expr.GetData(), m_exe_ctx_ref);
|
||||
}
|
||||
return dict_item.valobj_sp;
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::NSDictionaryMSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
|
||||
SyntheticChildrenFrontEnd(*valobj_sp.get()),
|
||||
m_exe_ctx_ref(),
|
||||
m_ptr_size(8),
|
||||
m_data_32(NULL),
|
||||
m_data_64(NULL)
|
||||
{
|
||||
if (valobj_sp)
|
||||
Update ();
|
||||
}
|
||||
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::~NSDictionaryMSyntheticFrontEnd ()
|
||||
{
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
|
||||
{
|
||||
const char* item_name = name.GetCString();
|
||||
uint32_t idx = ExtractIndexFromString(item_name);
|
||||
if (idx < UINT32_MAX && idx >= CalculateNumChildren())
|
||||
return UINT32_MAX;
|
||||
return idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::CalculateNumChildren ()
|
||||
{
|
||||
if (!m_data_32 && !m_data_64)
|
||||
return 0;
|
||||
return (m_data_32 ? m_data_32->_used : m_data_64->_used);
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::Update()
|
||||
{
|
||||
m_children.clear();
|
||||
ValueObjectSP valobj_sp = m_backend.GetSP();
|
||||
m_ptr_size = 0;
|
||||
delete m_data_32;
|
||||
m_data_32 = NULL;
|
||||
delete m_data_64;
|
||||
m_data_64 = NULL;
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
if (valobj_sp->IsDynamic())
|
||||
valobj_sp = valobj_sp->GetStaticValue();
|
||||
if (!valobj_sp)
|
||||
return false;
|
||||
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
||||
Error error;
|
||||
if (valobj_sp->IsPointerType())
|
||||
{
|
||||
valobj_sp = valobj_sp->Dereference(error);
|
||||
if (error.Fail() || !valobj_sp)
|
||||
return false;
|
||||
}
|
||||
error.Clear();
|
||||
lldb::ProcessSP process_sp(valobj_sp->GetProcessSP());
|
||||
if (!process_sp)
|
||||
return false;
|
||||
m_ptr_size = process_sp->GetAddressByteSize();
|
||||
uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size;
|
||||
if (m_ptr_size == 4)
|
||||
{
|
||||
m_data_32 = new DataDescriptor_32();
|
||||
process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data_64 = new DataDescriptor_64();
|
||||
process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error);
|
||||
}
|
||||
if (error.Fail())
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::MightHaveChildren ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lldb::ValueObjectSP
|
||||
lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::GetChildAtIndex (size_t idx)
|
||||
{
|
||||
lldb::addr_t m_keys_ptr = (m_data_32 ? m_data_32->_keys_addr : m_data_64->_keys_addr);
|
||||
lldb::addr_t m_values_ptr = (m_data_32 ? m_data_32->_objs_addr : m_data_64->_objs_addr);
|
||||
|
||||
uint32_t num_children = CalculateNumChildren();
|
||||
|
||||
if (idx >= num_children)
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
if (m_children.empty())
|
||||
{
|
||||
// do the scan phase
|
||||
lldb::addr_t key_at_idx = 0, val_at_idx = 0;
|
||||
|
||||
uint32_t tries = 0;
|
||||
uint32_t test_idx = 0;
|
||||
|
||||
while(tries < num_children)
|
||||
{
|
||||
key_at_idx = m_keys_ptr + (test_idx * m_ptr_size);
|
||||
val_at_idx = m_values_ptr + (test_idx * m_ptr_size);;
|
||||
ProcessSP process_sp = m_exe_ctx_ref.GetProcessSP();
|
||||
if (!process_sp)
|
||||
return lldb::ValueObjectSP();
|
||||
Error error;
|
||||
key_at_idx = process_sp->ReadPointerFromMemory(key_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
val_at_idx = process_sp->ReadPointerFromMemory(val_at_idx, error);
|
||||
if (error.Fail())
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
test_idx++;
|
||||
|
||||
if (!key_at_idx || !val_at_idx)
|
||||
continue;
|
||||
tries++;
|
||||
|
||||
DictionaryItemDescriptor descriptor = {key_at_idx,val_at_idx,lldb::ValueObjectSP()};
|
||||
|
||||
m_children.push_back(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (idx >= m_children.size()) // should never happen
|
||||
return lldb::ValueObjectSP();
|
||||
|
||||
DictionaryItemDescriptor &dict_item = m_children[idx];
|
||||
if (!dict_item.valobj_sp)
|
||||
{
|
||||
// make the new ValueObject
|
||||
StreamString expr;
|
||||
expr.Printf("struct __lldb_autogen_nspair { id key; id value; } _lldb_valgen_item; _lldb_valgen_item.key = (id)%" PRIu64 " ; _lldb_valgen_item.value = (id)%" PRIu64 "; _lldb_valgen_item;",dict_item.key_ptr,dict_item.val_ptr);
|
||||
StreamString idx_name;
|
||||
idx_name.Printf("[%zu]",idx);
|
||||
dict_item.valobj_sp = ValueObject::CreateValueObjectFromExpression(idx_name.GetData(), expr.GetData(), m_exe_ctx_ref);
|
||||
}
|
||||
return dict_item.valobj_sp;
|
||||
}
|
||||
|
||||
template bool
|
||||
lldb_private::formatters::NSDictionarySummaryProvider<true> (ValueObject&, Stream&) ;
|
||||
|
||||
template bool
|
||||
lldb_private::formatters::NSDictionarySummaryProvider<false> (ValueObject&, Stream&) ;
|
|
@ -0,0 +1,118 @@
|
|||
//===-- NSSet.cpp ------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/lldb-python.h"
|
||||
|
||||
#include "lldb/DataFormatters/CXXFormatterFunctions.h"
|
||||
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
|
||||
#include "lldb/Core/DataBufferHeap.h"
|
||||
#include "lldb/Core/Error.h"
|
||||
#include "lldb/Core/Stream.h"
|
||||
#include "lldb/Core/ValueObject.h"
|
||||
#include "lldb/Core/ValueObjectConstResult.h"
|
||||
#include "lldb/Host/Endian.h"
|
||||
#include "lldb/Symbol/ClangASTContext.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "lldb/Target/Target.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
using namespace lldb_private::formatters;
|
||||
|
||||
template<bool cf_style>
|
||||
bool
|
||||
lldb_private::formatters::NSSetSummaryProvider (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();
|
||||
bool is_64bit = (ptr_size == 8);
|
||||
|
||||
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
|
||||
|
||||
if (!valobj_addr)
|
||||
return false;
|
||||
|
||||
uint64_t value = 0;
|
||||
|
||||
const char* class_name = descriptor->GetClassName().GetCString();
|
||||
|
||||
if (!class_name || !*class_name)
|
||||
return false;
|
||||
|
||||
if (!strcmp(class_name,"__NSSetI"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSSetM"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U);
|
||||
}
|
||||
else if (!strcmp(class_name,"__NSCFSet"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + (is_64bit ? 20 : 12), ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
if (is_64bit)
|
||||
value &= ~0x1fff000000000000UL;
|
||||
}
|
||||
else if (!strcmp(class_name,"NSCountedSet"))
|
||||
{
|
||||
Error error;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
value = process_sp->ReadUnsignedIntegerFromMemory(value + (is_64bit ? 20 : 12), ptr_size, 0, error);
|
||||
if (error.Fail())
|
||||
return false;
|
||||
if (is_64bit)
|
||||
value &= ~0x1fff000000000000UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ExtractValueFromObjCExpression(valobj, "int", "count", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.Printf("%s%" PRIu64 " %s%s",
|
||||
(cf_style ? "@\"" : ""),
|
||||
value,
|
||||
(cf_style ? (value == 1 ? "value" : "values") : (value == 1 ? "object" : "objects")),
|
||||
(cf_style ? "\"" : ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
template bool
|
||||
lldb_private::formatters::NSSetSummaryProvider<true> (ValueObject& valobj, Stream& stream);
|
||||
|
||||
template bool
|
||||
lldb_private::formatters::NSSetSummaryProvider<false> (ValueObject& valobj, Stream& stream);
|
|
@ -3,3 +3,6 @@ LEVEL = ../../../make
|
|||
CXX_SOURCES := main.cpp
|
||||
|
||||
include $(LEVEL)/Makefile.rules
|
||||
|
||||
CXXFLAGS += -stdlib=libstdc++ -O0
|
||||
LDFLAGS += -stdlib=libstdc++
|
||||
|
|
Loading…
Reference in New Issue