[Symbol] Improve Variable::GetLanguage
authorAlex Langford <apl@fb.com>
Mon, 22 Jul 2019 20:14:18 +0000 (20:14 +0000)
committerAlex Langford <apl@fb.com>
Mon, 22 Jul 2019 20:14:18 +0000 (20:14 +0000)
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
lldb/source/Symbol/Variable.cpp

index 297365b..57bc8ae 100644 (file)
@@ -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;
 
index 29a7a51..d864011 100644 (file)
@@ -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;
 }