Fix crash exposed by r328025
authorPavel Labath <labath@google.com>
Wed, 21 Mar 2018 11:10:57 +0000 (11:10 +0000)
committerPavel Labath <labath@google.com>
Wed, 21 Mar 2018 11:10:57 +0000 (11:10 +0000)
The issue was that the ASTDumper was being passed a null pointer
(because we did not create any declaration for the operator==).  The
crash was in logging code, so it only manifested it self if you ran the
tests with logging enabled (like our bots do).

Given that this is logging code and the rest of the debugger is fine
with the declaration being null, I just make sure the logging code can
handle it as well. Right now I just do the null check in
ClangExpressionDeclMap, but if the ASTDumper class is meant to be a
debugging/logging aid, then it might be a good idea move the check
inside the class itself.

llvm-svn: 328088

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

index 07ff2e97aac77d07bb98ea4280ee4be413b11141..8a39e720eabae25ec7ca5f9ab324ef15a4122046 100644 (file)
@@ -2116,7 +2116,8 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
   parser_vars->m_llvm_value = NULL;
 
   if (log) {
-    ASTDumper ast_dumper(function_decl);
+    std::string function_str =
+        function_decl ? ASTDumper(function_decl).GetCString() : "nullptr";
 
     StreamString ss;
 
@@ -2127,7 +2128,7 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
     log->Printf(
         "  CEDM::FEVD[%u] Found %s function %s (description %s), returned %s",
         current_id, (function ? "specific" : "generic"), decl_name.c_str(),
-        ss.GetData(), ast_dumper.GetCString());
+        ss.GetData(), function_str.c_str());
   }
 }