[lldb] Avoid confusing reproducer crashes when initialization failed
authorJonas Devlieghere <jonas@devlieghere.com>
Mon, 9 Nov 2020 16:47:08 +0000 (08:47 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Mon, 9 Nov 2020 16:50:10 +0000 (08:50 -0800)
During active replay, the ::Initialize call is replayed like any other
SB API call and the return value is ignored. Since we can't intercept
this, we terminate here before the uninitialized debugger inevitably
crashes.

Differential revision: https://reviews.llvm.org/D90987

lldb/source/API/SystemInitializerFull.cpp

index a9723f7..cd5b464 100644 (file)
@@ -15,6 +15,7 @@
 #include "lldb/Initialization/SystemInitializerCommon.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Target/ProcessTrace.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/TargetSelect.h"
 
@@ -34,8 +35,16 @@ SystemInitializerFull::SystemInitializerFull() = default;
 SystemInitializerFull::~SystemInitializerFull() = default;
 
 llvm::Error SystemInitializerFull::Initialize() {
-  if (auto e = SystemInitializerCommon::Initialize())
-    return e;
+  llvm::Error error = SystemInitializerCommon::Initialize();
+  if (error) {
+    // During active replay, the ::Initialize call is replayed like any other
+    // SB API call and the return value is ignored. Since we can't intercept
+    // this, we terminate here before the uninitialized debugger inevitably
+    // crashes.
+    if (repro::Reproducer::Instance().IsReplaying())
+      llvm::report_fatal_error("system initialization failed");
+    return error;
+  }
 
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();