[PATCH] D51138: [Error] Add runtime flag BreakOnError and a debug trap in the Error class

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 23 09:26:02 PDT 2018


sgraenitz updated this revision to Diff 162202.
sgraenitz added a comment.

Move BreakOnError check to ErrorInfoBase constructor


Repository:
  rL LLVM

https://reviews.llvm.org/D51138

Files:
  include/llvm/Support/Error.h
  lib/Support/Error.cpp


Index: lib/Support/Error.cpp
===================================================================
--- lib/Support/Error.cpp
+++ lib/Support/Error.cpp
@@ -54,6 +54,10 @@
 char ECError::ID = 0;
 char StringError::ID = 0;
 
+#if !defined(NDEBUG)
+bool ErrorInfoBase::BreakOnError = false;
+#endif
+
 void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) {
   if (!E)
     return;
Index: include/llvm/Support/Error.h
===================================================================
--- include/llvm/Support/Error.h
+++ include/llvm/Support/Error.h
@@ -48,6 +48,14 @@
 /// the ErrorInfo template subclass instead.
 class ErrorInfoBase {
 public:
+  ErrorInfoBase() {
+#if !defined(NDEBUG)
+    if (BreakOnError) {
+      LLVM_BUILTIN_DEBUGTRAP;
+    }
+#endif
+  }
+
   virtual ~ErrorInfoBase() = default;
 
   /// Print an error message to an output stream.
@@ -88,6 +96,11 @@
   virtual void anchor();
 
   static char ID;
+
+#if !defined(NDEBUG)
+  // Set to true in debug sessions to immediately break when an error occcurs.
+  static bool BreakOnError;
+#endif
 };
 
 /// Lightweight error class with error context and mandatory checking.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51138.162202.patch
Type: text/x-patch
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180823/68b6cb0d/attachment.bin>


More information about the llvm-commits mailing list