Refactored the code for handling debug step in in the runtime system into one functio...
authorsgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 18 Dec 2008 14:32:49 +0000 (14:32 +0000)
committersgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 18 Dec 2008 14:32:49 +0000 (14:32 +0000)
Review URL: http://codereview.chromium.org/15035

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1001 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/debug.cc
src/debug.h
src/ic.cc
src/runtime.cc
test/mjsunit/debug-stepin-constructor.js

index 027c89b640fc8f9fcc85753d60a93cdd699459b2..ff32023b21a9ec252543a0c448f23b08cb25314b 100644 (file)
@@ -1095,6 +1095,33 @@ Handle<Object> Debug::GetSourceBreakLocations(
 }
 
 
+// Handle stepping into a function.
+void Debug::HandleStepIn(Handle<JSFunction> function,
+                         Address fp,
+                         bool is_constructor) {
+  // If the frame pointer is not supplied by the caller find it.
+  if (fp == 0) {
+    StackFrameIterator it;
+    it.Advance();
+    // For constructor functions skip another frame.
+    if (is_constructor) {
+      ASSERT(it.frame()->is_construct());
+      it.Advance();
+    }
+    fp = it.frame()->fp();
+  }
+
+  // Flood the function with one-shot break points if it is called from where
+  // step into was requested.
+  if (fp == Debug::step_in_fp()) {
+    // Don't allow step into functions in the native context.
+    if (function->context()->global() != Top::context()->builtins()) {
+      Debug::FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared()));
+    }
+  }  
+}
+
+
 void Debug::ClearStepping() {
   // Clear the various stepping setup.
   ClearOneShot();
index fdb80bd20b6a5bc784321105d260855fae8206bf..56b8026226b8d8f2e2ef012634d0ebbf5d7f29e2 100644 (file)
@@ -205,6 +205,9 @@ class Debug {
   inline static bool has_break_points() { return has_break_points_; }
 
   static bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
+  static void HandleStepIn(Handle<JSFunction> function,
+                           Address fp,
+                           bool is_constructor);
   static Address step_in_fp() { return thread_local_.step_into_fp_; }
   static Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; }
 
index 260a0fb7af43c1e4c2f1f2b96eacd9d05125f246..4b2e084f4e78ae8c7facfe634deb22cdccb53720 100644 (file)
--- a/src/ic.cc
+++ b/src/ic.cc
@@ -352,20 +352,14 @@ Object* CallIC::LoadFunction(State state,
       if (opt->IsJSFunction()) return opt;
     }
 
-    // If performing debug step into then flood this function with one-shot
-    // break points if it is called from where step into was requested.
-    if (Debug::StepInActive() && fp() == Debug::step_in_fp()) {
+    // Handle stepping into a function if step into is active.
+    if (Debug::StepInActive()) {
       // Protect the result in a handle as the debugger can allocate and might
       // cause GC.
       HandleScope scope;
-      Handle<Object> result_handle(result);
-      // Don't allow step into functions in the native context.
-      if (JSFunction::cast(result)->context()->global() !=
-          Top::context()->builtins()) {
-        Handle<SharedFunctionInfo> shared(JSFunction::cast(result)->shared());
-        Debug::FloodWithOneShot(shared);
-      }
-      return *result_handle;
+      Handle<JSFunction> function(JSFunction::cast(result));
+      Debug::HandleStepIn(function, fp(), false);
+      return *function;
     }
 
     return result;
index 69e2b6fd31408ca18ff9c1bbf10602b68f4ae736..e796081008c417f7e58632808d854e53cf269e7e 100644 (file)
@@ -3323,16 +3323,10 @@ static Object* Runtime_NewObject(Arguments args) {
   if (constructor->IsJSFunction()) {
     JSFunction* function = JSFunction::cast(constructor);
 
-    // Handle steping into constructors.
+    // Handle steping into constructors if step into is active.
     if (Debug::StepInActive()) {
-      StackFrameIterator it;
-      it.Advance();
-      ASSERT(it.frame()->is_construct());
-      it.Advance();
-      if (it.frame()->fp() == Debug::step_in_fp()) {
-        HandleScope scope;
-        Debug::FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared()));
-      }
+      HandleScope scope;
+      Debug::HandleStepIn(Handle<JSFunction>(function), 0, true);
     }
 
     if (function->has_initial_map() &&
index ecd12836304dda35e92a72fd88ea35d01617d73b..ec35ce163f4a7afb2348dc38145c0d30157dbcab 100644 (file)
@@ -68,7 +68,7 @@ function g() {
 
 break_break_point_hit_count = 0;
 g();
-assertEquals(5, break_break_point_hit_count);
+assertEquals(4, break_break_point_hit_count);
 
 // Get rid of the debug event listener.
 Debug.removeListener(listener);