From 4de5d9d61213d2b69557cb969862412d743114f7 Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Mon, 22 Jul 2019 20:14:18 +0000 Subject: [PATCH] [Symbol] Improve Variable::GetLanguage Summary: When trying to ascertain what language a variable belongs to, just checking the compilation unit is often not enough. In r364845 I added a way to check for a variable's language type, but didn't put it in Variable itself. Let's go ahead and put it in Variable. Reviewers: jingham, clayborg Subscribers: jdoerfert, lldb-commits Differential Revision: https://reviews.llvm.org/D64042 llvm-svn: 366733 --- lldb/source/Core/ValueObject.cpp | 11 +---------- lldb/source/Symbol/Variable.cpp | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 297365b4ecbd6..57bc8aebc8be0 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1672,16 +1672,7 @@ bool ValueObject::IsRuntimeSupportValue() { if (!GetVariable() || !GetVariable()->IsArtificial()) return false; - LanguageType lang = eLanguageTypeUnknown; - if (auto *sym_ctx_scope = GetSymbolContextScope()) { - if (auto *func = sym_ctx_scope->CalculateSymbolContextFunction()) - lang = func->GetLanguage(); - else if (auto *comp_unit = - sym_ctx_scope->CalculateSymbolContextCompileUnit()) - lang = comp_unit->GetLanguage(); - } - - if (auto *runtime = process->GetLanguageRuntime(lang)) + if (auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage())) if (runtime->IsWhitelistedRuntimeValue(GetName())) return false; diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp index 29a7a5191f610..d86401178d5d3 100644 --- a/lldb/source/Symbol/Variable.cpp +++ b/lldb/source/Symbol/Variable.cpp @@ -54,10 +54,19 @@ Variable::Variable( Variable::~Variable() {} lldb::LanguageType Variable::GetLanguage() const { - SymbolContext variable_sc; - m_owner_scope->CalculateSymbolContext(&variable_sc); - if (variable_sc.comp_unit) - return variable_sc.comp_unit->GetLanguage(); + lldb::LanguageType lang = m_mangled.GuessLanguage(); + if (lang != lldb::eLanguageTypeUnknown) + return lang; + + if (auto *func = m_owner_scope->CalculateSymbolContextFunction()) { + if ((lang = func->GetLanguage()) && lang != lldb::eLanguageTypeUnknown) + return lang; + else if (auto *comp_unit = + m_owner_scope->CalculateSymbolContextCompileUnit()) + if ((lang = func->GetLanguage()) && lang != lldb::eLanguageTypeUnknown) + return lang; + } + return lldb::eLanguageTypeUnknown; }