diff options
author | Enrico Granata <egranata@apple.com> | 2013-10-08 19:03:22 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2013-10-08 19:03:22 +0000 |
commit | 852cc954db37fec8e169f954589bd2901f93e845 (patch) | |
tree | 871ba9ead712e13c265f64e71856ef05b964ca3e /lldb/source/DataFormatters | |
parent | bda410f413cac139c32ef1f3416b09645cd6c8f5 (diff) | |
download | bcm5719-llvm-852cc954db37fec8e169f954589bd2901f93e845.tar.gz bcm5719-llvm-852cc954db37fec8e169f954589bd2901f93e845.zip |
<rdar://problem/11778815>
Formats (as in "type format") are now included in categories
The only bit missing is caching formats along with synthetic children and summaries, which might be now desirable
llvm-svn: 192217
Diffstat (limited to 'lldb/source/DataFormatters')
-rw-r--r-- | lldb/source/DataFormatters/DataVisualization.cpp | 57 | ||||
-rw-r--r-- | lldb/source/DataFormatters/FormatManager.cpp | 63 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeCategory.cpp | 119 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeCategoryMap.cpp | 26 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeFormat.cpp | 2 |
5 files changed, 204 insertions, 63 deletions
diff --git a/lldb/source/DataFormatters/DataVisualization.cpp b/lldb/source/DataFormatters/DataVisualization.cpp index 94447fc8ede..48d3517750a 100644 --- a/lldb/source/DataFormatters/DataVisualization.cpp +++ b/lldb/source/DataFormatters/DataVisualization.cpp @@ -47,66 +47,19 @@ DataVisualization::ShouldPrintAsOneLiner (ValueObject& valobj) } lldb::TypeFormatImplSP -DataVisualization::ValueFormats::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) +DataVisualization::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) { - lldb::TypeFormatImplSP entry; - GetFormatManager().GetValueNavigator().Get(valobj, entry, use_dynamic); - return entry; + return GetFormatManager().GetFormat(valobj, use_dynamic); } lldb::TypeFormatImplSP -DataVisualization::ValueFormats::GetFormat (const ConstString &type) +DataVisualization::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) { - 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) -{ - return GetFormatManager().GetValueNavigator().Delete(type); -} - -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) -{ - return GetFormatManager().GetValueNavigator().GetTypeNameSpecifierAtIndex(index); -} - -lldb::TypeFormatImplSP -DataVisualization::ValueFormats::GetFormatAtIndex (size_t index) -{ - 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/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index d4607b05417..b67cfb26c0a 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/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) { @@ -394,6 +420,42 @@ GetTypeForCache (ValueObject& valobj, return ConstString(); } +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::GetSummaryFormat] Looking into cache for type %s", valobj_type.AsCString("<invalid>")); +// if (m_format_cache.GetSummary(valobj_type,retval)) +// { +// if (log) +// { +// log->Printf("[FormatManager::GetSummaryFormat] Cache search success. Returning."); +// if (log->GetDebug()) +// log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); +// } +// return retval; +// } +// if (log) +// log->Printf("[FormatManager::GetSummaryFormat] Cache search failed. Going normal route"); +// } + retval = m_categories_map.GetFormat(valobj, use_dynamic); +// if (valobj_type) +// { +// if (log) +// log->Printf("[FormatManager::GetSummaryFormat] Caching %p for type %s",retval.get(),valobj_type.AsCString("<invalid>")); +// m_format_cache.SetSummary(valobj_type,retval); +// } +// if (log && log->GetDebug()) +// log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64 " - Cache Misses: %" PRIu64, m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); + return retval; +} + lldb::TypeSummaryImplSP FormatManager::GetSummaryFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) @@ -470,7 +532,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), diff --git a/lldb/source/DataFormatters/TypeCategory.cpp b/lldb/source/DataFormatters/TypeCategory.cpp index c887be5da49..636000bb23e 100644 --- a/lldb/source/DataFormatters/TypeCategory.cpp +++ b/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/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp index 4b7222adbec..621258806de 100644 --- a/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/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/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp index 279704f2af1..7f18ddef726 100644 --- a/lldb/source/DataFormatters/TypeFormat.cpp +++ b/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)" : "", |