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

Side by Side 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, 10 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/exceptions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/exceptions.h" 5 #include "vm/exceptions.h"
6 6
7 #include "platform/address_sanitizer.h" 7 #include "platform/address_sanitizer.h"
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
11 #include "vm/debugger.h" 11 #include "vm/debugger.h"
12 #include "vm/flags.h" 12 #include "vm/flags.h"
13 #include "vm/object.h" 13 #include "vm/object.h"
14 #include "vm/object_store.h" 14 #include "vm/object_store.h"
15 #include "vm/stack_frame.h" 15 #include "vm/stack_frame.h"
16 #include "vm/stub_code.h" 16 #include "vm/stub_code.h"
17 #include "vm/symbols.h" 17 #include "vm/symbols.h"
18 #include "vm/tags.h" 18 #include "vm/tags.h"
19 19
20 namespace dart { 20 namespace dart {
21 21
22 DEFINE_FLAG(bool, abort_on_assertion_errors, false,
23 "Abort on assertion and typecheck failures");
22 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, 24 DEFINE_FLAG(bool, print_stacktrace_at_throw, false,
23 "Prints a stack trace everytime a throw occurs."); 25 "Prints a stack trace everytime a throw occurs.");
24 26
25 27
26 const char* Exceptions::kCastErrorDstName = "type cast"; 28 const char* Exceptions::kCastErrorDstName = "type cast";
27 29
28 30
29 class StacktraceBuilder : public ValueObject { 31 class StacktraceBuilder : public ValueObject {
30 public: 32 public:
31 StacktraceBuilder() { } 33 StacktraceBuilder() { }
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 args.SetAt(2, Smi::Handle(Smi::New(column))); 452 args.SetAt(2, Smi::Handle(Smi::New(column)));
451 453
452 // Initialize '_srcType', '_dstType', '_dstName', and '_errorMsg'. 454 // Initialize '_srcType', '_dstType', '_dstName', and '_errorMsg'.
453 args.SetAt(3, src_type_name); 455 args.SetAt(3, src_type_name);
454 args.SetAt(4, dst_type_name); 456 args.SetAt(4, dst_type_name);
455 args.SetAt(5, dst_name); 457 args.SetAt(5, dst_name);
456 args.SetAt(6, error_msg); 458 args.SetAt(6, error_msg);
457 459
458 // Type errors in the core library may be difficult to diagnose. 460 // Type errors in the core library may be difficult to diagnose.
459 // Print type error information before throwing the error when debugging. 461 // Print type error information before throwing the error when debugging.
460 if (FLAG_print_stacktrace_at_throw) { 462 if (FLAG_print_stacktrace_at_throw || FLAG_abort_on_assertion_errors) {
461 if (!error_msg.IsNull()) { 463 if (!error_msg.IsNull()) {
462 OS::Print("%s\n", error_msg.ToCString()); 464 OS::Print("%s\n", error_msg.ToCString());
463 } 465 }
464 OS::Print("'%s': Failed type check: line %" Pd " pos %" Pd ": ", 466 OS::Print("'%s': Failed type check: line %" Pd " pos %" Pd ": ",
465 String::Handle(script.url()).ToCString(), line, column); 467 String::Handle(script.url()).ToCString(), line, column);
466 if (!dst_name.IsNull() && (dst_name.Length() > 0)) { 468 if (!dst_name.IsNull() && (dst_name.Length() > 0)) {
467 OS::Print("type '%s' is not a subtype of type '%s' of '%s'.\n", 469 OS::Print("type '%s' is not a subtype of type '%s' of '%s'.\n",
468 src_type_name.ToCString(), 470 src_type_name.ToCString(),
469 dst_type_name.ToCString(), 471 dst_type_name.ToCString(),
470 dst_name.ToCString()); 472 dst_name.ToCString());
471 } else { 473 } else {
472 OS::Print("type error.\n"); 474 OS::Print("type error.\n");
473 } 475 }
474 } 476 }
477
478 if (FLAG_abort_on_assertion_errors) {
479 PrintStackTraceAndAbort("a type error");
480 }
481
475 // Throw TypeError or CastError instance. 482 // Throw TypeError or CastError instance.
476 Exceptions::ThrowByType(exception_type, args); 483 Exceptions::ThrowByType(exception_type, args);
477 UNREACHABLE(); 484 UNREACHABLE();
478 } 485 }
479 486
480 487
481 void Exceptions::Throw(Thread* thread, const Instance& exception) { 488 void Exceptions::Throw(Thread* thread, const Instance& exception) {
482 // Do not notify debugger on stack overflow and out of memory exceptions. 489 // Do not notify debugger on stack overflow and out of memory exceptions.
483 // The VM would crash when the debugger calls back into the VM to 490 // The VM would crash when the debugger calls back into the VM to
484 // get values of variables. 491 // get values of variables.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 677
671 678
672 // Throw JavascriptCompatibilityError exception. 679 // Throw JavascriptCompatibilityError exception.
673 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) { 680 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) {
674 const Array& exc_args = Array::Handle(Array::New(1)); 681 const Array& exc_args = Array::Handle(Array::New(1));
675 const String& msg_str = String::Handle(String::New(msg)); 682 const String& msg_str = String::Handle(String::New(msg));
676 exc_args.SetAt(0, msg_str); 683 exc_args.SetAt(0, msg_str);
677 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); 684 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args);
678 } 685 }
679 686
687
688 void Exceptions::PrintStackTraceAndAbort(const char* reason) {
689 const Instance& stacktrace = Instance::Handle(CurrentStacktrace());
690
691 OS::PrintErr("\n\n\nAborting due to %s. Stacktrace:\n%s\n",
692 reason,
693 stacktrace.ToCString());
694 OS::Abort();
695 }
696
680 } // namespace dart 697 } // namespace dart
OLDNEW
« 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