diff options
author | Adrian Prantl <aprantl@apple.com> | 2019-12-09 16:38:19 -0800 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2019-12-10 15:53:40 -0800 |
commit | 62a6d9770450f93a2dcdf04710a73341af2f54fa (patch) | |
tree | 6f0b5fff1b91d2f203db94cf1bd5dd0606e54906 /lldb/source/DataFormatters/FormatManager.cpp | |
parent | 44c167ace998b41b7f8cbe6acd283c8ba9b0b5a3 (diff) | |
download | llvm-62a6d9770450f93a2dcdf04710a73341af2f54fa.zip llvm-62a6d9770450f93a2dcdf04710a73341af2f54fa.tar.gz llvm-62a6d9770450f93a2dcdf04710a73341af2f54fa.tar.bz2 |
Do not cache hardcoded formats in FormatManager
The cache in FormatCache uses only a type name as key. The hardcoded
formats, synthetic children, etc inspect an entire ValueObject to
determine their eligibility, which isn't modelled in the cache. This
leads to bugs such as the one in this patch (where two similarly named
types in different files have different hardcoded summary
providers). The problem is exaggerated in the Swift language plugin
due to the language's dynamic nature.
rdar://problem/57756763
Differential Revision: https://reviews.llvm.org/D71233
Diffstat (limited to 'lldb/source/DataFormatters/FormatManager.cpp')
-rw-r--r-- | lldb/source/DataFormatters/FormatManager.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index c8ddbd4..db15a7f 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -622,11 +622,21 @@ ImplSP FormatManager::GetHardcoded(FormattersMatchData &match_data) { return retval_sp; } -template <typename ImplSP> ImplSP -FormatManager::GetCached(ValueObject &valobj, - lldb::DynamicValueType use_dynamic) { - ImplSP retval_sp; +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; + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); + LLDB_LOGF(log, "[%s] Search failed. Giving hardcoded a chance.", __FUNCTION__); + return GetHardcoded<ImplSP>(match_data); +} + +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[%s] Looking into cache for type %s", __FUNCTION__, @@ -659,10 +669,6 @@ FormatManager::GetCached(ValueObject &valobj, return retval_sp; } } - if (!retval_sp) { - LLDB_LOGF(log, "[%s] Search failed. Giving hardcoded a chance.", __FUNCTION__); - retval_sp = GetHardcoded<ImplSP>(match_data); - } if (match_data.GetTypeForCache() && (!retval_sp || !retval_sp->NonCacheable())) { LLDB_LOGF(log, "[%s] Caching %p for type %s", __FUNCTION__, @@ -678,25 +684,25 @@ FormatManager::GetCached(ValueObject &valobj, lldb::TypeFormatImplSP FormatManager::GetFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic) { - return GetCached<lldb::TypeFormatImplSP>(valobj, use_dynamic); + return Get<lldb::TypeFormatImplSP>(valobj, use_dynamic); } lldb::TypeSummaryImplSP FormatManager::GetSummaryFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic) { - return GetCached<lldb::TypeSummaryImplSP>(valobj, use_dynamic); + return Get<lldb::TypeSummaryImplSP>(valobj, use_dynamic); } lldb::SyntheticChildrenSP FormatManager::GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic) { - return GetCached<lldb::SyntheticChildrenSP>(valobj, use_dynamic); + return Get<lldb::SyntheticChildrenSP>(valobj, use_dynamic); } lldb::TypeValidatorImplSP FormatManager::GetValidator(ValueObject &valobj, lldb::DynamicValueType use_dynamic) { - return GetCached<lldb::TypeValidatorImplSP>(valobj, use_dynamic); + return Get<lldb::TypeValidatorImplSP>(valobj, use_dynamic); } FormatManager::FormatManager() |