Sfoglia il codice sorgente

Switch back to `std::abort()` in `CARBON_CHECK`. (#1341)

This is a variation on #1339 and also fixes #1338.

The important difference from #1339 is that this works to retain the
benefits of #1216 which seem important -- both the clarity of printing
the message last and the correctness of actually showing the correct
line number in the backtrace.

The approach in this patch is to disable LLVM's error handling just
before using `std::abort()`. This should give us roughly the best of
both worlds.

This PR also fixes an issue where we wouldn't run the file-cleanup
actions that the LLVM `std::abort()` handler does. This almost certainly
doesn't yet matter, but likely would in the future.

We should separately consider adding back information about filing bugs
that roughly corresponds to the error message that LLVM itself prints.
I've not tried to replicate that from #1339 here and just focused on
getting to `std::abort()` while preserving the desired order of messages
and stack trace locations.
Chandler Carruth 3 anni fa
parent
commit
282bac207e
1 ha cambiato i file con 12 aggiunte e 4 eliminazioni
  1. 12 4
      common/check_internal.h

+ 12 - 4
common/check_internal.h

@@ -26,7 +26,10 @@ class ExitingStream {
   struct Helper {};
 
   ExitingStream() {
-    // Start all messages with a stack trace.
+    // Start all messages with a stack trace. Printing this first ensures the
+    // error message is the last thing written which makes it easier to find. It
+    // also helps ensure we report the most useful stack trace and location
+    // information.
     llvm::errs() << "Stack trace:\n";
     llvm::sys::PrintStackTrace(llvm::errs());
   }
@@ -66,9 +69,14 @@ class ExitingStream {
     // Finish with a newline.
     llvm::errs() << "\n";
     // We assume LLVM's exit handling is installed, which will stack trace on
-    // std::abort(). We print a stack trace on construction, so this avoids that
-    // stack trace on exit.
-    _exit(1);
+    // `std::abort()`. We print a more user friendly stack trace on
+    // construction, but it is still useful to exit the program with
+    // `std::abort()` for integration with debuggers and other tools. We also
+    // want to do any pending cleanups. So we replicate the signal handling here
+    // and unregister LLVM's handlers right before we abort.
+    llvm::sys::RunInterruptHandlers();
+    llvm::sys::unregisterHandlers();
+    std::abort();
   }
 
  private: