[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
Wed Aug 22 15:51:25 PDT 2018
sgraenitz created this revision.
sgraenitz added a reviewer: lhames.
Small debugging utility to stop immediately when an Error occurs and not only in `abort()` far up the stack.
Enable/disable in your debug session with one of these:
(lldb) expr BreakOnError = true
(lldb) expr llvm::Error::BreakOnError = true
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 LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
+bool Error::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
@@ -280,6 +280,12 @@
(reinterpret_cast<uintptr_t>(EI) &
~static_cast<uintptr_t>(0x1)) |
(reinterpret_cast<uintptr_t>(Payload) & 0x1));
+
+# if !defined(NDEBUG)
+ if (BreakOnError && EI != nullptr) {
+ LLVM_BUILTIN_DEBUGTRAP;
+ }
+# endif
#else
Payload = EI;
#endif
@@ -316,6 +322,11 @@
}
ErrorInfoBase *Payload = nullptr;
+
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
+ // Set to true in debug sessions to immediately break when an error occcurs.
+ static bool BreakOnError;
+#endif
};
/// Subclass of Error for the sole purpose of identifying the success path in
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51138.162085.patch
Type: text/x-patch
Size: 1252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180822/9124f1fc/attachment-0001.bin>
More information about the llvm-commits
mailing list