diff options
Diffstat (limited to 'lldb/source/DataFormatters/FormatManager.cpp')
-rw-r--r-- | lldb/source/DataFormatters/FormatManager.cpp | 357 |
1 files changed, 71 insertions, 286 deletions
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index 1eac372d79ec..d5db3ee75bf3 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() |