diff options
author | emaste <emaste@FreeBSD.org> | 2013-11-12 17:25:33 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2013-11-12 17:25:33 +0000 |
commit | 9dd6dd992f8bed9a53bf0653fc1eff3fb4ccd46e (patch) | |
tree | b9aa1d1064fb25a0f2313d9a7964c862c0b7b354 /contrib/llvm/tools/lldb/source/DataFormatters | |
parent | 4372cfee12af5dfa890561beb0fecc90957ba058 (diff) | |
parent | c727fe695d28799acb499e9961f11ec07d4f9fe2 (diff) | |
download | FreeBSD-src-9dd6dd992f8bed9a53bf0653fc1eff3fb4ccd46e.zip FreeBSD-src-9dd6dd992f8bed9a53bf0653fc1eff3fb4ccd46e.tar.gz |
Update LLDB to upstream r194122 snapshot
ludes minor changes relative to upstream, for compatibility with
FreeBSD's in-tree LLVM 3.3:
- Reverted LLDB r191806, restoring use of previous API.
- Reverted part of LLDB r189317, restoring previous enum names.
- Work around missing LLVM r192504, using previous registerEHFrames API
(limited functionality).
- Removed PlatformWindows header include and init/terminate calls.
Sponsored by: DARPA, AFRL
Diffstat (limited to 'contrib/llvm/tools/lldb/source/DataFormatters')
10 files changed, 1204 insertions, 150 deletions
diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/CXXFormatterFunctions.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/CXXFormatterFunctions.cpp index fba9217..e004135 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/CXXFormatterFunctions.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/CXXFormatterFunctions.cpp @@ -1003,11 +1003,11 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream& if (!has_null && has_explicit_length && !is_special) { lldb::addr_t explicit_length_offset = 2*ptr_size; - if (is_mutable and not is_inline) + if (is_mutable && !is_inline) explicit_length_offset = explicit_length_offset + ptr_size; // notInlineMutable.length; else if (is_inline) explicit_length = explicit_length + 0; // inline1.length; - else if (not is_inline and not is_mutable) + else if (!is_inline && !is_mutable) explicit_length_offset = explicit_length_offset + ptr_size; // notInlineImmutable1.length; else explicit_length_offset = 0; @@ -1039,7 +1039,7 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream& location = process_sp->ReadPointerFromMemory(location, error); if (error.Fail()) return false; - if (has_explicit_length and is_unicode) + if (has_explicit_length && is_unicode) { ReadUTFBufferAndDumpToStreamOptions<UTF16> options; options.SetConversionFunction(ConvertUTF16toUTF8); @@ -1237,6 +1237,7 @@ lldb_private::formatters::GetOSXEpoch () static time_t epoch = 0; if (!epoch) { +#ifndef _WIN32 tzset(); tm tm_epoch; tm_epoch.tm_sec = 0; @@ -1249,6 +1250,7 @@ lldb_private::formatters::GetOSXEpoch () tm_epoch.tm_gmtoff = 0; tm_epoch.tm_zone = NULL; epoch = timegm(&tm_epoch); +#endif } return epoch; } diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/DataVisualization.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/DataVisualization.cpp index c1ef359..48d3517 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/DataVisualization.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/DataVisualization.cpp @@ -40,67 +40,26 @@ DataVisualization::GetCurrentRevision () return GetFormatManager().GetCurrentRevision(); } -lldb::TypeFormatImplSP -DataVisualization::ValueFormats::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) -{ - lldb::TypeFormatImplSP entry; - GetFormatManager().GetValueNavigator().Get(valobj, entry, use_dynamic); - return entry; -} - -lldb::TypeFormatImplSP -DataVisualization::ValueFormats::GetFormat (const ConstString &type) -{ - lldb::TypeFormatImplSP entry; - GetFormatManager().GetValueNavigator().Get(type, entry); - return entry; -} - -void -DataVisualization::ValueFormats::Add (const ConstString &type, const lldb::TypeFormatImplSP &entry) -{ - GetFormatManager().GetValueNavigator().Add(FormatManager::GetValidTypeName(type),entry); -} - bool -DataVisualization::ValueFormats::Delete (const ConstString &type) +DataVisualization::ShouldPrintAsOneLiner (ValueObject& valobj) { - return GetFormatManager().GetValueNavigator().Delete(type); + return GetFormatManager().ShouldPrintAsOneLiner(valobj); } -void -DataVisualization::ValueFormats::Clear () -{ - GetFormatManager().GetValueNavigator().Clear(); -} - -void -DataVisualization::ValueFormats::LoopThrough (TypeFormatImpl::ValueCallback callback, void* callback_baton) -{ - GetFormatManager().GetValueNavigator().LoopThrough(callback, callback_baton); -} - -size_t -DataVisualization::ValueFormats::GetCount () -{ - return GetFormatManager().GetValueNavigator().GetCount(); -} - -lldb::TypeNameSpecifierImplSP -DataVisualization::ValueFormats::GetTypeNameSpecifierForFormatAtIndex (size_t index) +lldb::TypeFormatImplSP +DataVisualization::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) { - return GetFormatManager().GetValueNavigator().GetTypeNameSpecifierAtIndex(index); + return GetFormatManager().GetFormat(valobj, use_dynamic); } lldb::TypeFormatImplSP -DataVisualization::ValueFormats::GetFormatAtIndex (size_t index) +DataVisualization::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) { - return GetFormatManager().GetValueNavigator().GetAtIndex(index); + return GetFormatManager().GetFormatForType(type_sp); } lldb::TypeSummaryImplSP -DataVisualization::GetSummaryFormat (ValueObject& valobj, - lldb::DynamicValueType use_dynamic) +DataVisualization::GetSummaryFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) { return GetFormatManager().GetSummaryFormat(valobj, use_dynamic); } diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/FormatCache.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/FormatCache.cpp index af7b1c3..3721f18 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/FormatCache.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/FormatCache.cpp @@ -22,33 +22,55 @@ using namespace lldb; using namespace lldb_private; FormatCache::Entry::Entry () : +m_format_cached(false), m_summary_cached(false), m_synthetic_cached(false), +m_format_sp(), m_summary_sp(), m_synthetic_sp() {} +FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) : +m_summary_cached(false), +m_synthetic_cached(false), +m_summary_sp(), +m_synthetic_sp() +{ + SetFormat (format_sp); +} + FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) : +m_format_cached(false), m_synthetic_cached(false), +m_format_sp(), m_synthetic_sp() { SetSummary (summary_sp); } FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) : +m_format_cached(false), m_summary_cached(false), +m_format_sp(), m_summary_sp() { SetSynthetic (synthetic_sp); } -FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp,lldb::SyntheticChildrenSP synthetic_sp) +FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp) { + SetFormat (format_sp); SetSummary (summary_sp); SetSynthetic (synthetic_sp); } bool +FormatCache::Entry::IsFormatCached () +{ + return m_format_cached; +} + +bool FormatCache::Entry::IsSummaryCached () { return m_summary_cached; @@ -60,6 +82,12 @@ FormatCache::Entry::IsSyntheticCached () return m_synthetic_cached; } +lldb::TypeFormatImplSP +FormatCache::Entry::GetFormat () +{ + return m_format_sp; +} + lldb::TypeSummaryImplSP FormatCache::Entry::GetSummary () { @@ -73,6 +101,13 @@ FormatCache::Entry::GetSynthetic () } void +FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp) +{ + m_format_cached = true; + m_format_sp = format_sp; +} + +void FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp) { m_summary_cached = true; @@ -107,6 +142,26 @@ FormatCache::GetEntry (const ConstString& type) } bool +FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) +{ + Mutex::Locker lock(m_mutex); + auto entry = GetEntry(type); + if (entry.IsSummaryCached()) + { +#ifdef LLDB_CONFIGURATION_DEBUG + m_cache_hits++; +#endif + format_sp = entry.GetFormat(); + return true; + } +#ifdef LLDB_CONFIGURATION_DEBUG + m_cache_misses++; +#endif + format_sp.reset(); + return false; +} + +bool FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) { Mutex::Locker lock(m_mutex); @@ -147,6 +202,13 @@ FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& sy } void +FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) +{ + Mutex::Locker lock(m_mutex); + GetEntry(type).SetFormat(format_sp); +} + +void FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) { Mutex::Locker lock(m_mutex); diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/FormatManager.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/FormatManager.cpp index eeae8bc..b4c4628 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/FormatManager.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/FormatManager.cpp @@ -163,6 +163,32 @@ FormatManager::GetFormatAsCString (Format format) return NULL; } +lldb::TypeFormatImplSP +FormatManager::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) +{ + if (!type_sp) + return lldb::TypeFormatImplSP(); + lldb::TypeFormatImplSP format_chosen_sp; + uint32_t num_categories = m_categories_map.GetCount(); + lldb::TypeCategoryImplSP category_sp; + uint32_t prio_category = UINT32_MAX; + for (uint32_t category_id = 0; + category_id < num_categories; + category_id++) + { + category_sp = GetCategoryAtIndex(category_id); + if (category_sp->IsEnabled() == false) + continue; + lldb::TypeFormatImplSP format_current_sp = category_sp->GetFormatForType(type_sp); + if (format_current_sp && (format_chosen_sp.get() == NULL || (prio_category > category_sp->GetEnabledPosition()))) + { + prio_category = category_sp->GetEnabledPosition(); + format_chosen_sp = format_current_sp; + } + } + return format_chosen_sp; +} + lldb::TypeSummaryImplSP FormatManager::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp) { @@ -305,6 +331,66 @@ FormatManager::GetSingleItemFormat(lldb::Format vector_format) } } +bool +FormatManager::ShouldPrintAsOneLiner (ValueObject& valobj) +{ + // if settings say no oneline whatsoever + if (valobj.GetTargetSP().get() && valobj.GetTargetSP()->GetDebugger().GetAutoOneLineSummaries() == false) + return false; // then don't oneline + + // if this object has a summary, don't try to do anything special to it + // if the user wants one-liner, they can ask for it in summary :) + if (valobj.GetSummaryFormat().get() != nullptr) + return false; + + // no children, no party + if (valobj.GetNumChildren() == 0) + return false; + + size_t total_children_name_len = 0; + + for (size_t idx = 0; + idx < valobj.GetNumChildren(); + idx++) + { + ValueObjectSP child_sp(valobj.GetChildAtIndex(idx, true)); + // something is wrong here - bail out + if (!child_sp) + return false; + // if we decided to define synthetic children for a type, we probably care enough + // to show them, but avoid nesting children in children + if (child_sp->GetSyntheticChildren().get() != nullptr) + return false; + + total_children_name_len += child_sp->GetName().GetLength(); + + // 50 itself is a "randomly" chosen number - the idea is that + // overly long structs should not get this treatment + // FIXME: maybe make this a user-tweakable setting? + if (total_children_name_len > 50) + return false; + + // if a summary is there.. + if (child_sp->GetSummaryFormat()) + { + // and it wants children, then bail out + if (child_sp->GetSummaryFormat()->DoesPrintChildren()) + return false; + } + + // if this child has children.. + if (child_sp->GetNumChildren()) + { + // ...and no summary... + // (if it had a summary and the summary wanted children, we would have bailed out anyway + // so this only makes us bail out if this has no summary and we would then print children) + if (!child_sp->GetSummaryFormat()) + return false; // then bail out + } + } + return true; +} + ConstString FormatManager::GetValidTypeName (const ConstString& type) { @@ -334,6 +420,62 @@ GetTypeForCache (ValueObject& valobj, return ConstString(); } +static lldb::TypeFormatImplSP +GetHardcodedFormat (ValueObject& valobj, + lldb::DynamicValueType use_dynamic) +{ + return lldb::TypeFormatImplSP(); +} + +lldb::TypeFormatImplSP +FormatManager::GetFormat (ValueObject& valobj, + lldb::DynamicValueType use_dynamic) +{ + TypeFormatImplSP retval; + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); + ConstString valobj_type(GetTypeForCache(valobj, use_dynamic)); + if (valobj_type) + { + if (log) + log->Printf("\n\n[FormatManager::GetFormat] Looking into cache for type %s", valobj_type.AsCString("<invalid>")); + if (m_format_cache.GetFormat(valobj_type,retval)) + { + if (log) + { + log->Printf("[FormatManager::GetFormat] Cache search success. Returning."); + if (log->GetDebug()) + log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + } + return retval; + } + if (log) + log->Printf("[FormatManager::GetFormat] Cache search failed. Going normal route"); + } + retval = m_categories_map.GetFormat(valobj, use_dynamic); + if (!retval) + { + if (log) + log->Printf("[FormatManager::GetFormat] Search failed. Giving hardcoded a chance."); + retval = GetHardcodedFormat(valobj, use_dynamic); + } + if (valobj_type) + { + if (log) + log->Printf("[FormatManager::GetFormat] Caching %p for type %s",retval.get(),valobj_type.AsCString("<invalid>")); + m_format_cache.SetFormat(valobj_type,retval); + } + if (log && log->GetDebug()) + log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + return retval; +} + +static lldb::TypeSummaryImplSP +GetHardcodedSummaryFormat (ValueObject& valobj, + lldb::DynamicValueType use_dynamic) +{ + return lldb::TypeSummaryImplSP(); +} + lldb::TypeSummaryImplSP FormatManager::GetSummaryFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) @@ -359,6 +501,12 @@ FormatManager::GetSummaryFormat (ValueObject& valobj, log->Printf("[FormatManager::GetSummaryFormat] Cache search failed. Going normal route"); } retval = m_categories_map.GetSummaryFormat(valobj, use_dynamic); + if (!retval) + { + if (log) + log->Printf("[FormatManager::GetSummaryFormat] Search failed. Giving hardcoded a chance."); + retval = GetHardcodedSummaryFormat(valobj, use_dynamic); + } if (valobj_type) { if (log) @@ -371,6 +519,13 @@ FormatManager::GetSummaryFormat (ValueObject& valobj, } #ifndef LLDB_DISABLE_PYTHON +static lldb::SyntheticChildrenSP +GetHardcodedSyntheticChildren (ValueObject& valobj, + lldb::DynamicValueType use_dynamic) +{ + return lldb::SyntheticChildrenSP(); +} + lldb::SyntheticChildrenSP FormatManager::GetSyntheticChildren (ValueObject& valobj, lldb::DynamicValueType use_dynamic) @@ -396,6 +551,12 @@ FormatManager::GetSyntheticChildren (ValueObject& valobj, log->Printf("[FormatManager::GetSyntheticChildren] Cache search failed. Going normal route"); } retval = m_categories_map.GetSyntheticChildren(valobj, use_dynamic); + if (!retval) + { + if (log) + log->Printf("[FormatManager::GetSyntheticChildren] Search failed. Giving hardcoded a chance."); + retval = GetHardcodedSyntheticChildren(valobj, use_dynamic); + } if (valobj_type) { if (log) @@ -410,7 +571,6 @@ FormatManager::GetSyntheticChildren (ValueObject& valobj, FormatManager::FormatManager() : m_format_cache(), - m_value_nav("format",this), m_named_summaries_map(this), m_last_revision(0), m_categories_map(this), @@ -442,6 +602,22 @@ FormatManager::FormatManager() : } static void +AddFormat (TypeCategoryImpl::SharedPointer category_sp, + lldb::Format format, + ConstString type_name, + TypeFormatImpl::Flags flags, + bool regex = false) +{ + lldb::TypeFormatImplSP format_sp(new TypeFormatImpl(format, flags)); + + if (regex) + category_sp->GetRegexValueNavigator()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),format_sp); + else + category_sp->GetValueNavigator()->Add(type_name, format_sp); +} + + +static void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, const char* string, ConstString type_name, @@ -632,7 +808,8 @@ FormatManager::LoadLibcxxFormatters() AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator, "libc++ std::set synthetic children", ConstString("^std::__1::set<.+> >(( )?&)?$"), stl_synth_flags, true); AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator, "libc++ std::multiset synthetic children", ConstString("^std::__1::multiset<.+> >(( )?&)?$"), stl_synth_flags, true); AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator, "libc++ std::multimap synthetic children", ConstString("^std::__1::multimap<.+> >(( )?&)?$"), stl_synth_flags, true); - + AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEndCreator, "libc++ std::unordered containers synthetic children", ConstString("^(std::__1::)unordered_(multi)?(map|set)<.+> >$"), stl_synth_flags, true); + libcxx_category_sp->GetRegexSyntheticNavigator()->Add(RegularExpressionSP(new RegularExpression("^(std::__1::)deque<.+>(( )?&)?$")), SyntheticChildrenSP(new ScriptedSyntheticChildren(stl_synth_flags, "lldb.formatters.cpp.libcxx.stddeque_SynthProvider"))); @@ -650,6 +827,7 @@ FormatManager::LoadLibcxxFormatters() AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::set summary provider", ConstString("^std::__1::set<.+>(( )?&)?$"), stl_summary_flags, true); AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::multiset summary provider", ConstString("^std::__1::multiset<.+>(( )?&)?$"), stl_summary_flags, true); AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::multimap summary provider", ConstString("^std::__1::multimap<.+>(( )?&)?$"), stl_summary_flags, true); + AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::unordered containers summary provider", ConstString("^(std::__1::)unordered_(multi)?(map|set)<.+> >$"), stl_summary_flags, true); stl_summary_flags.SetSkipPointers(true); AddStringSummary(libcxx_category_sp, "{${var.__ptr_%S}} (strong=${var.count} weak=${var.weak_count})}", ConstString("^std::__1::shared_ptr<.+>(( )?&)?$"), stl_summary_flags, true); @@ -694,7 +872,7 @@ FormatManager::LoadSystemFormatters() sys_category_sp->GetSummaryNavigator()->Add(ConstString("char *"), string_format); sys_category_sp->GetSummaryNavigator()->Add(ConstString("unsigned char *"), string_format); sys_category_sp->GetRegexSummaryNavigator()->Add(any_size_char_arr, string_array_format); - + lldb::TypeSummaryImplSP ostype_summary(new StringSummaryFormat(TypeSummaryImpl::Flags().SetCascades(false) .SetSkipPointers(true) .SetSkipReferences(true) @@ -731,6 +909,11 @@ FormatManager::LoadSystemFormatters() AddCXXSummary(sys_category_sp, lldb_private::formatters::Char16SummaryProvider, "unichar summary provider", ConstString("unichar"), widechar_flags); + TypeFormatImpl::Flags fourchar_flags; + fourchar_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences(true); + + AddFormat(sys_category_sp, lldb::eFormatOSType, ConstString("FourCharCode"), fourchar_flags); + #endif } @@ -879,22 +1062,22 @@ FormatManager::LoadObjCFormatters() AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSArraySummaryProvider, "NSArray summary provider", ConstString("__NSArrayI"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSArraySummaryProvider, "NSArray summary provider", ConstString("__NSArrayM"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSArraySummaryProvider, "NSArray summary provider", ConstString("__NSCFArray"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSArraySummaryProvider, "NSArray summary provider", ConstString("CFArrayRef"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSArraySummaryProvider, "NSArray summary provider", ConstString("CFMutableArrayRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSArraySummaryProvider, "NSArray summary provider", ConstString("CFArrayRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSArraySummaryProvider, "NSArray summary provider", ConstString("CFMutableArrayRef"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<false>, "NSDictionary summary provider", ConstString("NSDictionary"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<false>, "NSDictionary summary provider", ConstString("NSMutableDictionary"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<false>, "NSDictionary summary provider", ConstString("__NSCFDictionary"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<false>, "NSDictionary summary provider", ConstString("__NSDictionaryI"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<false>, "NSDictionary summary provider", ConstString("__NSDictionaryM"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<true>, "NSDictionary summary provider", ConstString("CFDictionaryRef"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<true>, "NSDictionary summary provider", ConstString("CFMutableDictionaryRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<true>, "NSDictionary summary provider", ConstString("CFDictionaryRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSDictionarySummaryProvider<true>, "NSDictionary summary provider", ConstString("CFMutableDictionaryRef"), 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<false>, "NSMutableSet summary", ConstString("NSMutableSet"), 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(corefoundation_category_sp, lldb_private::formatters::NSSetSummaryProvider<true>, "CFSetRef summary", ConstString("CFSetRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSSetSummaryProvider<true>, "CFMutableSetRef summary", ConstString("CFMutableSetRef"), appkit_flags); + AddCXXSummary(corefoundation_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); @@ -911,16 +1094,16 @@ FormatManager::LoadObjCFormatters() AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("__NSArrayI"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("NSArray"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("NSMutableArray"), ScriptedSyntheticChildren::Flags()); - AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("__NSCFArray"), ScriptedSyntheticChildren::Flags()); - AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("CFMutableArrayRef"), ScriptedSyntheticChildren::Flags()); - AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("CFArrayRef"), ScriptedSyntheticChildren::Flags()); + AddCXXSynthetic(corefoundation_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("__NSCFArray"), ScriptedSyntheticChildren::Flags()); + AddCXXSynthetic(corefoundation_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("CFMutableArrayRef"), ScriptedSyntheticChildren::Flags()); + AddCXXSynthetic(corefoundation_category_sp, lldb_private::formatters::NSArraySyntheticFrontEndCreator, "NSArray synthetic children", ConstString("CFArrayRef"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("__NSDictionaryM"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("__NSDictionaryI"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("NSDictionary"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("NSMutableDictionary"), ScriptedSyntheticChildren::Flags()); - AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("CFDictionaryRef"), ScriptedSyntheticChildren::Flags()); - AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("CFMutableDictionaryRef"), ScriptedSyntheticChildren::Flags()); + AddCXXSynthetic(corefoundation_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("CFDictionaryRef"), ScriptedSyntheticChildren::Flags()); + AddCXXSynthetic(corefoundation_category_sp, lldb_private::formatters::NSDictionarySyntheticFrontEndCreator, "NSDictionary synthetic children", ConstString("CFMutableDictionaryRef"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator, "NSSet synthetic children", ConstString("NSSet"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator, "__NSSetI synthetic children", ConstString("__NSSetI"), ScriptedSyntheticChildren::Flags()); @@ -930,22 +1113,22 @@ FormatManager::LoadObjCFormatters() AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator, "__NSOrderedSetI synthetic children", ConstString("__NSOrderedSetI"), ScriptedSyntheticChildren::Flags()); AddCXXSynthetic(appkit_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator, "__NSOrderedSetM synthetic children", ConstString("__NSOrderedSetM"), ScriptedSyntheticChildren::Flags()); - AddCXXSummary(appkit_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("CFBagRef"), appkit_flags); - AddCXXSummary(appkit_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("__CFBag"), appkit_flags); - 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); + AddCXXSummary(corefoundation_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("CFBagRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("__CFBag"), appkit_flags); + AddCXXSummary(corefoundation_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("const struct __CFBag"), appkit_flags); + AddCXXSummary(corefoundation_category_sp,lldb_private::formatters::CFBagSummaryProvider, "CFBag summary provider", ConstString("CFMutableBagRef"), 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(corefoundation_category_sp,lldb_private::formatters::CFBinaryHeapSummaryProvider, "CFBinaryHeap summary provider", ConstString("CFBinaryHeapRef"), appkit_flags); + AddCXXSummary(corefoundation_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); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("CFMutableStringRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("CFStringRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("CFMutableStringRef"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSMutableString"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("__NSCFConstantString"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("__NSCFString"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSCFConstantString"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSCFString"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("__NSCFConstantString"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("__NSCFString"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSCFConstantString"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSCFString"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSPathStore2"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSAttributedStringSummaryProvider, "NSAttributedString summary provider", ConstString("NSAttributedString"), appkit_flags); @@ -957,9 +1140,9 @@ FormatManager::LoadObjCFormatters() AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>, "NSData summary provider", ConstString("NSData"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>, "NSData summary provider", ConstString("NSConcreteData"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>, "NSData summary provider", ConstString("NSConcreteMutableData"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>, "NSData summary provider", ConstString("__NSCFData"), appkit_flags); - 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); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>, "NSData summary provider", ConstString("__NSCFData"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSDataSummaryProvider<true>, "NSData summary provider", ConstString("CFDataRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSDataSummaryProvider<true>, "NSData summary provider", ConstString("CFMutableDataRef"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSMachPortSummaryProvider, "NSMachPort summary provider", ConstString("NSMachPort"), appkit_flags); @@ -970,10 +1153,11 @@ FormatManager::LoadObjCFormatters() AddStringSummary(appkit_category_sp,"name:${var.name%S} reason:${var.reason%S}",ConstString("NSException"),appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSNumber"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("__NSCFBoolean"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("__NSCFNumber"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSCFBoolean"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSCFNumber"), appkit_flags); + AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "CFNumberRef summary provider", ConstString("CFNumberRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("__NSCFBoolean"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("__NSCFNumber"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSCFBoolean"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSCFNumber"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::RuntimeSpecificDescriptionSummaryProvider, "NSDecimalNumber summary provider", ConstString("NSDecimalNumber"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::RuntimeSpecificDescriptionSummaryProvider, "NSHost summary provider", ConstString("NSHost"), appkit_flags); @@ -981,7 +1165,7 @@ FormatManager::LoadObjCFormatters() AddCXXSummary(appkit_category_sp, lldb_private::formatters::RuntimeSpecificDescriptionSummaryProvider, "NSValue summary provider", ConstString("NSValue"), 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); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSURLSummaryProvider, "NSURL summary provider", ConstString("CFURLRef"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDateSummaryProvider, "NSDate summary provider", ConstString("NSDate"), appkit_flags); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDateSummaryProvider, "NSDate summary provider", ConstString("__NSDate"), appkit_flags); @@ -995,7 +1179,7 @@ FormatManager::LoadObjCFormatters() // CFAbsoluteTime is actually a double rather than a pointer to an object // we do not care about the numeric value, since it is probably meaningless to users appkit_flags.SetDontShowValue(true); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::CFAbsoluteTimeSummaryProvider, "CFAbsoluteTime summary provider", ConstString("CFAbsoluteTime"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::CFAbsoluteTimeSummaryProvider, "CFAbsoluteTime summary provider", ConstString("CFAbsoluteTime"), appkit_flags); appkit_flags.SetDontShowValue(false); AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSIndexSetSummaryProvider, "NSIndexSet summary provider", ConstString("NSIndexSet"), appkit_flags); @@ -1006,10 +1190,10 @@ FormatManager::LoadObjCFormatters() ConstString("CFGregorianDate"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("CFBitVectorRef"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("CFMutableBitVectorRef"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("__CFBitVector"), appkit_flags); - AddCXXSummary(appkit_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("__CFMutableBitVector"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("CFBitVectorRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("CFMutableBitVectorRef"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("__CFBitVector"), appkit_flags); + AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::CFBitVectorSummaryProvider, "CFBitVector summary provider", ConstString("__CFMutableBitVector"), appkit_flags); #endif // LLDB_DISABLE_PYTHON TypeCategoryImpl::SharedPointer vectors_category_sp = GetCategory(m_vectortypes_category_name); diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/LibCxxUnorderedMap.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/LibCxxUnorderedMap.cpp new file mode 100644 index 0000000..b73d3bf --- /dev/null +++ b/contrib/llvm/tools/lldb/source/DataFormatters/LibCxxUnorderedMap.cpp @@ -0,0 +1,135 @@ +//===-- LibCxxUnorderedMap.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 "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; + +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::LibcxxStdUnorderedMapSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) : +SyntheticChildrenFrontEnd(*valobj_sp.get()), +m_tree(NULL), +m_num_elements(0), +m_next_element(nullptr), +m_children(), +m_elements_cache() +{ + if (valobj_sp) + Update(); +} + +size_t +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::CalculateNumChildren () +{ + if (m_num_elements != UINT32_MAX) + return m_num_elements; + return 0; +} + +lldb::ValueObjectSP +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::GetChildAtIndex (size_t idx) +{ + if (idx >= CalculateNumChildren()) + return lldb::ValueObjectSP(); + if (m_tree == NULL) + return lldb::ValueObjectSP(); + + auto cached = m_children.find(idx); + if (cached != m_children.end()) + return cached->second; + + while (idx >= m_elements_cache.size()) + { + if (m_next_element == nullptr) + return lldb::ValueObjectSP(); + + Error error; + ValueObjectSP node_sp = m_next_element->Dereference(error); + if (!node_sp || error.Fail()) + return lldb::ValueObjectSP(); + + ValueObjectSP value_sp = node_sp->GetChildMemberWithName(ConstString("__value_"), true); + ValueObjectSP hash_sp = node_sp->GetChildMemberWithName(ConstString("__hash_"), true); + if (!hash_sp || !value_sp) + return lldb::ValueObjectSP(); + m_elements_cache.push_back({value_sp.get(),hash_sp->GetValueAsUnsigned(0)}); + m_next_element = node_sp->GetChildMemberWithName(ConstString("__next_"),true).get(); + if (!m_next_element || m_next_element->GetValueAsUnsigned(0) == 0) + m_next_element = nullptr; + } + + std::pair<ValueObject*, uint64_t> val_hash = m_elements_cache[idx]; + if (!val_hash.first) + return lldb::ValueObjectSP(); + StreamString stream; + stream.Printf("[%zu]",idx); + DataExtractor data; + val_hash.first->GetData(data); + ExecutionContext exe_ctx = val_hash.first->GetExecutionContextRef().Lock(); + return val_hash.first->CreateValueObjectFromData(stream.GetData(), + data, + exe_ctx, + val_hash.first->GetClangType()); +} + +bool +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::Update() +{ + m_num_elements = UINT32_MAX; + m_next_element = nullptr; + m_elements_cache.clear(); + m_children.clear(); + ValueObjectSP table_sp = m_backend.GetChildMemberWithName(ConstString("__table_"), true); + if (!table_sp) + return false; + ValueObjectSP num_elements_sp = table_sp->GetChildAtNamePath({ConstString("__p2_"),ConstString("__first_")}); + if (!num_elements_sp) + return false; + m_num_elements = num_elements_sp->GetValueAsUnsigned(0); + m_tree = table_sp->GetChildAtNamePath({ConstString("__p1_"),ConstString("__first_"),ConstString("__next_")}).get(); + if (m_num_elements > 0) + m_next_element = table_sp->GetChildAtNamePath({ConstString("__p1_"),ConstString("__first_"),ConstString("__next_")}).get(); + return false; +} + +bool +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::MightHaveChildren () +{ + return true; +} + +size_t +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name) +{ + return ExtractIndexFromString(name.GetCString()); +} + +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::~LibcxxStdUnorderedMapSyntheticFrontEnd () +{} + +SyntheticChildrenFrontEnd* +lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp) +{ + if (!valobj_sp) + return NULL; + return (new LibcxxStdUnorderedMapSyntheticFrontEnd(valobj_sp)); +} diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategory.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategory.cpp index c887be5..636000b 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategory.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategory.cpp @@ -21,6 +21,8 @@ using namespace lldb_private; TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener* clist, ConstString name) : +m_value_nav(new ValueNavigator("format",clist)), +m_regex_value_nav(new RegexValueNavigator("regex-format",clist)), m_summary_nav(new SummaryNavigator("summary",clist)), m_regex_summary_nav(new RegexSummaryNavigator("regex-summary",clist)), m_filter_nav(new FilterNavigator("filter",clist)), @@ -37,6 +39,22 @@ m_name(name) bool TypeCategoryImpl::Get (ValueObject& valobj, + lldb::TypeFormatImplSP& entry, + lldb::DynamicValueType use_dynamic, + uint32_t* reason) +{ + if (!IsEnabled()) + return false; + if (GetValueNavigator()->Get(valobj, entry, use_dynamic, reason)) + return true; + bool regex = GetRegexValueNavigator()->Get(valobj, entry, use_dynamic, reason); + if (regex && reason) + *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + return regex; +} + +bool +TypeCategoryImpl::Get (ValueObject& valobj, lldb::TypeSummaryImplSP& entry, lldb::DynamicValueType use_dynamic, uint32_t* reason) @@ -119,14 +137,21 @@ TypeCategoryImpl::Get(ValueObject& valobj, void TypeCategoryImpl::Clear (FormatCategoryItems items) { + if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) + m_value_nav->Clear(); + if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) + m_regex_value_nav->Clear(); + if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) m_summary_nav->Clear(); if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) m_regex_summary_nav->Clear(); + if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) m_filter_nav->Clear(); if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) m_regex_filter_nav->Clear(); + #ifndef LLDB_DISABLE_PYTHON if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) m_synth_nav->Clear(); @@ -140,14 +165,22 @@ TypeCategoryImpl::Delete (ConstString name, FormatCategoryItems items) { bool success = false; + + if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) + success = m_value_nav->Delete(name) || success; + if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) + success = m_regex_value_nav->Delete(name) || success; + if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) success = m_summary_nav->Delete(name) || success; if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) success = m_regex_summary_nav->Delete(name) || success; + if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) success = m_filter_nav->Delete(name) || success; if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) success = m_regex_filter_nav->Delete(name) || success; + #ifndef LLDB_DISABLE_PYTHON if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) success = m_synth_nav->Delete(name) || success; @@ -161,14 +194,22 @@ uint32_t TypeCategoryImpl::GetCount (FormatCategoryItems items) { uint32_t count = 0; + + if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) + count += m_value_nav->GetCount(); + if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) + count += m_regex_value_nav->GetCount(); + if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) count += m_summary_nav->GetCount(); if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) count += m_regex_summary_nav->GetCount(); + if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) count += m_filter_nav->GetCount(); if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) count += m_regex_filter_nav->GetCount(); + #ifndef LLDB_DISABLE_PYTHON if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) count += m_synth_nav->GetCount(); @@ -188,15 +229,39 @@ TypeCategoryImpl::AnyMatches(ConstString type_name, if (!IsEnabled() && only_enabled) return false; - lldb::TypeSummaryImplSP summary; - TypeFilterImpl::SharedPointer filter; + lldb::TypeFormatImplSP format_sp; + lldb::TypeSummaryImplSP summary_sp; + TypeFilterImpl::SharedPointer filter_sp; #ifndef LLDB_DISABLE_PYTHON - ScriptedSyntheticChildren::SharedPointer synth; + ScriptedSyntheticChildren::SharedPointer synth_sp; #endif + if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue ) + { + if (m_value_nav->Get(type_name, format_sp)) + { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemValue; + return true; + } + } + if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue ) + { + if (m_regex_value_nav->Get(type_name, format_sp)) + { + if (matching_category) + *matching_category = m_name.GetCString(); + if (matching_type) + *matching_type = eFormatCategoryItemRegexValue; + return true; + } + } + if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary ) { - if (m_summary_nav->Get(type_name, summary)) + if (m_summary_nav->Get(type_name, summary_sp)) { if (matching_category) *matching_category = m_name.GetCString(); @@ -207,7 +272,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name, } if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary ) { - if (m_regex_summary_nav->Get(type_name, summary)) + if (m_regex_summary_nav->Get(type_name, summary_sp)) { if (matching_category) *matching_category = m_name.GetCString(); @@ -216,9 +281,10 @@ TypeCategoryImpl::AnyMatches(ConstString type_name, return true; } } + if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter ) { - if (m_filter_nav->Get(type_name, filter)) + if (m_filter_nav->Get(type_name, filter_sp)) { if (matching_category) *matching_category = m_name.GetCString(); @@ -229,7 +295,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name, } if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter ) { - if (m_regex_filter_nav->Get(type_name, filter)) + if (m_regex_filter_nav->Get(type_name, filter_sp)) { if (matching_category) *matching_category = m_name.GetCString(); @@ -238,10 +304,11 @@ TypeCategoryImpl::AnyMatches(ConstString type_name, return true; } } + #ifndef LLDB_DISABLE_PYTHON if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth ) { - if (m_synth_nav->Get(type_name, synth)) + if (m_synth_nav->Get(type_name, synth_sp)) { if (matching_category) *matching_category = m_name.GetCString(); @@ -252,7 +319,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name, } if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth ) { - if (m_regex_synth_nav->Get(type_name, synth)) + if (m_regex_synth_nav->Get(type_name, synth_sp)) { if (matching_category) *matching_category = m_name.GetCString(); @@ -265,6 +332,22 @@ TypeCategoryImpl::AnyMatches(ConstString type_name, return false; } +TypeCategoryImpl::ValueNavigator::MapValueType +TypeCategoryImpl::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) +{ + ValueNavigator::MapValueType retval; + + if (type_sp) + { + if (type_sp->IsRegex()) + m_regex_value_nav->GetExact(ConstString(type_sp->GetName()),retval); + else + m_value_nav->GetExact(ConstString(type_sp->GetName()),retval); + } + + return retval; +} + TypeCategoryImpl::SummaryNavigator::MapValueType TypeCategoryImpl::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp) { @@ -324,6 +407,15 @@ TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex (size_t index) return m_regex_summary_nav->GetTypeNameSpecifierAtIndex(index-m_summary_nav->GetCount()); } +TypeCategoryImpl::ValueNavigator::MapValueType +TypeCategoryImpl::GetFormatAtIndex (size_t index) +{ + if (index < m_value_nav->GetCount()) + return m_value_nav->GetAtIndex(index); + else + return m_regex_value_nav->GetAtIndex(index-m_value_nav->GetCount()); +} + TypeCategoryImpl::SummaryNavigator::MapValueType TypeCategoryImpl::GetSummaryAtIndex (size_t index) { @@ -343,6 +435,15 @@ TypeCategoryImpl::GetFilterAtIndex (size_t index) } lldb::TypeNameSpecifierImplSP +TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex (size_t index) +{ + if (index < m_value_nav->GetCount()) + return m_value_nav->GetTypeNameSpecifierAtIndex(index); + else + return m_regex_value_nav->GetTypeNameSpecifierAtIndex(index-m_value_nav->GetCount()); +} + +lldb::TypeNameSpecifierImplSP TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex (size_t index) { if (index < m_filter_nav->GetCount()) diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategoryMap.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategoryMap.cpp index 4b7222a..6212588 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/TypeCategoryMap.cpp @@ -176,6 +176,32 @@ TypeCategoryMap::AnyMatches (ConstString type_name, return false; } +lldb::TypeFormatImplSP +TypeCategoryMap::GetFormat (ValueObject& valobj, + lldb::DynamicValueType use_dynamic) +{ + Mutex::Locker locker(m_map_mutex); + + uint32_t reason_why; + ActiveCategoriesIterator begin, end = m_active_categories.end(); + + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); + + for (begin = m_active_categories.begin(); begin != end; begin++) + { + lldb::TypeCategoryImplSP category_sp = *begin; + lldb::TypeFormatImplSP current_format; + if (log) + log->Printf("\n[TypeCategoryMap::GetFormat] Trying to use category %s", category_sp->GetName()); + if (!category_sp->Get(valobj, current_format, use_dynamic, &reason_why)) + continue; + return current_format; + } + if (log) + log->Printf("[TypeCategoryMap::GetFormat] nothing found - returning empty SP"); + return lldb::TypeFormatImplSP(); +} + lldb::TypeSummaryImplSP TypeCategoryMap::GetSummaryFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/TypeFormat.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/TypeFormat.cpp index 279704f..7f18dde 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/TypeFormat.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/TypeFormat.cpp @@ -42,7 +42,7 @@ std::string TypeFormatImpl::GetDescription() { StreamString sstr; - sstr.Printf ("%s%s%s%s\n", + sstr.Printf ("%s%s%s%s", FormatManager::GetFormatAsCString (GetFormat()), Cascades() ? "" : " (not cascading)", SkipsPointers() ? " (skip pointers)" : "", diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/TypeSummary.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/TypeSummary.cpp index 8c4d3f7..4c75b4b 100644 --- a/contrib/llvm/tools/lldb/source/DataFormatters/TypeSummary.cpp +++ b/contrib/llvm/tools/lldb/source/DataFormatters/TypeSummary.cpp @@ -23,6 +23,7 @@ #include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" #include "lldb/DataFormatters/TypeSummary.h" +#include "lldb/DataFormatters/ValueObjectPrinter.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Symbol/ClangASTType.h" #include "lldb/Target/StackFrame.h" @@ -65,51 +66,12 @@ StringSummaryFormat::FormatObject (ValueObject *valobj, if (frame) sc = frame->GetSymbolContext(lldb::eSymbolContextEverything); - if (IsOneliner()) + if (IsOneLiner()) { - ValueObject* object; - - ValueObjectSP synth_valobj = valobj->GetSyntheticValue(); - if (synth_valobj) - object = synth_valobj.get(); - else - object = valobj; - - const uint32_t num_children = object->GetNumChildren(); - if (num_children) - { - s.PutChar('('); - - for (uint32_t idx=0; idx<num_children; ++idx) - { - lldb::ValueObjectSP child_sp(object->GetChildAtIndex(idx, true)); - if (child_sp.get()) - { - if (idx) - s.PutCString(", "); - if (!HideNames()) - { - s.PutCString(child_sp.get()->GetName().AsCString()); - s.PutCString(" = "); - } - child_sp.get()->DumpPrintableRepresentation(s, - ValueObject::eValueObjectRepresentationStyleSummary, - lldb::eFormatInvalid, - ValueObject::ePrintableRepresentationSpecialCasesDisable); - } - } - - s.PutChar(')'); - - retval.assign(s.GetString()); - return true; - } - else - { - retval.assign("error: oneliner for no children"); - return false; - } - + ValueObjectPrinter printer(valobj,&s,DumpValueObjectOptions()); + printer.PrintChildrenOneLiner(HideNames()); + retval.assign(s.GetData()); + return true; } else { @@ -135,7 +97,7 @@ StringSummaryFormat::GetDescription () Cascades() ? "" : " (not cascading)", !DoesPrintChildren() ? "" : " (show children)", !DoesPrintValue() ? " (hide value)" : "", - IsOneliner() ? " (one-line printout)" : "", + IsOneLiner() ? " (one-line printout)" : "", SkipsPointers() ? " (skip pointers)" : "", SkipsReferences() ? " (skip references)" : "", HideNames() ? " (hide member names)" : ""); @@ -171,7 +133,7 @@ CXXFunctionSummaryFormat::GetDescription () Cascades() ? "" : " (not cascading)", !DoesPrintChildren() ? "" : " (show children)", !DoesPrintValue() ? " (hide value)" : "", - IsOneliner() ? " (one-line printout)" : "", + IsOneLiner() ? " (one-line printout)" : "", SkipsPointers() ? " (skip pointers)" : "", SkipsReferences() ? " (skip references)" : "", HideNames() ? " (hide member names)" : ""); @@ -238,7 +200,7 @@ ScriptSummaryFormat::GetDescription () sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)", !DoesPrintChildren() ? "" : " (show children)", !DoesPrintValue() ? " (hide value)" : "", - IsOneliner() ? " (one-line printout)" : "", + IsOneLiner() ? " (one-line printout)" : "", SkipsPointers() ? " (skip pointers)" : "", SkipsReferences() ? " (skip references)" : "", HideNames() ? " (hide member names)" : "", diff --git a/contrib/llvm/tools/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/contrib/llvm/tools/lldb/source/DataFormatters/ValueObjectPrinter.cpp new file mode 100644 index 0000000..5c7f48b --- /dev/null +++ b/contrib/llvm/tools/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -0,0 +1,623 @@ +//===-- ValueObjectPrinter.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/DataFormatters/ValueObjectPrinter.h" + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/Debugger.h" +#include "lldb/DataFormatters/DataVisualization.h" +#include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Target/Target.h" + +using namespace lldb; +using namespace lldb_private; + +ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, + Stream* s, + const DumpValueObjectOptions& options) +{ + Init(valobj,s,options,options.m_max_ptr_depth,0); +} + +ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, + Stream* s, + const DumpValueObjectOptions& options, + uint32_t ptr_depth, + uint32_t curr_depth) +{ + Init(valobj,s,options,ptr_depth,curr_depth); +} + +void +ValueObjectPrinter::Init (ValueObject* valobj, + Stream* s, + const DumpValueObjectOptions& options, + uint32_t ptr_depth, + uint32_t curr_depth) +{ + m_orig_valobj = valobj; + m_valobj = nullptr; + m_stream = s; + this->options = options; + m_ptr_depth = ptr_depth; + m_curr_depth = curr_depth; + assert (m_orig_valobj && "cannot print a NULL ValueObject"); + assert (m_stream && "cannot print to a NULL Stream"); + m_should_print = eLazyBoolCalculate; + m_is_nil = eLazyBoolCalculate; + m_is_ptr = eLazyBoolCalculate; + m_is_ref = eLazyBoolCalculate; + m_is_aggregate = eLazyBoolCalculate; + m_summary_formatter = {nullptr,false}; + m_value.assign(""); + m_summary.assign(""); + m_error.assign(""); +} + +bool +ValueObjectPrinter::PrintValueObject () +{ + if (!GetDynamicValueIfNeeded () || m_valobj == nullptr) + return false; + + if (ShouldPrintValueObject()) + { + PrintLocationIfNeeded(); + m_stream->Indent(); + + bool show_type = PrintTypeIfNeeded(); + + PrintNameIfNeeded(show_type); + } + + bool value_printed = false; + bool summary_printed = false; + + bool val_summary_ok = PrintValueAndSummaryIfNeeded (value_printed,summary_printed); + + if (val_summary_ok) + PrintChildrenIfNeeded (value_printed, summary_printed); + else + m_stream->EOL(); + + return true; +} + +bool +ValueObjectPrinter::GetDynamicValueIfNeeded () +{ + if (m_valobj) + return true; + bool update_success = m_orig_valobj->UpdateValueIfNeeded (true); + if (!update_success) + { + m_valobj = m_orig_valobj; + } + else + { + if (m_orig_valobj->IsDynamic()) + { + if (options.m_use_dynamic == eNoDynamicValues) + { + ValueObject *static_value = m_orig_valobj->GetStaticValue().get(); + if (static_value) + m_valobj = static_value; + else + m_valobj = m_orig_valobj; + } + else + m_valobj = m_orig_valobj; + } + else + { + if (options.m_use_dynamic != eNoDynamicValues) + { + ValueObject *dynamic_value = m_orig_valobj->GetDynamicValue(options.m_use_dynamic).get(); + if (dynamic_value) + m_valobj = dynamic_value; + else + m_valobj = m_orig_valobj; + } + else + m_valobj = m_orig_valobj; + } + } + m_clang_type = m_valobj->GetClangType(); + m_type_flags = m_clang_type.GetTypeInfo (); + return true; +} + +const char* +ValueObjectPrinter::GetDescriptionForDisplay () +{ + const char* str = m_valobj->GetObjectDescription(); + if (!str) + str = m_valobj->GetSummaryAsCString(); + if (!str) + str = m_valobj->GetValueAsCString(); + return str; +} + +const char* +ValueObjectPrinter::GetRootNameForDisplay (const char* if_fail) +{ + const char *root_valobj_name = options.m_root_valobj_name.empty() ? + m_valobj->GetName().AsCString() : + options.m_root_valobj_name.c_str(); + return root_valobj_name ? root_valobj_name : if_fail; +} + +bool +ValueObjectPrinter::ShouldPrintValueObject () +{ + if (m_should_print == eLazyBoolCalculate) + m_should_print = (options.m_flat_output == false || m_type_flags.Test (ClangASTType::eTypeHasValue)) ? eLazyBoolYes : eLazyBoolNo; + return m_should_print == eLazyBoolYes; +} + +bool +ValueObjectPrinter::IsNil () +{ + if (m_is_nil == eLazyBoolCalculate) + m_is_nil = m_valobj->IsObjCNil() ? eLazyBoolYes : eLazyBoolNo; + return m_is_nil == eLazyBoolYes; +} + +bool +ValueObjectPrinter::IsPtr () +{ + if (m_is_ptr == eLazyBoolCalculate) + m_is_ptr = m_type_flags.Test (ClangASTType::eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo; + return m_is_ptr == eLazyBoolYes; +} + +bool +ValueObjectPrinter::IsRef () +{ + if (m_is_ref == eLazyBoolCalculate) + m_is_ref = m_type_flags.Test (ClangASTType::eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo; + return m_is_ref == eLazyBoolYes; +} + +bool +ValueObjectPrinter::IsAggregate () +{ + if (m_is_aggregate == eLazyBoolCalculate) + m_is_aggregate = m_type_flags.Test (ClangASTType::eTypeHasChildren) ? eLazyBoolYes : eLazyBoolNo; + return m_is_aggregate == eLazyBoolYes; +} + +bool +ValueObjectPrinter::PrintLocationIfNeeded () +{ + if (options.m_show_location) + { + m_stream->Printf("%s: ", m_valobj->GetLocationAsCString()); + return true; + } + return false; +} + +bool +ValueObjectPrinter::PrintTypeIfNeeded () +{ + bool show_type = true; + // if we are at the root-level and been asked to hide the root's type, then hide it + if (m_curr_depth == 0 && options.m_hide_root_type) + show_type = false; + else + // otherwise decide according to the usual rules (asked to show types - always at the root level) + show_type = options.m_show_types || (m_curr_depth == 0 && !options.m_flat_output); + + if (show_type) + { + // Some ValueObjects don't have types (like registers sets). Only print + // the type if there is one to print + ConstString qualified_type_name(m_valobj->GetQualifiedTypeName()); + if (qualified_type_name) + m_stream->Printf("(%s) ", qualified_type_name.GetCString()); + else + show_type = false; + } + return show_type; +} + +bool +ValueObjectPrinter::PrintNameIfNeeded (bool show_type) +{ + if (options.m_flat_output) + { + // If we are showing types, also qualify the C++ base classes + const bool qualify_cxx_base_classes = show_type; + if (!options.m_hide_name) + { + m_valobj->GetExpressionPath(*m_stream, qualify_cxx_base_classes); + m_stream->PutCString(" ="); + return true; + } + } + else if (!options.m_hide_name) + { + const char *name_cstr = GetRootNameForDisplay(""); + m_stream->Printf ("%s =", name_cstr); + return true; + } + return false; +} + +bool +ValueObjectPrinter::CheckScopeIfNeeded () +{ + if (options.m_scope_already_checked) + return true; + return m_valobj->IsInScope(); +} + +TypeSummaryImpl* +ValueObjectPrinter::GetSummaryFormatter () +{ + if (m_summary_formatter.second == false) + { + TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : m_valobj->GetSummaryFormat().get(); + + if (options.m_omit_summary_depth > 0) + entry = NULL; + m_summary_formatter.first = entry; + m_summary_formatter.second = true; + } + return m_summary_formatter.first; +} + +void +ValueObjectPrinter::GetValueSummaryError (std::string& value, + std::string& summary, + std::string& error) +{ + if (options.m_format != eFormatDefault && options.m_format != m_valobj->GetFormat()) + { + m_valobj->GetValueAsCString(options.m_format, + value); + } + else + { + const char* val_cstr = m_valobj->GetValueAsCString(); + if (val_cstr) + value.assign(val_cstr); + } + const char* err_cstr = m_valobj->GetError().AsCString(); + if (err_cstr) + error.assign(err_cstr); + + if (ShouldPrintValueObject()) + { + if (IsNil()) + summary.assign("nil"); + else if (options.m_omit_summary_depth == 0) + { + TypeSummaryImpl* entry = GetSummaryFormatter(); + if (entry) + m_valobj->GetSummaryAsCString(entry, summary); + else + { + const char* sum_cstr = m_valobj->GetSummaryAsCString(); + if (sum_cstr) + summary.assign(sum_cstr); + } + } + } +} + +bool +ValueObjectPrinter::PrintValueAndSummaryIfNeeded (bool& value_printed, + bool& summary_printed) +{ + bool error_printed = false; + if (ShouldPrintValueObject()) + { + if (!CheckScopeIfNeeded()) + m_error.assign("out of scope"); + if (m_error.empty()) + { + GetValueSummaryError(m_value, m_summary, m_error); + } + if (m_error.size()) + { + error_printed = true; + m_stream->Printf (" <%s>\n", m_error.c_str()); + } + else + { + // Make sure we have a value and make sure the summary didn't + // specify that the value should not be printed - and do not print + // the value if this thing is nil + // (but show the value if the user passes a format explicitly) + TypeSummaryImpl* entry = GetSummaryFormatter(); + if (!IsNil() && !m_value.empty() && (entry == NULL || (entry->DoesPrintValue() || options.m_format != eFormatDefault) || m_summary.empty()) && !options.m_hide_value) + { + m_stream->Printf(" %s", m_value.c_str()); + value_printed = true; + } + + if (m_summary.size()) + { + m_stream->Printf(" %s", m_summary.c_str()); + summary_printed = true; + } + } + } + return !error_printed; +} + +bool +ValueObjectPrinter::PrintObjectDescriptionIfNeeded (bool value_printed, + bool summary_printed) +{ + if (ShouldPrintValueObject()) + { + // let's avoid the overly verbose no description error for a nil thing + if (options.m_use_objc && !IsNil()) + { + if (!options.m_hide_value || !options.m_hide_name) + m_stream->Printf(" "); + const char *object_desc = nullptr; + if (value_printed || summary_printed) + object_desc = m_valobj->GetObjectDescription(); + else + object_desc = GetDescriptionForDisplay(); + if (object_desc && *object_desc) + { + m_stream->Printf("%s\n", object_desc); + return true; + } + else if (value_printed == false && summary_printed == false) + return true; + else + return false; + } + } + return true; +} + +bool +ValueObjectPrinter::ShouldPrintChildren (bool is_failed_description, + uint32_t& curr_ptr_depth) +{ + const bool is_ref = IsRef (); + const bool is_ptr = IsPtr (); + + if (is_failed_description || m_curr_depth < options.m_max_depth) + { + // We will show children for all concrete types. We won't show + // pointer contents unless a pointer depth has been specified. + // We won't reference contents unless the reference is the + // root object (depth of zero). + + // Use a new temporary pointer depth in case we override the + // current pointer depth below... + uint32_t curr_ptr_depth = m_ptr_depth; + + if (is_ptr || is_ref) + { + // We have a pointer or reference whose value is an address. + // Make sure that address is not NULL + AddressType ptr_address_type; + if (m_valobj->GetPointerValue (&ptr_address_type) == 0) + return false; + + else if (is_ref && m_curr_depth == 0) + { + // If this is the root object (depth is zero) that we are showing + // and it is a reference, and no pointer depth has been supplied + // print out what it references. Don't do this at deeper depths + // otherwise we can end up with infinite recursion... + curr_ptr_depth = 1; + } + + return (curr_ptr_depth > 0); + } + + TypeSummaryImpl* entry = GetSummaryFormatter(); + + return (!entry || entry->DoesPrintChildren() || m_summary.empty()); + } + return false; +} + +ValueObject* +ValueObjectPrinter::GetValueObjectForChildrenGeneration () +{ + ValueObjectSP synth_valobj_sp = m_valobj->GetSyntheticValue (options.m_use_synthetic); + return (synth_valobj_sp ? synth_valobj_sp.get() : m_valobj); +} + +void +ValueObjectPrinter::PrintChildrenPreamble () +{ + if (options.m_flat_output) + { + if (ShouldPrintValueObject()) + m_stream->EOL(); + } + else + { + if (ShouldPrintValueObject()) + m_stream->PutCString(IsRef () ? ": {\n" : " {\n"); + m_stream->IndentMore(); + } +} + +void +ValueObjectPrinter::PrintChild (ValueObjectSP child_sp, + uint32_t curr_ptr_depth) +{ + DumpValueObjectOptions child_options(options); + child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName(); + child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value) + .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0); + if (child_sp.get()) + { + ValueObjectPrinter child_printer(child_sp.get(), + m_stream, + child_options, + (IsPtr() || IsRef()) ? curr_ptr_depth - 1 : curr_ptr_depth, + m_curr_depth + 1); + child_printer.PrintValueObject(); + } + +} + +uint32_t +ValueObjectPrinter::GetMaxNumChildrenToPrint (bool& print_dotdotdot) +{ + ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); + + size_t num_children = synth_m_valobj->GetNumChildren(); + print_dotdotdot = false; + if (num_children) + { + const size_t max_num_children = m_valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); + + if (num_children > max_num_children && !options.m_ignore_cap) + { + print_dotdotdot = true; + return max_num_children; + } + } + return num_children; +} + +void +ValueObjectPrinter::PrintChildrenPostamble (bool print_dotdotdot) +{ + if (!options.m_flat_output) + { + if (print_dotdotdot) + { + m_valobj->GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated(); + m_stream->Indent("...\n"); + } + m_stream->IndentLess(); + m_stream->Indent("}\n"); + } +} + +void +ValueObjectPrinter::PrintChildren (uint32_t curr_ptr_depth) +{ + ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); + + bool print_dotdotdot = false; + size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); + if (num_children) + { + PrintChildrenPreamble (); + + for (size_t idx=0; idx<num_children; ++idx) + { + ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true)); + PrintChild (child_sp, curr_ptr_depth); + } + + PrintChildrenPostamble (print_dotdotdot); + } + else if (IsAggregate()) + { + // Aggregate, no children... + if (ShouldPrintValueObject()) + m_stream->PutCString(" {}\n"); + } + else + { + if (ShouldPrintValueObject()) + m_stream->EOL(); + } +} + +bool +ValueObjectPrinter::PrintChildrenOneLiner (bool hide_names) +{ + if (!GetDynamicValueIfNeeded () || m_valobj == nullptr) + return false; + + ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); + + bool print_dotdotdot = false; + size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); + + if (num_children) + { + m_stream->PutChar('('); + + for (uint32_t idx=0; idx<num_children; ++idx) + { + lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true)); + lldb::ValueObjectSP child_dyn_sp = child_sp.get() ? child_sp->GetDynamicValue(options.m_use_dynamic) : child_sp; + if (child_dyn_sp) + child_sp = child_dyn_sp; + if (child_sp) + { + if (idx) + m_stream->PutCString(", "); + if (!hide_names) + { + const char* name = child_sp.get()->GetName().AsCString(); + if (name && *name) + { + m_stream->PutCString(name); + m_stream->PutCString(" = "); + } + } + child_sp->DumpPrintableRepresentation(*m_stream, + ValueObject::eValueObjectRepresentationStyleSummary, + lldb::eFormatInvalid, + ValueObject::ePrintableRepresentationSpecialCasesDisable); + } + } + + if (print_dotdotdot) + m_stream->PutCString(", ...)"); + else + m_stream->PutChar(')'); + } + return true; +} + +void +ValueObjectPrinter::PrintChildrenIfNeeded (bool value_printed, + bool summary_printed) +{ + // this flag controls whether we tried to display a description for this object and failed + // if that happens, we want to display the children, if any + bool is_failed_description = !PrintObjectDescriptionIfNeeded(value_printed, summary_printed); + + uint32_t curr_ptr_depth = m_ptr_depth; + bool print_children = ShouldPrintChildren (is_failed_description,curr_ptr_depth); + bool print_oneline = (curr_ptr_depth > 0 || options.m_show_types || options.m_be_raw) ? false : DataVisualization::ShouldPrintAsOneLiner(*m_valobj); + + if (print_children) + { + if (print_oneline) + { + m_stream->PutChar(' '); + PrintChildrenOneLiner (false); + m_stream->EOL(); + } + else + PrintChildren (curr_ptr_depth); + } + else if (m_curr_depth >= options.m_max_depth && IsAggregate() && ShouldPrintValueObject()) + { + m_stream->PutCString("{...}\n"); + } + else + m_stream->EOL(); +} |