From 9f77ba9f1f1d2aee2196d4e75bf9392275582fe6 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 9 Apr 2013 11:31:10 +0000 Subject: [PATCH] Add an option to dump core when an uncaught exception is thrown. BUG= Review URL: https://chromiumcodereview.appspot.com/13071005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14185 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/flag-definitions.h | 2 ++ src/isolate.cc | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/flag-definitions.h b/src/flag-definitions.h index 746d8e1808..48cca5b829 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -499,6 +499,8 @@ DEFINE_int(sim_stack_alignment, 8, "Stack alingment in bytes in simulator (4 or 8, 8 is default)") // isolate.cc +DEFINE_bool(abort_on_uncaught_exception, false, + "abort program (dump core) when an uncaught exception is thrown") DEFINE_bool(trace_exception, false, "print stack trace when throwing exceptions") DEFINE_bool(preallocate_message_memory, false, diff --git a/src/isolate.cc b/src/isolate.cc index fd70002cce..e61c387b8d 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -1213,6 +1213,7 @@ bool Isolate::IsErrorObject(Handle obj) { return false; } +static int fatal_exception_depth = 0; void Isolate::DoThrow(Object* exception, MessageLocation* location) { ASSERT(!has_pending_exception()); @@ -1296,6 +1297,20 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) { thread_local_top()->pending_message_start_pos_ = location->start_pos(); thread_local_top()->pending_message_end_pos_ = location->end_pos(); } + + // If the abort-on-uncaught-exception flag is specified, abort on any + // exception not caught by JavaScript, even when an external handler is + // present. This flag is intended for use by JavaScript developers, so + // print a user-friendly stack trace (not an internal one). + if (fatal_exception_depth == 0 && + FLAG_abort_on_uncaught_exception && + (report_exception || can_be_caught_externally)) { + fatal_exception_depth++; + fprintf(stderr, "%s\n\nFROM\n", + *MessageHandler::GetLocalizedMessage(this, message_obj)); + PrintCurrentStackTrace(stderr); + OS::Abort(); + } } else if (location != NULL && !location->script().is_null()) { // We are bootstrapping and caught an error where the location is set // and we have a script for the location.