diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
| commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
| tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /lldb/source/DataFormatters | |
| parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) | |
Notes
Diffstat (limited to 'lldb/source/DataFormatters')
| -rw-r--r-- | lldb/source/DataFormatters/DataVisualization.cpp | 14 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/FormatCache.cpp | 166 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/FormatClasses.cpp | 3 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/FormatManager.cpp | 357 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/LanguageCategory.cpp | 188 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/TypeCategory.cpp | 123 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/TypeCategoryMap.cpp | 155 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/TypeValidator.cpp | 53 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/ValueObjectPrinter.cpp | 38 |
9 files changed, 195 insertions, 902 deletions
diff --git a/lldb/source/DataFormatters/DataVisualization.cpp b/lldb/source/DataFormatters/DataVisualization.cpp index 08b3b34447bba..99c303c9f0b1c 100644 --- a/lldb/source/DataFormatters/DataVisualization.cpp +++ b/lldb/source/DataFormatters/DataVisualization.cpp @@ -66,17 +66,6 @@ DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { return GetFormatManager().GetSyntheticForType(type_sp); } -lldb::TypeValidatorImplSP -DataVisualization::GetValidator(ValueObject &valobj, - lldb::DynamicValueType use_dynamic) { - return GetFormatManager().GetValidator(valobj, use_dynamic); -} - -lldb::TypeValidatorImplSP -DataVisualization::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) { - return GetFormatManager().GetValidatorForType(type_sp); -} - bool DataVisualization::AnyMatches( ConstString type_name, TypeCategoryImpl::FormatCategoryItems items, bool only_enabled, const char **matching_category, @@ -122,8 +111,7 @@ void DataVisualization::Categories::Enable(ConstString category, TypeCategoryMap::Position pos) { if (GetFormatManager().GetCategory(category)->IsEnabled()) GetFormatManager().DisableCategory(category); - GetFormatManager().EnableCategory( - category, pos, std::initializer_list<lldb::LanguageType>()); + GetFormatManager().EnableCategory(category, pos, {}); } void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) { diff --git a/lldb/source/DataFormatters/FormatCache.cpp b/lldb/source/DataFormatters/FormatCache.cpp index 7e328cb0dac85..231e7ed0c0a07 100644 --- a/lldb/source/DataFormatters/FormatCache.cpp +++ b/lldb/source/DataFormatters/FormatCache.cpp @@ -17,46 +17,7 @@ using namespace lldb_private; FormatCache::Entry::Entry() : m_format_cached(false), m_summary_cached(false), - m_synthetic_cached(false), m_validator_cached(false), m_format_sp(), - m_summary_sp(), m_synthetic_sp(), m_validator_sp() {} - -FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp) - : m_summary_cached(false), m_synthetic_cached(false), - m_validator_cached(false), m_summary_sp(), m_synthetic_sp(), - m_validator_sp() { - SetFormat(format_sp); -} - -FormatCache::Entry::Entry(lldb::TypeSummaryImplSP summary_sp) - : m_format_cached(false), m_synthetic_cached(false), - m_validator_cached(false), m_format_sp(), m_synthetic_sp(), - m_validator_sp() { - SetSummary(summary_sp); -} - -FormatCache::Entry::Entry(lldb::SyntheticChildrenSP synthetic_sp) - : m_format_cached(false), m_summary_cached(false), - m_validator_cached(false), m_format_sp(), m_summary_sp(), - m_validator_sp() { - SetSynthetic(synthetic_sp); -} - -FormatCache::Entry::Entry(lldb::TypeValidatorImplSP validator_sp) - : m_format_cached(false), m_summary_cached(false), - m_synthetic_cached(false), m_format_sp(), m_summary_sp(), - m_synthetic_sp() { - SetValidator(validator_sp); -} - -FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp, - lldb::TypeSummaryImplSP summary_sp, - lldb::SyntheticChildrenSP synthetic_sp, - lldb::TypeValidatorImplSP validator_sp) { - SetFormat(format_sp); - SetSummary(summary_sp); - SetSynthetic(synthetic_sp); - SetValidator(validator_sp); -} + m_synthetic_cached(false) {} bool FormatCache::Entry::IsFormatCached() { return m_format_cached; } @@ -64,42 +25,33 @@ bool FormatCache::Entry::IsSummaryCached() { return m_summary_cached; } bool FormatCache::Entry::IsSyntheticCached() { return m_synthetic_cached; } -bool FormatCache::Entry::IsValidatorCached() { return m_validator_cached; } - -lldb::TypeFormatImplSP FormatCache::Entry::GetFormat() { return m_format_sp; } - -lldb::TypeSummaryImplSP FormatCache::Entry::GetSummary() { - return m_summary_sp; +void FormatCache::Entry::Get(lldb::TypeFormatImplSP &retval) { + retval = m_format_sp; } -lldb::SyntheticChildrenSP FormatCache::Entry::GetSynthetic() { - return m_synthetic_sp; +void FormatCache::Entry::Get(lldb::TypeSummaryImplSP &retval) { + retval = m_summary_sp; } -lldb::TypeValidatorImplSP FormatCache::Entry::GetValidator() { - return m_validator_sp; +void FormatCache::Entry::Get(lldb::SyntheticChildrenSP &retval) { + retval = m_synthetic_sp; } -void FormatCache::Entry::SetFormat(lldb::TypeFormatImplSP format_sp) { +void FormatCache::Entry::Set(lldb::TypeFormatImplSP format_sp) { m_format_cached = true; m_format_sp = format_sp; } -void FormatCache::Entry::SetSummary(lldb::TypeSummaryImplSP summary_sp) { +void FormatCache::Entry::Set(lldb::TypeSummaryImplSP summary_sp) { m_summary_cached = true; m_summary_sp = summary_sp; } -void FormatCache::Entry::SetSynthetic(lldb::SyntheticChildrenSP synthetic_sp) { +void FormatCache::Entry::Set(lldb::SyntheticChildrenSP synthetic_sp) { m_synthetic_cached = true; m_synthetic_sp = synthetic_sp; } -void FormatCache::Entry::SetValidator(lldb::TypeValidatorImplSP validator_sp) { - m_validator_cached = true; - m_validator_sp = validator_sp; -} - FormatCache::FormatCache() : m_map(), m_mutex() #ifdef LLDB_CONFIGURATION_DEBUG @@ -117,100 +69,60 @@ FormatCache::Entry &FormatCache::GetEntry(ConstString type) { return m_map[type]; } -bool FormatCache::GetFormat(ConstString type, - lldb::TypeFormatImplSP &format_sp) { - std::lock_guard<std::recursive_mutex> guard(m_mutex); - auto entry = GetEntry(type); - if (entry.IsFormatCached()) { -#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; +template<> bool FormatCache::Entry::IsCached<lldb::TypeFormatImplSP>() { + return IsFormatCached(); } - -bool FormatCache::GetSummary(ConstString type, - lldb::TypeSummaryImplSP &summary_sp) { - std::lock_guard<std::recursive_mutex> guard(m_mutex); - auto entry = GetEntry(type); - if (entry.IsSummaryCached()) { -#ifdef LLDB_CONFIGURATION_DEBUG - m_cache_hits++; -#endif - summary_sp = entry.GetSummary(); - return true; - } -#ifdef LLDB_CONFIGURATION_DEBUG - m_cache_misses++; -#endif - summary_sp.reset(); - return false; +template<> bool FormatCache::Entry::IsCached<lldb::TypeSummaryImplSP> () { + return IsSummaryCached(); } - -bool FormatCache::GetSynthetic(ConstString type, - lldb::SyntheticChildrenSP &synthetic_sp) { - std::lock_guard<std::recursive_mutex> guard(m_mutex); - auto entry = GetEntry(type); - if (entry.IsSyntheticCached()) { -#ifdef LLDB_CONFIGURATION_DEBUG - m_cache_hits++; -#endif - synthetic_sp = entry.GetSynthetic(); - return true; - } -#ifdef LLDB_CONFIGURATION_DEBUG - m_cache_misses++; -#endif - synthetic_sp.reset(); - return false; +template<> bool FormatCache::Entry::IsCached<lldb::SyntheticChildrenSP>() { + return IsSyntheticCached(); } -bool FormatCache::GetValidator(ConstString type, - lldb::TypeValidatorImplSP &validator_sp) { +template <typename ImplSP> +bool FormatCache::Get(ConstString type, ImplSP &format_impl_sp) { std::lock_guard<std::recursive_mutex> guard(m_mutex); auto entry = GetEntry(type); - if (entry.IsValidatorCached()) { + if (entry.IsCached<ImplSP>()) { #ifdef LLDB_CONFIGURATION_DEBUG m_cache_hits++; #endif - validator_sp = entry.GetValidator(); + entry.Get(format_impl_sp); return true; } #ifdef LLDB_CONFIGURATION_DEBUG m_cache_misses++; #endif - validator_sp.reset(); + format_impl_sp.reset(); return false; } -void FormatCache::SetFormat(ConstString type, - lldb::TypeFormatImplSP &format_sp) { - std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetFormat(format_sp); -} +/// Explicit instantiations for the three types. +/// \{ +template bool +FormatCache::Get<lldb::TypeFormatImplSP>(ConstString, lldb::TypeFormatImplSP &); +template bool +FormatCache::Get<lldb::TypeSummaryImplSP>(ConstString, + lldb::TypeSummaryImplSP &); +template bool +FormatCache::Get<lldb::SyntheticChildrenSP>(ConstString, + lldb::SyntheticChildrenSP &); +/// \} -void FormatCache::SetSummary(ConstString type, - lldb::TypeSummaryImplSP &summary_sp) { +void FormatCache::Set(ConstString type, lldb::TypeFormatImplSP &format_sp) { std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetSummary(summary_sp); + GetEntry(type).Set(format_sp); } -void FormatCache::SetSynthetic(ConstString type, - lldb::SyntheticChildrenSP &synthetic_sp) { +void FormatCache::Set(ConstString type, lldb::TypeSummaryImplSP &summary_sp) { std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetSynthetic(synthetic_sp); + GetEntry(type).Set(summary_sp); } -void FormatCache::SetValidator(ConstString type, - lldb::TypeValidatorImplSP &validator_sp) { +void FormatCache::Set(ConstString type, + lldb::SyntheticChildrenSP &synthetic_sp) { std::lock_guard<std::recursive_mutex> guard(m_mutex); - GetEntry(type).SetValidator(validator_sp); + GetEntry(type).Set(synthetic_sp); } void FormatCache::Clear() { diff --git a/lldb/source/DataFormatters/FormatClasses.cpp b/lldb/source/DataFormatters/FormatClasses.cpp index 271963b5f8f43..6a9279f54d64c 100644 --- a/lldb/source/DataFormatters/FormatClasses.cpp +++ b/lldb/source/DataFormatters/FormatClasses.cpp @@ -24,7 +24,8 @@ FormattersMatchData::FormattersMatchData(ValueObject &valobj, m_formatters_match_vector({}, false), m_type_for_cache(), m_candidate_languages() { m_type_for_cache = FormatManager::GetTypeForCache(valobj, use_dynamic); - m_candidate_languages = FormatManager::GetCandidateLanguages(valobj); + m_candidate_languages = + FormatManager::GetCandidateLanguages(valobj.GetObjectRuntimeLanguage()); } FormattersMatchVector FormattersMatchData::GetMatchesVector() { diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index 1eac372d79ec8..d5db3ee75bf34 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -230,15 +230,38 @@ void FormatManager::GetPossibleMatches( if (non_ptr_type.IsTypedefType()) { CompilerType deffed_pointed_type = non_ptr_type.GetTypedefedType().GetPointerType(); + const bool stripped_typedef = true; GetPossibleMatches( valobj, deffed_pointed_type, reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, - true); // this is not exactly the usual meaning of stripping typedefs + stripped_typedef); // this is not exactly the usual meaning of + // stripping typedefs + } + } + + // For arrays with typedef-ed elements, we add a candidate with the typedef + // stripped. + uint64_t array_size; + if (compiler_type.IsArrayType(nullptr, &array_size, nullptr)) { + CompilerType element_type = compiler_type.GetArrayElementType(); + if (element_type.IsTypedefType()) { + // Get the stripped element type and compute the stripped array type + // from it. + CompilerType deffed_array_type = + element_type.GetTypedefedType().GetArrayType(array_size); + const bool stripped_typedef = true; + GetPossibleMatches( + valobj, deffed_array_type, + reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, + use_dynamic, entries, did_strip_ptr, did_strip_ref, + stripped_typedef); // this is not exactly the usual meaning of + // stripping typedefs } } - for (lldb::LanguageType language_type : GetCandidateLanguages(valobj)) { + for (lldb::LanguageType language_type : + GetCandidateLanguages(valobj.GetObjectRuntimeLanguage())) { if (Language *language = Language::FindPlugin(language_type)) { for (ConstString candidate : language->GetPossibleFormattersMatches(valobj, use_dynamic)) { @@ -385,30 +408,6 @@ FormatManager::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { return synth_chosen_sp; } -lldb::TypeValidatorImplSP -FormatManager::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) { - if (!type_sp) - return lldb::TypeValidatorImplSP(); - lldb::TypeValidatorImplSP validator_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()) - continue; - lldb::TypeValidatorImplSP validator_current_sp( - category_sp->GetValidatorForType(type_sp).get()); - if (validator_current_sp && - (validator_chosen_sp.get() == nullptr || - (prio_category > category_sp->GetEnabledPosition()))) { - prio_category = category_sp->GetEnabledPosition(); - validator_chosen_sp = validator_current_sp; - } - } - return validator_chosen_sp; -} - void FormatManager::ForEachCategory(TypeCategoryMap::ForEachCallback callback) { m_categories_map.ForEach(callback); std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); @@ -579,12 +578,6 @@ ConstString FormatManager::GetTypeForCache(ValueObject &valobj, } std::vector<lldb::LanguageType> -FormatManager::GetCandidateLanguages(ValueObject &valobj) { - lldb::LanguageType lang_type = valobj.GetObjectRuntimeLanguage(); - return GetCandidateLanguages(lang_type); -} - -std::vector<lldb::LanguageType> FormatManager::GetCandidateLanguages(lldb::LanguageType lang_type) { switch (lang_type) { case lldb::eLanguageTypeC: @@ -599,6 +592,7 @@ FormatManager::GetCandidateLanguages(lldb::LanguageType lang_type) { default: return {lang_type}; } + llvm_unreachable("Fully covered switch"); } LanguageCategory * @@ -614,302 +608,93 @@ FormatManager::GetCategoryForLanguage(lldb::LanguageType lang_type) { return lang_category; } -lldb::TypeFormatImplSP -FormatManager::GetHardcodedFormat(FormattersMatchData &match_data) { - TypeFormatImplSP retval_sp; - +template <typename ImplSP> +ImplSP FormatManager::GetHardcoded(FormattersMatchData &match_data) { + ImplSP retval_sp; for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; + return retval_sp; } } - return retval_sp; } -lldb::TypeFormatImplSP -FormatManager::GetFormat(ValueObject &valobj, - lldb::DynamicValueType use_dynamic) { +template <typename ImplSP> +ImplSP FormatManager::Get(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { FormattersMatchData match_data(valobj, use_dynamic); + if (ImplSP retval_sp = GetCached<ImplSP>(match_data)) + return retval_sp; - TypeFormatImplSP retval; Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); - if (match_data.GetTypeForCache()) { - LLDB_LOGF(log, - "\n\n[FormatManager::GetFormat] Looking into cache for type %s", - match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetFormat(match_data.GetTypeForCache(), retval)) { - if (log) { - LLDB_LOGF( - log, "[FormatManager::GetFormat] Cache search success. Returning."); - LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", - m_format_cache.GetCacheHits(), - m_format_cache.GetCacheMisses()); - } - return retval; - } - LLDB_LOGF( - log, - "[FormatManager::GetFormat] Cache search failed. Going normal route"); - } - - retval = m_categories_map.GetFormat(match_data); - if (!retval) { - LLDB_LOGF(log, - "[FormatManager::GetFormat] Search failed. Giving language a " - "chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { - if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) { - LLDB_LOGF( - log, - "[FormatManager::GetFormat] Language search success. Returning."); - return retval; - } - } - if (!retval) { - LLDB_LOGF(log, "[FormatManager::GetFormat] Search failed. Giving hardcoded " - "a chance."); - retval = GetHardcodedFormat(match_data); - } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { - LLDB_LOGF(log, "[FormatManager::GetFormat] Caching %p for type %s", - static_cast<void *>(retval.get()), - match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetFormat(match_data.GetTypeForCache(), retval); - } - LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", - m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; -} - -lldb::TypeSummaryImplSP -FormatManager::GetHardcodedSummaryFormat(FormattersMatchData &match_data) { - TypeSummaryImplSP retval_sp; + LLDB_LOGF(log, "[%s] Search failed. Giving language a chance.", __FUNCTION__); for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { - if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; + ImplSP retval_sp; + if (lang_category->Get(match_data, retval_sp)) + if (retval_sp) { + LLDB_LOGF(log, "[%s] Language search success. Returning.", + __FUNCTION__); + return retval_sp; + } } } - return retval_sp; + LLDB_LOGF(log, "[%s] Search failed. Giving hardcoded a chance.", + __FUNCTION__); + return GetHardcoded<ImplSP>(match_data); } -lldb::TypeSummaryImplSP -FormatManager::GetSummaryFormat(ValueObject &valobj, - lldb::DynamicValueType use_dynamic) { - FormattersMatchData match_data(valobj, use_dynamic); - - TypeSummaryImplSP retval; +template <typename ImplSP> +ImplSP FormatManager::GetCached(FormattersMatchData &match_data) { + ImplSP retval_sp; Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); if (match_data.GetTypeForCache()) { - LLDB_LOGF(log, - "\n\n[FormatManager::GetSummaryFormat] Looking into cache " - "for type %s", + LLDB_LOGF(log, "\n\n[%s] Looking into cache for type %s", __FUNCTION__, match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetSummary(match_data.GetTypeForCache(), retval)) { + if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp)) { if (log) { - LLDB_LOGF(log, - "[FormatManager::GetSummaryFormat] Cache search success. " - "Returning."); + LLDB_LOGF(log, "[%s] Cache search success. Returning.", __FUNCTION__); LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); } - return retval; + return retval_sp; } - LLDB_LOGF(log, "[FormatManager::GetSummaryFormat] Cache search failed. " - "Going normal route"); + LLDB_LOGF(log, "[%s] Cache search failed. Going normal route", + __FUNCTION__); } - retval = m_categories_map.GetSummaryFormat(match_data); - if (!retval) { - LLDB_LOGF(log, "[FormatManager::GetSummaryFormat] Search failed. Giving " - "language a chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { - if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) { - LLDB_LOGF(log, "[FormatManager::GetSummaryFormat] Language search " - "success. Returning."); - return retval; - } - } - if (!retval) { - LLDB_LOGF(log, "[FormatManager::GetSummaryFormat] Search failed. Giving " - "hardcoded a chance."); - retval = GetHardcodedSummaryFormat(match_data); - } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { - LLDB_LOGF(log, "[FormatManager::GetSummaryFormat] Caching %p for type %s", - static_cast<void *>(retval.get()), + m_categories_map.Get(match_data, retval_sp); + if (match_data.GetTypeForCache() && (!retval_sp || !retval_sp->NonCacheable())) { + LLDB_LOGF(log, "[%s] Caching %p for type %s", __FUNCTION__, + static_cast<void *>(retval_sp.get()), match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetSummary(match_data.GetTypeForCache(), retval); + m_format_cache.Set(match_data.GetTypeForCache(), retval_sp); } LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; + return retval_sp; } -lldb::SyntheticChildrenSP -FormatManager::GetHardcodedSyntheticChildren(FormattersMatchData &match_data) { - SyntheticChildrenSP retval_sp; - - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { - if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { - if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; - } - } +lldb::TypeFormatImplSP +FormatManager::GetFormat(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + return Get<lldb::TypeFormatImplSP>(valobj, use_dynamic); +} - return retval_sp; +lldb::TypeSummaryImplSP +FormatManager::GetSummaryFormat(ValueObject &valobj, + lldb::DynamicValueType use_dynamic) { + return Get<lldb::TypeSummaryImplSP>(valobj, use_dynamic); } lldb::SyntheticChildrenSP FormatManager::GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic) { - FormattersMatchData match_data(valobj, use_dynamic); - - SyntheticChildrenSP retval; - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); - if (match_data.GetTypeForCache()) { - LLDB_LOGF(log, - "\n\n[FormatManager::GetSyntheticChildren] Looking into " - "cache for type %s", - match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(), retval)) { - if (log) { - LLDB_LOGF(log, "[FormatManager::GetSyntheticChildren] Cache search " - "success. Returning."); - LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", - m_format_cache.GetCacheHits(), - m_format_cache.GetCacheMisses()); - } - return retval; - } - LLDB_LOGF(log, "[FormatManager::GetSyntheticChildren] Cache search failed. " - "Going normal route"); - } - - retval = m_categories_map.GetSyntheticChildren(match_data); - if (!retval) { - LLDB_LOGF(log, - "[FormatManager::GetSyntheticChildren] Search failed. Giving " - "language a chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { - if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) { - LLDB_LOGF(log, "[FormatManager::GetSyntheticChildren] Language search " - "success. Returning."); - return retval; - } - } - if (!retval) { - LLDB_LOGF(log, - "[FormatManager::GetSyntheticChildren] Search failed. Giving " - "hardcoded a chance."); - retval = GetHardcodedSyntheticChildren(match_data); - } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { - LLDB_LOGF(log, - "[FormatManager::GetSyntheticChildren] Caching %p for type %s", - static_cast<void *>(retval.get()), - match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetSynthetic(match_data.GetTypeForCache(), retval); - } - LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", - m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; -} - -lldb::TypeValidatorImplSP -FormatManager::GetValidator(ValueObject &valobj, - lldb::DynamicValueType use_dynamic) { - FormattersMatchData match_data(valobj, use_dynamic); - - TypeValidatorImplSP retval; - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); - if (match_data.GetTypeForCache()) { - LLDB_LOGF( - log, "\n\n[FormatManager::GetValidator] Looking into cache for type %s", - match_data.GetTypeForCache().AsCString("<invalid>")); - if (m_format_cache.GetValidator(match_data.GetTypeForCache(), retval)) { - if (log) { - LLDB_LOGF( - log, - "[FormatManager::GetValidator] Cache search success. Returning."); - LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", - m_format_cache.GetCacheHits(), - m_format_cache.GetCacheMisses()); - } - return retval; - } - LLDB_LOGF(log, "[FormatManager::GetValidator] Cache search failed. Going " - "normal route"); - } - - retval = m_categories_map.GetValidator(match_data); - if (!retval) { - LLDB_LOGF(log, "[FormatManager::GetValidator] Search failed. Giving " - "language a chance."); - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { - if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { - if (lang_category->Get(match_data, retval)) - break; - } - } - if (retval) { - LLDB_LOGF(log, "[FormatManager::GetValidator] Language search success. " - "Returning."); - return retval; - } - } - if (!retval) { - LLDB_LOGF(log, "[FormatManager::GetValidator] Search failed. Giving " - "hardcoded a chance."); - retval = GetHardcodedValidator(match_data); - } - - if (match_data.GetTypeForCache() && (!retval || !retval->NonCacheable())) { - LLDB_LOGF(log, "[FormatManager::GetValidator] Caching %p for type %s", - static_cast<void *>(retval.get()), - match_data.GetTypeForCache().AsCString("<invalid>")); - m_format_cache.SetValidator(match_data.GetTypeForCache(), retval); - } - LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}", - m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses()); - return retval; -} - -lldb::TypeValidatorImplSP -FormatManager::GetHardcodedValidator(FormattersMatchData &match_data) { - TypeValidatorImplSP retval_sp; - - for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) { - if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) { - if (lang_category->GetHardcoded(*this, match_data, retval_sp)) - break; - } - } - - return retval_sp; + return Get<lldb::SyntheticChildrenSP>(valobj, use_dynamic); } FormatManager::FormatManager() diff --git a/lldb/source/DataFormatters/LanguageCategory.cpp b/lldb/source/DataFormatters/LanguageCategory.cpp index 969b02556548c..e18ec0feaa8b2 100644 --- a/lldb/source/DataFormatters/LanguageCategory.cpp +++ b/lldb/source/DataFormatters/LanguageCategory.cpp @@ -14,7 +14,6 @@ #include "lldb/DataFormatters/TypeFormat.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" -#include "lldb/DataFormatters/TypeValidator.h" #include "lldb/Target/Language.h" using namespace lldb; @@ -22,20 +21,19 @@ using namespace lldb_private; LanguageCategory::LanguageCategory(lldb::LanguageType lang_type) : m_category_sp(), m_hardcoded_formats(), m_hardcoded_summaries(), - m_hardcoded_synthetics(), m_hardcoded_validators(), m_format_cache(), - m_enabled(false) { + m_hardcoded_synthetics(), m_format_cache(), m_enabled(false) { if (Language *language_plugin = Language::FindPlugin(lang_type)) { m_category_sp = language_plugin->GetFormatters(); m_hardcoded_formats = language_plugin->GetHardcodedFormats(); m_hardcoded_summaries = language_plugin->GetHardcodedSummaries(); m_hardcoded_synthetics = language_plugin->GetHardcodedSynthetics(); - m_hardcoded_validators = language_plugin->GetHardcodedValidators(); } Enable(); } +template<typename ImplSP> bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::TypeFormatImplSP &format_sp) { + ImplSP &retval_sp) { if (!m_category_sp) return false; @@ -43,168 +41,76 @@ bool LanguageCategory::Get(FormattersMatchData &match_data, return false; if (match_data.GetTypeForCache()) { - if (m_format_cache.GetFormat(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; + if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp)) + return (bool)retval_sp; } ValueObject &valobj(match_data.GetValueObject()); - bool result = - m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); + bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(), + match_data.GetMatchesVector(), retval_sp); if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp); + (!retval_sp || !retval_sp->NonCacheable())) { + m_format_cache.Set(match_data.GetTypeForCache(), retval_sp); } return result; } -bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::TypeSummaryImplSP &format_sp) { - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) { - if (m_format_cache.GetSummary(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject &valobj(match_data.GetValueObject()); - bool result = - m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp); - } - return result; +/// Explicit instantiations for the three types. +/// \{ +template bool +LanguageCategory::Get<lldb::TypeFormatImplSP>(FormattersMatchData &, + lldb::TypeFormatImplSP &); +template bool +LanguageCategory::Get<lldb::TypeSummaryImplSP>(FormattersMatchData &, + lldb::TypeSummaryImplSP &); +template bool +LanguageCategory::Get<lldb::SyntheticChildrenSP>(FormattersMatchData &, + lldb::SyntheticChildrenSP &); +/// \} + +template <> +auto &LanguageCategory::GetHardcodedFinder<lldb::TypeFormatImplSP>() { + return m_hardcoded_formats; } -bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::SyntheticChildrenSP &format_sp) { - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) { - if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject &valobj(match_data.GetValueObject()); - bool result = - m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp); - } - return result; +template <> +auto &LanguageCategory::GetHardcodedFinder<lldb::TypeSummaryImplSP>() { + return m_hardcoded_summaries; } -bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::TypeValidatorImplSP &format_sp) { - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) { - if (m_format_cache.GetValidator(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject &valobj(match_data.GetValueObject()); - bool result = - m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp); - } - return result; +template <> +auto &LanguageCategory::GetHardcodedFinder<lldb::SyntheticChildrenSP>() { + return m_hardcoded_synthetics; } +template <typename ImplSP> bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, - lldb::TypeFormatImplSP &format_sp) { + ImplSP &retval_sp) { if (!IsEnabled()) return false; ValueObject &valobj(match_data.GetValueObject()); lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - for (auto &candidate : m_hardcoded_formats) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) + for (auto &candidate : GetHardcodedFinder<ImplSP>()) { + if (auto result = candidate(valobj, use_dynamic, fmt_mgr)) { + retval_sp = result; break; + } } - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; -} - -bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, - FormattersMatchData &match_data, - lldb::TypeSummaryImplSP &format_sp) { - if (!IsEnabled()) - return false; - - ValueObject &valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto &candidate : m_hardcoded_summaries) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; -} - -bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, - FormattersMatchData &match_data, - lldb::SyntheticChildrenSP &format_sp) { - if (!IsEnabled()) - return false; - - ValueObject &valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto &candidate : m_hardcoded_synthetics) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; + return (bool)retval_sp; } -bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, - FormattersMatchData &match_data, - lldb::TypeValidatorImplSP &format_sp) { - if (!IsEnabled()) - return false; - - ValueObject &valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto &candidate : m_hardcoded_validators) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; -} +/// Explicit instantiations for the three types. +/// \{ +template bool LanguageCategory::GetHardcoded<lldb::TypeFormatImplSP>( + FormatManager &, FormattersMatchData &, lldb::TypeFormatImplSP &); +template bool LanguageCategory::GetHardcoded<lldb::TypeSummaryImplSP>( + FormatManager &, FormattersMatchData &, lldb::TypeSummaryImplSP &); +template bool LanguageCategory::GetHardcoded<lldb::SyntheticChildrenSP>( + FormatManager &, FormattersMatchData &, lldb::SyntheticChildrenSP &); +/// \} lldb::TypeCategoryImplSP LanguageCategory::GetCategory() const { return m_category_sp; diff --git a/lldb/source/DataFormatters/TypeCategory.cpp b/lldb/source/DataFormatters/TypeCategory.cpp index fed2dfb3c7c5b..85699691f52ba 100644 --- a/lldb/source/DataFormatters/TypeCategory.cpp +++ b/lldb/source/DataFormatters/TypeCategory.cpp @@ -13,18 +13,13 @@ using namespace lldb; using namespace lldb_private; -TypeCategoryImpl::TypeCategoryImpl( - IFormatChangeListener *clist, ConstString name, - std::initializer_list<lldb::LanguageType> langs) +TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener *clist, + ConstString name) : m_format_cont("format", "regex-format", clist), m_summary_cont("summary", "regex-summary", clist), m_filter_cont("filter", "regex-filter", clist), - m_synth_cont("synth", "regex-synth", clist), - m_validator_cont("validator", "regex-validator", clist), m_enabled(false), - m_change_listener(clist), m_mutex(), m_name(name), m_languages() { - for (const lldb::LanguageType lang : langs) - AddLanguage(lang); -} + m_synth_cont("synth", "regex-synth", clist), m_enabled(false), + m_change_listener(clist), m_mutex(), m_name(name), m_languages() {} static bool IsApplicable(lldb::LanguageType category_lang, lldb::LanguageType valobj_lang) { @@ -64,11 +59,10 @@ static bool IsApplicable(lldb::LanguageType category_lang, } } -bool TypeCategoryImpl::IsApplicable(ValueObject &valobj) { - lldb::LanguageType valobj_lang = valobj.GetObjectRuntimeLanguage(); +bool TypeCategoryImpl::IsApplicable(lldb::LanguageType lang) { for (size_t idx = 0; idx < GetNumLanguages(); idx++) { const lldb::LanguageType category_lang = GetLanguageAtIndex(idx); - if (::IsApplicable(category_lang, valobj_lang)) + if (::IsApplicable(category_lang, lang)) return true; } return false; @@ -90,16 +84,10 @@ void TypeCategoryImpl::AddLanguage(lldb::LanguageType lang) { m_languages.push_back(lang); } -bool TypeCategoryImpl::HasLanguage(lldb::LanguageType lang) { - const auto iter = std::find(m_languages.begin(), m_languages.end(), lang), - end = m_languages.end(); - return (iter != end); -} - -bool TypeCategoryImpl::Get(ValueObject &valobj, +bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, lldb::TypeFormatImplSP &entry, uint32_t *reason) { - if (!IsEnabled() || !IsApplicable(valobj)) + if (!IsEnabled() || !IsApplicable(lang)) return false; if (GetTypeFormatsContainer()->Get(candidates, entry, reason)) return true; @@ -109,10 +97,10 @@ bool TypeCategoryImpl::Get(ValueObject &valobj, return regex; } -bool TypeCategoryImpl::Get(ValueObject &valobj, +bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, lldb::TypeSummaryImplSP &entry, uint32_t *reason) { - if (!IsEnabled() || !IsApplicable(valobj)) + if (!IsEnabled() || !IsApplicable(lang)) return false; if (GetTypeSummariesContainer()->Get(candidates, entry, reason)) return true; @@ -122,10 +110,10 @@ bool TypeCategoryImpl::Get(ValueObject &valobj, return regex; } -bool TypeCategoryImpl::Get(ValueObject &valobj, +bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, lldb::SyntheticChildrenSP &entry, uint32_t *reason) { - if (!IsEnabled() || !IsApplicable(valobj)) + if (!IsEnabled() || !IsApplicable(lang)) return false; TypeFilterImpl::SharedPointer filter_sp; uint32_t reason_filter = 0; @@ -169,20 +157,6 @@ bool TypeCategoryImpl::Get(ValueObject &valobj, return false; } -bool TypeCategoryImpl::Get(ValueObject &valobj, - const FormattersMatchVector &candidates, - lldb::TypeValidatorImplSP &entry, uint32_t *reason) { - if (!IsEnabled()) - return false; - if (GetTypeValidatorsContainer()->Get(candidates, entry, reason)) - return true; - bool regex = - GetRegexTypeValidatorsContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; - return regex; -} - void TypeCategoryImpl::Clear(FormatCategoryItems items) { if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue) GetTypeFormatsContainer()->Clear(); @@ -205,12 +179,6 @@ void TypeCategoryImpl::Clear(FormatCategoryItems items) { GetTypeSyntheticsContainer()->Clear(); if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth) GetRegexTypeSyntheticsContainer()->Clear(); - - if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) - GetTypeValidatorsContainer()->Clear(); - if ((items & eFormatCategoryItemRegexValidator) == - eFormatCategoryItemRegexValidator) - GetRegexTypeValidatorsContainer()->Clear(); } bool TypeCategoryImpl::Delete(ConstString name, FormatCategoryItems items) { @@ -238,12 +206,6 @@ bool TypeCategoryImpl::Delete(ConstString name, FormatCategoryItems items) { if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth) success = GetRegexTypeSyntheticsContainer()->Delete(name) || success; - if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) - success = GetTypeValidatorsContainer()->Delete(name) || success; - if ((items & eFormatCategoryItemRegexValidator) == - eFormatCategoryItemRegexValidator) - success = GetRegexTypeValidatorsContainer()->Delete(name) || success; - return success; } @@ -272,12 +234,6 @@ uint32_t TypeCategoryImpl::GetCount(FormatCategoryItems items) { if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth) count += GetRegexTypeSyntheticsContainer()->GetCount(); - if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) - count += GetTypeValidatorsContainer()->GetCount(); - if ((items & eFormatCategoryItemRegexValidator) == - eFormatCategoryItemRegexValidator) - count += GetRegexTypeValidatorsContainer()->GetCount(); - return count; } @@ -292,7 +248,6 @@ bool TypeCategoryImpl::AnyMatches(ConstString type_name, lldb::TypeSummaryImplSP summary_sp; TypeFilterImpl::SharedPointer filter_sp; ScriptedSyntheticChildren::SharedPointer synth_sp; - TypeValidatorImpl::SharedPointer validator_sp; if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue) { if (GetTypeFormatsContainer()->Get(type_name, format_sp)) { @@ -374,26 +329,6 @@ bool TypeCategoryImpl::AnyMatches(ConstString type_name, } } - if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) { - if (GetTypeValidatorsContainer()->Get(type_name, validator_sp)) { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemValidator; - return true; - } - } - if ((items & eFormatCategoryItemRegexValidator) == - eFormatCategoryItemRegexValidator) { - if (GetRegexTypeValidatorsContainer()->Get(type_name, validator_sp)) { - if (matching_category) - *matching_category = m_name.GetCString(); - if (matching_type) - *matching_type = eFormatCategoryItemRegexValidator; - return true; - } - } - return false; } @@ -461,22 +396,6 @@ TypeCategoryImpl::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { return retval; } -TypeCategoryImpl::ValidatorContainer::MapValueType -TypeCategoryImpl::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) { - ValidatorContainer::MapValueType retval; - - if (type_sp) { - if (type_sp->IsRegex()) - GetRegexTypeValidatorsContainer()->GetExact( - ConstString(type_sp->GetName()), retval); - else - GetTypeValidatorsContainer()->GetExact(ConstString(type_sp->GetName()), - retval); - } - - return retval; -} - lldb::TypeNameSpecifierImplSP TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex(size_t index) { if (index < GetTypeSummariesContainer()->GetCount()) @@ -549,24 +468,6 @@ TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex(size_t index) { index - GetTypeSyntheticsContainer()->GetCount()); } -TypeCategoryImpl::ValidatorContainer::MapValueType -TypeCategoryImpl::GetValidatorAtIndex(size_t index) { - if (index < GetTypeValidatorsContainer()->GetCount()) - return GetTypeValidatorsContainer()->GetAtIndex(index); - else - return GetRegexTypeValidatorsContainer()->GetAtIndex( - index - GetTypeValidatorsContainer()->GetCount()); -} - -lldb::TypeNameSpecifierImplSP -TypeCategoryImpl::GetTypeNameSpecifierForValidatorAtIndex(size_t index) { - if (index < GetTypeValidatorsContainer()->GetCount()) - return GetTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(index); - else - return GetRegexTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex( - index - GetTypeValidatorsContainer()->GetCount()); -} - void TypeCategoryImpl::Enable(bool value, uint32_t position) { std::lock_guard<std::recursive_mutex> guard(m_mutex); if ((m_enabled = value)) diff --git a/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp index b1075e9878d87..ac515154299a2 100644 --- a/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/lldb/source/DataFormatters/TypeCategoryMap.cpp @@ -169,8 +169,8 @@ bool TypeCategoryMap::AnyMatches( return false; } -lldb::TypeFormatImplSP -TypeCategoryMap::GetFormat(FormattersMatchData &match_data) { +template <typename ImplSP> +void TypeCategoryMap::Get(FormattersMatchData &match_data, ImplSP &retval) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); uint32_t reason_why; @@ -182,8 +182,8 @@ TypeCategoryMap::GetFormat(FormattersMatchData &match_data) { for (auto match : match_data.GetMatchesVector()) { LLDB_LOGF( log, - "[CategoryMap::GetFormat] candidate match = %s %s %s %s reason = " - "%" PRIu32, + "[%s] candidate match = %s %s %s %s reason = %" PRIu32, + __FUNCTION__, match.GetTypeName().GetCString(), match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", match.DidStripReference() ? "strip-reference" : "no-strip-reference", @@ -194,140 +194,31 @@ TypeCategoryMap::GetFormat(FormattersMatchData &match_data) { for (begin = m_active_categories.begin(); begin != end; begin++) { lldb::TypeCategoryImplSP category_sp = *begin; - lldb::TypeFormatImplSP current_format; - LLDB_LOGF(log, "[TypeCategoryMap::GetFormat] Trying to use category %s", + ImplSP current_format; + LLDB_LOGF(log, "[%s] Trying to use category %s", __FUNCTION__, category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), - match_data.GetMatchesVector(), current_format, - &reason_why)) + if (!category_sp->Get( + match_data.GetValueObject().GetObjectRuntimeLanguage(), + match_data.GetMatchesVector(), current_format, &reason_why)) continue; - return current_format; - } - LLDB_LOGF(log, - "[TypeCategoryMap::GetFormat] nothing found - returning empty SP"); - return lldb::TypeFormatImplSP(); -} - -lldb::TypeSummaryImplSP -TypeCategoryMap::GetSummaryFormat(FormattersMatchData &match_data) { - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - - uint32_t reason_why; - ActiveCategoriesIterator begin, end = m_active_categories.end(); - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); - - if (log) { - for (auto match : match_data.GetMatchesVector()) { - LLDB_LOGF( - log, - "[CategoryMap::GetSummaryFormat] candidate match = %s %s %s %s " - "reason = %" PRIu32, - match.GetTypeName().GetCString(), - match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", - match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); - } + retval = std::move(current_format); + return; } - - for (begin = m_active_categories.begin(); begin != end; begin++) { - lldb::TypeCategoryImplSP category_sp = *begin; - lldb::TypeSummaryImplSP current_format; - LLDB_LOGF(log, "[CategoryMap::GetSummaryFormat] Trying to use category %s", - category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), - match_data.GetMatchesVector(), current_format, - &reason_why)) - continue; - return current_format; - } - LLDB_LOGF( - log, - "[CategoryMap::GetSummaryFormat] nothing found - returning empty SP"); - return lldb::TypeSummaryImplSP(); + LLDB_LOGF(log, "[%s] nothing found - returning empty SP", __FUNCTION__); } -lldb::SyntheticChildrenSP -TypeCategoryMap::GetSyntheticChildren(FormattersMatchData &match_data) { - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - - uint32_t reason_why; - - ActiveCategoriesIterator begin, end = m_active_categories.end(); - - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); - - if (log) { - for (auto match : match_data.GetMatchesVector()) { - LLDB_LOGF( - log, - "[CategoryMap::GetSyntheticChildren] candidate match = %s %s %s %s " - "reason = %" PRIu32, - match.GetTypeName().GetCString(), - match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", - match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); - } - } - - for (begin = m_active_categories.begin(); begin != end; begin++) { - lldb::TypeCategoryImplSP category_sp = *begin; - lldb::SyntheticChildrenSP current_format; - LLDB_LOGF(log, - "[CategoryMap::GetSyntheticChildren] Trying to use category %s", - category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), - match_data.GetMatchesVector(), current_format, - &reason_why)) - continue; - return current_format; - } - LLDB_LOGF(log, - "[CategoryMap::GetSyntheticChildren] nothing found - returning " - "empty SP"); - return lldb::SyntheticChildrenSP(); -} - -lldb::TypeValidatorImplSP -TypeCategoryMap::GetValidator(FormattersMatchData &match_data) { - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - - uint32_t reason_why; - ActiveCategoriesIterator begin, end = m_active_categories.end(); - - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); - - if (log) { - for (auto match : match_data.GetMatchesVector()) { - LLDB_LOGF( - log, - "[CategoryMap::GetValidator] candidate match = %s %s %s %s reason = " - "%" PRIu32, - match.GetTypeName().GetCString(), - match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", - match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); - } - } - - for (begin = m_active_categories.begin(); begin != end; begin++) { - lldb::TypeCategoryImplSP category_sp = *begin; - lldb::TypeValidatorImplSP current_format; - LLDB_LOGF(log, "[CategoryMap::GetValidator] Trying to use category %s", - category_sp->GetName()); - if (!category_sp->Get(match_data.GetValueObject(), - match_data.GetMatchesVector(), current_format, - &reason_why)) - continue; - return current_format; - } - LLDB_LOGF(log, - "[CategoryMap::GetValidator] nothing found - returning empty SP"); - return lldb::TypeValidatorImplSP(); -} +/// Explicit instantiations for the three types. +/// \{ +template void +TypeCategoryMap::Get<lldb::TypeFormatImplSP>(FormattersMatchData &match_data, + lldb::TypeFormatImplSP &retval); +template void +TypeCategoryMap::Get<lldb::TypeSummaryImplSP>(FormattersMatchData &match_data, + lldb::TypeSummaryImplSP &retval); +template void TypeCategoryMap::Get<lldb::SyntheticChildrenSP>( + FormattersMatchData &match_data, lldb::SyntheticChildrenSP &retval); +/// \} void TypeCategoryMap::ForEach(ForEachCallback callback) { if (callback) { diff --git a/lldb/source/DataFormatters/TypeValidator.cpp b/lldb/source/DataFormatters/TypeValidator.cpp deleted file mode 100644 index 5ce24cacfb555..0000000000000 --- a/lldb/source/DataFormatters/TypeValidator.cpp +++ /dev/null @@ -1,53 +0,0 @@ -//===-- TypeValidator.cpp ---------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - - - - -#include "lldb/DataFormatters/TypeValidator.h" -#include "lldb/Utility/StreamString.h" - -using namespace lldb; -using namespace lldb_private; - -TypeValidatorImpl::TypeValidatorImpl(const Flags &flags) - : m_flags(flags), m_my_revision(0) {} - -TypeValidatorImpl::~TypeValidatorImpl() {} - -TypeValidatorImpl::ValidationResult TypeValidatorImpl::Success() { - return ValidationResult{TypeValidatorResult::Success, ""}; -} - -TypeValidatorImpl::ValidationResult -TypeValidatorImpl::Failure(std::string message) { - return ValidationResult{TypeValidatorResult::Failure, message}; -} - -TypeValidatorImpl_CXX::TypeValidatorImpl_CXX( - ValidatorFunction f, std::string d, const TypeValidatorImpl::Flags &flags) - : TypeValidatorImpl(flags), m_description(d), m_validator_function(f) {} - -TypeValidatorImpl_CXX::~TypeValidatorImpl_CXX() {} - -TypeValidatorImpl::ValidationResult -TypeValidatorImpl_CXX::FormatObject(ValueObject *valobj) const { - if (!valobj) - return Success(); // I guess there's nothing wrong with a null valueobject.. - - return m_validator_function(valobj); -} - -std::string TypeValidatorImpl_CXX::GetDescription() { - StreamString sstr; - sstr.Printf("%s%s%s%s", m_description.c_str(), - Cascades() ? "" : " (not cascading)", - SkipsPointers() ? " (skip pointers)" : "", - SkipsReferences() ? " (skip references)" : ""); - return sstr.GetString(); -} diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp index fa43c677a1940..466cf398ec24c 100644 --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -75,8 +75,6 @@ bool ValueObjectPrinter::PrintValueObject() { return false; if (ShouldPrintValueObject()) { - PrintValidationMarkerIfNeeded(); - PrintLocationIfNeeded(); m_stream->Indent(); @@ -94,8 +92,6 @@ bool ValueObjectPrinter::PrintValueObject() { else m_stream->EOL(); - PrintValidationErrorIfNeeded(); - return true; } @@ -790,37 +786,3 @@ void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed, } else m_stream->EOL(); } - -bool ValueObjectPrinter::ShouldPrintValidation() { - return m_options.m_run_validator; -} - -bool ValueObjectPrinter::PrintValidationMarkerIfNeeded() { - if (!ShouldPrintValidation()) - return false; - - m_validation = m_valobj->GetValidationStatus(); - - if (TypeValidatorResult::Failure == m_validation.first) { - m_stream->Printf("! "); - return true; - } - - return false; -} - -bool ValueObjectPrinter::PrintValidationErrorIfNeeded() { - if (!ShouldPrintValidation()) - return false; - - if (TypeValidatorResult::Success == m_validation.first) - return false; - - if (m_validation.second.empty()) - m_validation.second.assign("unknown error"); - - m_stream->Printf(" ! validation error: %s", m_validation.second.c_str()); - m_stream->EOL(); - - return true; -} |
