Revision: 4359
Author: [email protected]
Date: Thu Apr  8 05:37:10 2010
Log: LiveEdit: update breakpoint positions for non-changed functions

Review URL: http://codereview.chromium.org/1090003
http://code.google.com/p/v8/source/detail?r=4359

Modified:
 /branches/bleeding_edge/src/debug-debugger.js
 /branches/bleeding_edge/src/liveedit-debugger.js
 /branches/bleeding_edge/src/liveedit.cc
 /branches/bleeding_edge/src/liveedit.h
 /branches/bleeding_edge/src/runtime.cc

=======================================
--- /branches/bleeding_edge/src/debug-debugger.js       Tue Apr  6 10:58:28 2010
+++ /branches/bleeding_edge/src/debug-debugger.js       Thu Apr  8 05:37:10 2010
@@ -124,6 +124,12 @@
 };


+BreakPoint.prototype.updateSourcePosition = function(new_position, script) {
+  this.source_position_ = new_position;
+  // TODO(635): also update line and column.
+};
+
+
 BreakPoint.prototype.hit_count = function() {
   return this.hit_count_;
 };
=======================================
--- /branches/bleeding_edge/src/liveedit-debugger.js Tue Apr 6 10:58:28 2010 +++ /branches/bleeding_edge/src/liveedit-debugger.js Thu Apr 8 05:37:10 2010
@@ -180,11 +180,18 @@
   var position_patch_report;
   function PatchPositions(new_info, shared_info) {
     if (!shared_info) {
-      // TODO: explain what is happening.
+      // TODO(LiveEdit): explain what is happening.
       return;
     }
-    %LiveEditPatchFunctionPositions(shared_info.raw_array,
-        position_change_array);
+    var breakpoint_position_update = %LiveEditPatchFunctionPositions(
+        shared_info.raw_array, position_change_array);
+    for (var i = 0; i < breakpoint_position_update.length; i += 2) {
+      var new_pos = breakpoint_position_update[i];
+      var break_point_object = breakpoint_position_update[i + 1];
+      change_log.push( { breakpoint_position_update:
+          { from: break_point_object.source_position(), to: new_pos } } );
+      break_point_object.updateSourcePosition(new_pos, script);
+    }
     position_patch_report.push( { name: new_info.function_name } );
   }

=======================================
--- /branches/bleeding_edge/src/liveedit.cc     Wed Apr  7 11:13:18 2010
+++ /branches/bleeding_edge/src/liveedit.cc     Thu Apr  8 05:37:10 2010
@@ -644,13 +644,28 @@
 }


-void LiveEdit::PatchFunctionPositions(Handle<JSArray> shared_info_array,
- Handle<JSArray> position_change_array) {
+static Handle<Object> GetBreakPointObjectsForJS(
+    Handle<BreakPointInfo> break_point_info) {
+  if (break_point_info->break_point_objects()->IsFixedArray()) {
+    Handle<FixedArray> fixed_array(
+        FixedArray::cast(break_point_info->break_point_objects()));
+    Handle<Object> array = Factory::NewJSArrayWithElements(fixed_array);
+    return array;
+  } else {
+    return Handle<Object>(break_point_info->break_point_objects());
+  }
+}
+
+
+Handle<JSArray> LiveEdit::PatchFunctionPositions(
+ Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array) {
   SharedInfoWrapper shared_info_wrapper(shared_info_array);
   Handle<SharedFunctionInfo> info = shared_info_wrapper.GetInfo();

-  info->set_start_position(TranslatePosition(info->start_position(),
-                                             position_change_array));
+  int old_function_start = info->start_position();
+  int new_function_start = TranslatePosition(old_function_start,
+                                             position_change_array);
+  info->set_start_position(new_function_start);
   info->set_end_position(TranslatePosition(info->end_position(),
                                            position_change_array));

@@ -671,6 +686,10 @@
       ReplaceCodeObject(info->code(), *patched_code);
     }
   }
+
+
+  Handle<JSArray> result = Factory::NewJSArray(0);
+  int result_len = 0;

   if (info->debug_info()->IsDebugInfo()) {
     Handle<DebugInfo> debug_info(DebugInfo::cast(info->debug_info()));
@@ -690,12 +709,22 @@
       }
       Handle<BreakPointInfo> info(
           BreakPointInfo::cast(break_point_infos->get(i)));
- int new_position = TranslatePosition(info->source_position()->value(),
+      int old_in_script_position = info->source_position()->value() +
+          old_function_start;
+ int new_in_script_position = TranslatePosition(old_in_script_position,
           position_change_array);
-      info->set_source_position(Smi::FromInt(new_position));
+      info->set_source_position(
+          Smi::FromInt(new_in_script_position - new_function_start));
+      if (old_in_script_position != new_in_script_position) {
+        SetElement(result, result_len,
+                   Handle<Smi>(Smi::FromInt(new_in_script_position)));
+        SetElement(result, result_len + 1,
+                   GetBreakPointObjectsForJS(info));
+        result_len += 2;
+      }
     }
   }
-  // TODO(635): Also patch breakpoint objects in JS.
+  return result;
 }


=======================================
--- /branches/bleeding_edge/src/liveedit.h      Tue Apr  6 10:58:28 2010
+++ /branches/bleeding_edge/src/liveedit.h      Thu Apr  8 05:37:10 2010
@@ -88,8 +88,10 @@
   static void RelinkFunctionToScript(Handle<JSArray> shared_info_array,
                                      Handle<Script> script_handle);

-  static void PatchFunctionPositions(Handle<JSArray> shared_info_array,
- Handle<JSArray> position_change_array); + // Returns an array of pairs (new source position, breakpoint_object/array)
+  // so that JS side could update positions in breakpoint objects.
+  static Handle<JSArray> PatchFunctionPositions(
+ Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array);

   // Checks listed functions on stack and return array with corresponding
   // FunctionPatchabilityStatus statuses; extra array element may
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Wed Apr  7 04:13:05 2010
+++ /branches/bleeding_edge/src/runtime.cc      Thu Apr  8 05:37:10 2010
@@ -9656,6 +9656,8 @@
   old_script->set_eval_from_instructions_offset(
       original_script->eval_from_instructions_offset());

+  // Drop line ends so that they will be recalculated.
+  original_script->set_line_ends(Heap::undefined_value());

   Debugger::OnAfterCompile(old_script, Debugger::SEND_WHEN_DEBUGGING);

@@ -9692,15 +9694,18 @@
 // array of groups of 3 numbers:
 // (change_begin, change_end, change_end_new_position).
// Each group describes a change in text; groups are sorted by change_begin.
+// Returns an array of pairs (new source position, breakpoint_object/array)
+// so that JS side could update positions in breakpoint objects.
 static Object* Runtime_LiveEditPatchFunctionPositions(Arguments args) {
   ASSERT(args.length() == 2);
   HandleScope scope;
   CONVERT_ARG_CHECKED(JSArray, shared_array, 0);
   CONVERT_ARG_CHECKED(JSArray, position_change_array, 1);

-  LiveEdit::PatchFunctionPositions(shared_array, position_change_array);
-
-  return Heap::undefined_value();
+  Handle<Object> result =
+ LiveEdit::PatchFunctionPositions(shared_array, position_change_array);
+
+  return *result;
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to