Index: src/debug.cc |
diff --git a/src/debug.cc b/src/debug.cc |
index 543ce9f24df5f096106902b918f927f9a7e3dc8e..a748b4cc7a10a984a5bb2accb437f334c46918a1 100644 |
--- a/src/debug.cc |
+++ b/src/debug.cc |
@@ -1170,14 +1170,16 @@ Handle<DebugInfo> Debug::GetDebugInfo(Handle<SharedFunctionInfo> shared) { |
} |
-void Debug::SetBreakPoint(Handle<SharedFunctionInfo> shared, |
+void Debug::SetBreakPoint(Handle<JSFunction> function, |
Handle<Object> break_point_object, |
int* source_position) { |
HandleScope scope(isolate_); |
PrepareForBreakPoints(); |
- if (!EnsureDebugInfo(shared)) { |
+ // Make sure the function is compiled and has set up the debug info. |
+ Handle<SharedFunctionInfo> shared(function->shared()); |
+ if (!EnsureDebugInfo(shared, function)) { |
// Return if retrieving debug info failed. |
return; |
} |
@@ -1198,6 +1200,51 @@ void Debug::SetBreakPoint(Handle<SharedFunctionInfo> shared, |
} |
+bool Debug::SetBreakPointForScript(Handle<Script> script, |
+ Handle<Object> break_point_object, |
+ int* source_position) { |
+ HandleScope scope(isolate_); |
+ |
+ // No need to call PrepareForBreakPoints because it will be called |
+ // implicitly by Runtime::FindSharedFunctionInfoInScript. |
+ Object* result = Runtime::FindSharedFunctionInfoInScript(isolate_, |
+ script, |
+ *source_position); |
+ if (result->IsUndefined()) return false; |
+ |
+ // Make sure the function has set up the debug info. |
+ Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result)); |
+ if (!EnsureDebugInfo(shared, Handle<JSFunction>::null())) { |
+ // Return if retrieving debug info failed. |
+ return false; |
+ } |
+ |
+ // Find position within function. The script position might be before the |
+ // source position of the first function. |
+ int position; |
+ if (shared->start_position() > *source_position) { |
+ position = 0; |
+ } else { |
+ position = *source_position - shared->start_position(); |
+ } |
+ |
+ Handle<DebugInfo> debug_info = GetDebugInfo(shared); |
+ // Source positions starts with zero. |
+ ASSERT(position >= 0); |
+ |
+ // Find the break point and change it. |
+ BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS); |
+ it.FindBreakLocationFromPosition(position); |
+ it.SetBreakPoint(break_point_object); |
+ |
+ *source_position = it.position() + shared->start_position(); |
+ |
+ // At least one active break point now. |
+ ASSERT(debug_info->GetBreakPointCount() > 0); |
+ return true; |
+} |
+ |
+ |
void Debug::ClearBreakPoint(Handle<Object> break_point_object) { |
HandleScope scope(isolate_); |
@@ -1249,10 +1296,12 @@ void Debug::ClearAllBreakPoints() { |
} |
-void Debug::FloodWithOneShot(Handle<SharedFunctionInfo> shared) { |
+void Debug::FloodWithOneShot(Handle<JSFunction> function) { |
PrepareForBreakPoints(); |
- // Make sure the function has set up the debug info. |
- if (!EnsureDebugInfo(shared)) { |
+ |
+ // Make sure the function is compiled and has set up the debug info. |
+ Handle<SharedFunctionInfo> shared(function->shared()); |
+ if (!EnsureDebugInfo(shared, function)) { |
// Return if we failed to retrieve the debug info. |
return; |
} |
@@ -1272,8 +1321,8 @@ void Debug::FloodBoundFunctionWithOneShot(Handle<JSFunction> function) { |
if (!bindee.is_null() && bindee->IsJSFunction() && |
!JSFunction::cast(*bindee)->IsBuiltin()) { |
- Handle<SharedFunctionInfo> shared_info(JSFunction::cast(*bindee)->shared()); |
- Debug::FloodWithOneShot(shared_info); |
+ Handle<JSFunction> bindee_function(JSFunction::cast(*bindee)); |
+ Debug::FloodWithOneShot(bindee_function); |
} |
} |
@@ -1288,11 +1337,9 @@ void Debug::FloodHandlerWithOneShot() { |
for (JavaScriptFrameIterator it(isolate_, id); !it.done(); it.Advance()) { |
JavaScriptFrame* frame = it.frame(); |
if (frame->HasHandler()) { |
- Handle<SharedFunctionInfo> shared = |
- Handle<SharedFunctionInfo>( |
- JSFunction::cast(frame->function())->shared()); |
// Flood the function with the catch block with break points |
- FloodWithOneShot(shared); |
+ JSFunction* function = JSFunction::cast(frame->function()); |
+ FloodWithOneShot(Handle<JSFunction>(function)); |
return; |
} |
} |
@@ -1359,14 +1406,14 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { |
frames_it.Advance(); |
// Fill the function to return to with one-shot break points. |
JSFunction* function = JSFunction::cast(frames_it.frame()->function()); |
- FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared())); |
+ FloodWithOneShot(Handle<JSFunction>(function)); |
return; |
} |
// Get the debug info (create it if it does not exist). |
- Handle<SharedFunctionInfo> shared = |
- Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); |
- if (!EnsureDebugInfo(shared)) { |
+ Handle<JSFunction> function(JSFunction::cast(frame->function())); |
+ Handle<SharedFunctionInfo> shared(function->shared()); |
+ if (!EnsureDebugInfo(shared, function)) { |
// Return if ensuring debug info failed. |
return; |
} |
@@ -1436,7 +1483,7 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { |
if (!frames_it.done()) { |
// Fill the function to return to with one-shot break points. |
JSFunction* function = JSFunction::cast(frames_it.frame()->function()); |
- FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared())); |
+ FloodWithOneShot(Handle<JSFunction>(function)); |
// Set target frame pointer. |
ActivateStepOut(frames_it.frame()); |
} |
@@ -1446,7 +1493,7 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { |
// Step next or step min. |
// Fill the current function with one-shot break points. |
- FloodWithOneShot(shared); |
+ FloodWithOneShot(function); |
// Remember source position and frame to handle step next. |
thread_local_.last_statement_position_ = |
@@ -1458,9 +1505,7 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { |
if (is_at_restarted_function) { |
Handle<JSFunction> restarted_function( |
JSFunction::cast(*thread_local_.restarter_frame_function_pointer_)); |
- Handle<SharedFunctionInfo> restarted_shared( |
- restarted_function->shared()); |
- FloodWithOneShot(restarted_shared); |
+ FloodWithOneShot(restarted_function); |
} else if (!call_function_stub.is_null()) { |
// If it's CallFunction stub ensure target function is compiled and flood |
// it with one shot breakpoints. |
@@ -1502,7 +1547,7 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { |
} else if (!js_function->IsBuiltin()) { |
// Don't step into builtins. |
// It will also compile target function if it's not compiled yet. |
- FloodWithOneShot(Handle<SharedFunctionInfo>(js_function->shared())); |
+ FloodWithOneShot(js_function); |
} |
} |
} |
@@ -1511,7 +1556,7 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { |
// a call target as the function called might be a native function for |
// which step in will not stop. It also prepares for stepping in |
// getters/setters. |
- FloodWithOneShot(shared); |
+ FloodWithOneShot(function); |
if (is_load_or_store) { |
// Remember source position and frame to handle step in getter/setter. If |
@@ -1711,12 +1756,11 @@ void Debug::HandleStepIn(Handle<JSFunction> function, |
// function. |
if (!holder.is_null() && holder->IsJSFunction() && |
!JSFunction::cast(*holder)->IsBuiltin()) { |
- Handle<SharedFunctionInfo> shared_info( |
- JSFunction::cast(*holder)->shared()); |
- Debug::FloodWithOneShot(shared_info); |
+ Handle<JSFunction> js_function = Handle<JSFunction>::cast(holder); |
+ Debug::FloodWithOneShot(js_function); |
} |
} else { |
- Debug::FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared())); |
+ Debug::FloodWithOneShot(function); |
} |
} |
} |
@@ -1956,6 +2000,9 @@ void Debug::PrepareForBreakPoints() { |
Handle<Code> lazy_compile = |
Handle<Code>(isolate_->builtins()->builtin(Builtins::kLazyCompile)); |
+ // There will be at least one break point when we are done. |
+ has_break_points_ = true; |
+ |
// Keep the list of activated functions in a handlified list as it |
// is used both in GC and non-GC code. |
List<Handle<JSFunction> > active_functions(100); |
@@ -2063,15 +2110,20 @@ void Debug::PrepareForBreakPoints() { |
// Ensures the debug information is present for shared. |
-bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared) { |
+bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared, |
+ Handle<JSFunction> function) { |
// Return if we already have the debug info for shared. |
if (HasDebugInfo(shared)) { |
ASSERT(shared->is_compiled()); |
return true; |
} |
- // Ensure shared in compiled. Return false if this failed. |
- if (!SharedFunctionInfo::EnsureCompiled(shared, CLEAR_EXCEPTION)) { |
+ // Make sure we are prepared to handle breakpoints. |
+ ASSERT(has_break_points_); |
+ |
+ // Ensure function is compiled. Return false if this failed. |
+ if (!function.is_null() && |
+ !JSFunction::EnsureCompiled(function, CLEAR_EXCEPTION)) { |
return false; |
} |
@@ -2083,9 +2135,6 @@ bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared) { |
node->set_next(debug_info_list_); |
debug_info_list_ = node; |
- // Now there is at least one break point. |
- has_break_points_ = true; |
- |
return true; |
} |
@@ -2127,9 +2176,9 @@ void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { |
PrepareForBreakPoints(); |
// Get the executing function in which the debug break occurred. |
- Handle<SharedFunctionInfo> shared = |
- Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); |
- if (!EnsureDebugInfo(shared)) { |
+ Handle<JSFunction> function(JSFunction::cast(frame->function())); |
+ Handle<SharedFunctionInfo> shared(function->shared()); |
+ if (!EnsureDebugInfo(shared, function)) { |
// Return if we failed to retrieve the debug info. |
return; |
} |
@@ -2219,9 +2268,9 @@ bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) { |
PrepareForBreakPoints(); |
// Get the executing function in which the debug break occurred. |
- Handle<SharedFunctionInfo> shared = |
- Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); |
- if (!EnsureDebugInfo(shared)) { |
+ Handle<JSFunction> function(JSFunction::cast(frame->function())); |
+ Handle<SharedFunctionInfo> shared(function->shared()); |
+ if (!EnsureDebugInfo(shared, function)) { |
// Return if we failed to retrieve the debug info. |
return false; |
} |