[Lldb-commits] [lldb] r362032 - [Target] Sink some asserts into Process::GetLanguageRuntime

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Wed May 29 14:07:54 PDT 2019


Author: xiaobai
Date: Wed May 29 14:07:53 2019
New Revision: 362032

URL: http://llvm.org/viewvc/llvm-project?rev=362032&view=rev
Log:
[Target] Sink some asserts into Process::GetLanguageRuntime

Modified:
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=362032&r1=362031&r2=362032&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed May 29 14:07:53 2019
@@ -1574,17 +1574,28 @@ LanguageRuntime *Process::GetLanguageRun
   if (m_finalizing)
     return nullptr;
 
+  LanguageRuntime *runtime = nullptr;
+
   std::lock_guard<std::recursive_mutex> guard(m_language_runtimes_mutex);
   LanguageRuntimeCollection::iterator pos;
   pos = m_language_runtimes.find(language);
-  if (pos == m_language_runtimes.end() || (retry_if_null && !(*pos).second)) {
+  if (pos == m_language_runtimes.end() || (retry_if_null && !pos->second)) {
     lldb::LanguageRuntimeSP runtime_sp(
         LanguageRuntime::FindPlugin(this, language));
 
     m_language_runtimes[language] = runtime_sp;
-    return runtime_sp.get();
+    runtime = runtime_sp.get();
   } else
-    return (*pos).second.get();
+    runtime = pos->second.get();
+
+  if (runtime)
+    // It's possible that a language runtime can support multiple LanguageTypes,
+    // for example, CPPLanguageRuntime will support eLanguageTypeC_plus_plus,
+    // eLanguageTypeC_plus_plus_03, etc. Because of this, we should get the
+    // primary language type and make sure that our runtime supports it.
+    assert(runtime->GetLanguageType() == Language::GetPrimaryLanguage(language));
+
+  return runtime;
 }
 
 CPPLanguageRuntime *Process::GetCPPLanguageRuntime(bool retry_if_null) {
@@ -1594,7 +1605,6 @@ CPPLanguageRuntime *Process::GetCPPLangu
   if (!runtime)
     return nullptr;
 
-  assert(runtime->GetLanguageType() == eLanguageTypeC_plus_plus);
   return static_cast<CPPLanguageRuntime *>(runtime);
 }
 
@@ -1605,7 +1615,6 @@ ObjCLanguageRuntime *Process::GetObjCLan
   if (!runtime)
     return nullptr;
 
-  assert(runtime->GetLanguageType() == eLanguageTypeObjC);
   return static_cast<ObjCLanguageRuntime *>(runtime);
 }
 




More information about the lldb-commits mailing list