Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Unified Diff: runtime/vm/exceptions.cc

Issue 1654153002: Introduce a flag to force program abort on type/assertion errors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/exceptions.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/exceptions.cc
diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc
index 99563bb3d07387c1a577b4e3a47cc668214222ad..3ef19c9b1605ab82cfbe856f98836181415c4d19 100644
--- a/runtime/vm/exceptions.cc
+++ b/runtime/vm/exceptions.cc
@@ -19,6 +19,8 @@
namespace dart {
+DEFINE_FLAG(bool, abort_on_assertion_errors, false,
+ "Abort on assertion and typecheck failures");
DEFINE_FLAG(bool, print_stacktrace_at_throw, false,
"Prints a stack trace everytime a throw occurs.");
@@ -457,7 +459,7 @@ void Exceptions::CreateAndThrowTypeError(intptr_t location,
// Type errors in the core library may be difficult to diagnose.
// Print type error information before throwing the error when debugging.
- if (FLAG_print_stacktrace_at_throw) {
+ if (FLAG_print_stacktrace_at_throw || FLAG_abort_on_assertion_errors) {
if (!error_msg.IsNull()) {
OS::Print("%s\n", error_msg.ToCString());
}
@@ -472,6 +474,11 @@ void Exceptions::CreateAndThrowTypeError(intptr_t location,
OS::Print("type error.\n");
}
}
+
+ if (FLAG_abort_on_assertion_errors) {
+ PrintStackTraceAndAbort("a type error");
+ }
+
// Throw TypeError or CastError instance.
Exceptions::ThrowByType(exception_type, args);
UNREACHABLE();
@@ -677,4 +684,14 @@ void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) {
Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args);
}
+
+void Exceptions::PrintStackTraceAndAbort(const char* reason) {
+ const Instance& stacktrace = Instance::Handle(CurrentStacktrace());
+
+ OS::PrintErr("\n\n\nAborting due to %s. Stacktrace:\n%s\n",
+ reason,
+ stacktrace.ToCString());
+ OS::Abort();
+}
+
} // namespace dart
« no previous file with comments | « runtime/vm/exceptions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698