From 41064a57c3fe5cc633f2f1430c1d23c85c8b1194 Mon Sep 17 00:00:00 2001 From: "peter.rybin@gmail.com" Date: Thu, 16 Sep 2010 21:40:42 +0000 Subject: [PATCH] Add breakOnCaughtException and breakOnUncaughtException flags Review URL: http://codereview.chromium.org/3275011 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5480 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/debug-debugger.js | 36 ++++++++++++++++++++++++++++++++---- src/debug.cc | 9 +++++++++ src/debug.h | 1 + src/runtime.cc | 14 ++++++++++++++ src/runtime.h | 1 + 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/debug-debugger.js b/src/debug-debugger.js index 0b02e21..34eb0f0 100644 --- a/src/debug-debugger.js +++ b/src/debug-debugger.js @@ -45,7 +45,7 @@ Debug.DebugEvent = { Break: 1, ScriptCollected: 6 }; // Types of exceptions that can be broken upon. -Debug.ExceptionBreak = { All : 0, +Debug.ExceptionBreak = { Caught : 0, Uncaught: 1 }; // The different types of steps. @@ -87,7 +87,27 @@ var debugger_flags = { this.value = !!value; %SetDisableBreak(!this.value); } - } + }, + breakOnCaughtException: { + getValue: function() { return Debug.isBreakOnException(); }, + setValue: function(value) { + if (value) { + Debug.setBreakOnException(); + } else { + Debug.clearBreakOnException(); + } + } + }, + breakOnUncaughtException: { + getValue: function() { return Debug.isBreakOnUncaughtException(); }, + setValue: function(value) { + if (value) { + Debug.setBreakOnUncaughtException(); + } else { + Debug.clearBreakOnUncaughtException(); + } + } + }, }; @@ -781,11 +801,15 @@ Debug.clearStepping = function() { } Debug.setBreakOnException = function() { - return %ChangeBreakOnException(Debug.ExceptionBreak.All, true); + return %ChangeBreakOnException(Debug.ExceptionBreak.Caught, true); }; Debug.clearBreakOnException = function() { - return %ChangeBreakOnException(Debug.ExceptionBreak.All, false); + return %ChangeBreakOnException(Debug.ExceptionBreak.Caught, false); +}; + +Debug.isBreakOnException = function() { + return !!%IsBreakOnException(Debug.ExceptionBreak.Caught); }; Debug.setBreakOnUncaughtException = function() { @@ -796,6 +820,10 @@ Debug.clearBreakOnUncaughtException = function() { return %ChangeBreakOnException(Debug.ExceptionBreak.Uncaught, false); }; +Debug.isBreakOnUncaughtException = function() { + return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught); +}; + Debug.showBreakPoints = function(f, full) { if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.'); var source = full ? this.scriptSource(f) : this.source(f); diff --git a/src/debug.cc b/src/debug.cc index 87780d3..24b1d31 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -1200,6 +1200,15 @@ void Debug::ChangeBreakOnException(ExceptionBreakType type, bool enable) { } +bool Debug::IsBreakOnException(ExceptionBreakType type) { + if (type == BreakUncaughtException) { + return break_on_uncaught_exception_; + } else { + return break_on_exception_; + } +} + + void Debug::PrepareStep(StepAction step_action, int step_count) { HandleScope scope; ASSERT(Debug::InDebugger()); diff --git a/src/debug.h b/src/debug.h index 8b3b29e..0d63085 100644 --- a/src/debug.h +++ b/src/debug.h @@ -236,6 +236,7 @@ class Debug { static void FloodWithOneShot(Handle shared); static void FloodHandlerWithOneShot(); static void ChangeBreakOnException(ExceptionBreakType type, bool enable); + static bool IsBreakOnException(ExceptionBreakType type); static void PrepareStep(StepAction step_action, int step_count); static void ClearStepping(); static bool StepNextContinue(BreakLocationIterator* break_location_iterator, diff --git a/src/runtime.cc b/src/runtime.cc index 627ea12..a5a85ff 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -8962,6 +8962,20 @@ static Object* Runtime_ChangeBreakOnException(Arguments args) { } +// Returns the state of break on exceptions +// args[0]: boolean indicating uncaught exceptions +static Object* Runtime_IsBreakOnException(Arguments args) { + HandleScope scope; + ASSERT(args.length() == 1); + ASSERT(args[0]->IsNumber()); + + ExceptionBreakType type = + static_cast(NumberToUint32(args[0])); + bool result = Debug::IsBreakOnException(type); + return Smi::FromInt(result); +} + + // Prepare for stepping // args[0]: break id for checking execution state // args[1]: step action from the enumeration StepAction diff --git a/src/runtime.h b/src/runtime.h index 8a3671a..68567fc 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -332,6 +332,7 @@ namespace internal { F(SetScriptBreakPoint, 3, 1) \ F(ClearBreakPoint, 1, 1) \ F(ChangeBreakOnException, 2, 1) \ + F(IsBreakOnException, 1, 1) \ F(PrepareStep, 3, 1) \ F(ClearStepping, 0, 1) \ F(DebugEvaluate, 4, 1) \ -- 2.7.4