Revision: 15416
Author:   [email protected]
Date:     Mon Jul  1 05:54:13 2013
Log:      Debug: support breakpoints set in the middle of statement

[email protected]

Review URL: https://codereview.chromium.org/16093040
http://code.google.com/p/v8/source/detail?r=15416

Modified:
 /branches/bleeding_edge/src/debug-debugger.js
 /branches/bleeding_edge/src/debug.cc
 /branches/bleeding_edge/src/debug.h
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/runtime.h
 /branches/bleeding_edge/test/cctest/test-debug.cc
 /branches/bleeding_edge/test/mjsunit/debug-breakpoints.js

=======================================
--- /branches/bleeding_edge/src/debug-debugger.js       Wed Jan 16 07:44:26 2013
+++ /branches/bleeding_edge/src/debug-debugger.js       Mon Jul  1 05:54:13 2013
@@ -71,6 +71,13 @@
                                ScriptName: 1,
                                ScriptRegExp: 2 };

+// The different types of breakpoint position alignments.
+// Must match BreakPositionAlignment in debug.h.
+Debug.BreakPositionAlignment = {
+  Statement: 0,
+  BreakPosition: 1
+};
+
 function ScriptTypeFlag(type) {
   return (1 << type);
 }
@@ -251,7 +258,7 @@
 // script name or script id and the break point is represented as line and
 // column.
 function ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column,
-                          opt_groupId) {
+                          opt_groupId, opt_position_alignment) {
   this.type_ = type;
   if (type == Debug.ScriptBreakPointType.ScriptId) {
     this.script_id_ = script_id_or_name;
@@ -265,6 +272,8 @@
   this.line_ = opt_line || 0;
   this.column_ = opt_column;
   this.groupId_ = opt_groupId;
+  this.position_alignment_ = IS_UNDEFINED(opt_position_alignment)
+      ? Debug.BreakPositionAlignment.Statement : opt_position_alignment;
   this.hit_count_ = 0;
   this.active_ = true;
   this.condition_ = null;
@@ -276,7 +285,8 @@
 //Creates a clone of script breakpoint that is linked to another script.
 ScriptBreakPoint.prototype.cloneForOtherScript = function (other_script) {
   var copy = new ScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId,
-      other_script.id, this.line_, this.column_, this.groupId_);
+      other_script.id, this.line_, this.column_, this.groupId_,
+      this.position_alignment_);
   copy.number_ = next_break_point_number++;
   script_break_points.push(copy);

@@ -443,7 +453,9 @@
   // Create a break point object and set the break point.
   break_point = MakeBreakPoint(position, this);
   break_point.setIgnoreCount(this.ignoreCount());
- var actual_position = %SetScriptBreakPoint(script, position, break_point);
+  var actual_position = %SetScriptBreakPoint(script, position,
+                                             this.position_alignment_,
+                                             break_point);
   if (IS_UNDEFINED(actual_position)) {
     actual_position = position;
   }
@@ -509,9 +521,11 @@
   %Break();
 };

-Debug.breakLocations = function(f) {
+Debug.breakLocations = function(f, opt_position_aligment) {
   if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.');
-  return %GetBreakLocations(f);
+  var position_aligment = IS_UNDEFINED(opt_position_aligment)
+      ? Debug.BreakPositionAlignment.Statement : opt_position_aligment;
+  return %GetBreakLocations(f, position_aligment);
 };

 // Returns a Script object. If the parameter is a function the return value
@@ -674,7 +688,8 @@


 Debug.setBreakPointByScriptIdAndPosition = function(script_id, position,
-                                                    condition, enabled)
+                                                    condition, enabled,
+                                                    opt_position_alignment)
 {
   break_point = MakeBreakPoint(position);
   break_point.setCondition(condition);
@@ -682,10 +697,12 @@
     break_point.disable();
   }
   var scripts = this.scripts();
+  var position_alignment = IS_UNDEFINED(opt_position_alignment)
+      ? Debug.BreakPositionAlignment.Statement : opt_position_alignment;
   for (var i = 0; i < scripts.length; i++) {
     if (script_id == scripts[i].id) {
break_point.actual_position = %SetScriptBreakPoint(scripts[i], position,
-                                                         break_point);
+          position_alignment, break_point);
       break;
     }
   }
@@ -780,11 +797,11 @@
 // specified source line and column within that line.
 Debug.setScriptBreakPoint = function(type, script_id_or_name,
                                      opt_line, opt_column, opt_condition,
-                                     opt_groupId) {
+                                     opt_groupId, opt_position_alignment) {
   // Create script break point object.
   var script_break_point =
       new ScriptBreakPoint(type, script_id_or_name, opt_line, opt_column,
-                           opt_groupId);
+                           opt_groupId, opt_position_alignment);

   // Assign number to the new script break point and add it.
   script_break_point.number_ = next_break_point_number++;
@@ -806,10 +823,12 @@

 Debug.setScriptBreakPointById = function(script_id,
                                          opt_line, opt_column,
-                                         opt_condition, opt_groupId) {
+                                         opt_condition, opt_groupId,
+                                         opt_position_alignment) {
   return this.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId,
                                   script_id, opt_line, opt_column,
-                                  opt_condition, opt_groupId);
+                                  opt_condition, opt_groupId,
+                                  opt_position_alignment);
 };


@@ -893,11 +912,11 @@
   return !!%IsBreakOnException(Debug.ExceptionBreak.Uncaught);
 };

-Debug.showBreakPoints = function(f, full) {
+Debug.showBreakPoints = function(f, full, opt_position_alignment) {
   if (!IS_FUNCTION(f)) throw new Error('Parameters have wrong types.');
   var source = full ? this.scriptSource(f) : this.source(f);
   var offset = full ? this.sourcePosition(f) : 0;
-  var locations = this.breakLocations(f);
+  var locations = this.breakLocations(f, opt_position_alignment);
   if (!locations) return source;
   locations.sort(function(x, y) { return x - y; });
   var result = "";
=======================================
--- /branches/bleeding_edge/src/debug.cc        Fri Jun 28 04:34:51 2013
+++ /branches/bleeding_edge/src/debug.cc        Mon Jul  1 05:54:13 2013
@@ -235,17 +235,30 @@


 // Find the break point closest to the supplied source position.
-void BreakLocationIterator::FindBreakLocationFromPosition(int position) {
+void BreakLocationIterator::FindBreakLocationFromPosition(int position,
+    BreakPositionAlignment alignment) {
   // Run through all break points to locate the one closest to the source
   // position.
   int closest_break_point = 0;
   int distance = kMaxInt;
+
   while (!Done()) {
+    int next_position;
+    switch (alignment) {
+    case STATEMENT_ALIGNED:
+      next_position = this->statement_position();
+      break;
+    case BREAK_POSITION_ALIGNED:
+      next_position = this->position();
+      break;
+    default:
+      UNREACHABLE();
+      next_position = this->statement_position();
+    }
     // Check if this break point is closer that what was previously found.
-    if (position <= statement_position() &&
-        statement_position() - position < distance) {
+    if (position <= next_position && next_position - position < distance) {
       closest_break_point = break_point();
-      distance = statement_position() - position;
+      distance = next_position - position;
       // Check whether we can't get any closer.
       if (distance == 0) break;
     }
@@ -1190,7 +1203,7 @@

   // Find the break point and change it.
   BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS);
-  it.FindBreakLocationFromPosition(*source_position);
+  it.FindBreakLocationFromPosition(*source_position, STATEMENT_ALIGNED);
   it.SetBreakPoint(break_point_object);

   *source_position = it.position();
@@ -1202,7 +1215,8 @@

 bool Debug::SetBreakPointForScript(Handle<Script> script,
                                    Handle<Object> break_point_object,
-                                   int* source_position) {
+                                   int* source_position,
+                                   BreakPositionAlignment alignment) {
   HandleScope scope(isolate_);

   PrepareForBreakPoints();
@@ -1233,7 +1247,7 @@

   // Find the break point and change it.
   BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS);
-  it.FindBreakLocationFromPosition(position);
+  it.FindBreakLocationFromPosition(position, alignment);
   it.SetBreakPoint(break_point_object);

   *source_position = it.position() + shared->start_position();
@@ -1687,7 +1701,8 @@

// Simple function for returning the source positions for active break points.
 Handle<Object> Debug::GetSourceBreakLocations(
-    Handle<SharedFunctionInfo> shared) {
+    Handle<SharedFunctionInfo> shared,
+    BreakPositionAlignment position_alignment) {
   Isolate* isolate = Isolate::Current();
   Heap* heap = isolate->heap();
   if (!HasDebugInfo(shared)) {
@@ -1705,7 +1720,20 @@
       BreakPointInfo* break_point_info =
           BreakPointInfo::cast(debug_info->break_points()->get(i));
       if (break_point_info->GetBreakPointCount() > 0) {
-        locations->set(count++, break_point_info->statement_position());
+        Smi* position;
+        switch (position_alignment) {
+        case STATEMENT_ALIGNED:
+          position = break_point_info->statement_position();
+          break;
+        case BREAK_POSITION_ALIGNED:
+          position = break_point_info->source_position();
+          break;
+        default:
+          UNREACHABLE();
+          position = break_point_info->statement_position();
+        }
+
+        locations->set(count++, position);
       }
     }
   }
=======================================
--- /branches/bleeding_edge/src/debug.h Tue Jun 25 06:42:44 2013
+++ /branches/bleeding_edge/src/debug.h Mon Jul  1 05:54:13 2013
@@ -79,6 +79,14 @@
 };


+// The different types of breakpoint position alignments.
+// Must match Debug.BreakPositionAlignment in debug-debugger.js
+enum BreakPositionAlignment {
+  STATEMENT_ALIGNED = 0,
+  BREAK_POSITION_ALIGNED = 1
+};
+
+
 // Class for iterating through the break points in a function and changing
 // them.
 class BreakLocationIterator {
@@ -90,7 +98,8 @@
   void Next();
   void Next(int count);
   void FindBreakLocationFromAddress(Address pc);
-  void FindBreakLocationFromPosition(int position);
+  void FindBreakLocationFromPosition(int position,
+      BreakPositionAlignment alignment);
   void Reset();
   bool Done() const;
   void SetBreakPoint(Handle<Object> break_point_object);
@@ -241,7 +250,8 @@
                      int* source_position);
   bool SetBreakPointForScript(Handle<Script> script,
                               Handle<Object> break_point_object,
-                              int* source_position);
+                              int* source_position,
+                              BreakPositionAlignment alignment);
   void ClearBreakPoint(Handle<Object> break_point_object);
   void ClearAllBreakPoints();
   void FloodWithOneShot(Handle<JSFunction> function);
@@ -284,7 +294,8 @@
static Handle<Code> FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode);

   static Handle<Object> GetSourceBreakLocations(
-      Handle<SharedFunctionInfo> shared);
+      Handle<SharedFunctionInfo> shared,
+      BreakPositionAlignment position_aligment);

   // Getter for the debug_context.
   inline Handle<Context> debug_context() { return debug_context_; }
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Mon Jul  1 02:14:15 2013
+++ /branches/bleeding_edge/src/runtime.cc      Mon Jul  1 05:54:13 2013
@@ -12100,16 +12100,30 @@
   isolate->debug()->set_disable_break(disable_break);
   return  isolate->heap()->undefined_value();
 }
+
+
+static bool IsPositionAlignmentValueCorrect(BreakPositionAlignment alignment) { + return alignment == STATEMENT_ALIGNED || alignment == BREAK_POSITION_ALIGNED;
+}


 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetBreakLocations) {
   HandleScope scope(isolate);
-  ASSERT(args.length() == 1);
+  ASSERT(args.length() == 2);

   CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
+  CONVERT_NUMBER_CHECKED(int32_t, statement_alighned_code, Int32, args[1]);
+
+  BreakPositionAlignment alignment =
+      static_cast<BreakPositionAlignment>(statement_alighned_code);
+  if (!IsPositionAlignmentValueCorrect(alignment)) {
+    return isolate->ThrowIllegalOperation();
+  }
+
   Handle<SharedFunctionInfo> shared(fun->shared());
   // Find the number of break points
-  Handle<Object> break_locations = Debug::GetSourceBreakLocations(shared);
+  Handle<Object> break_locations =
+      Debug::GetSourceBreakLocations(shared, alignment);
if (break_locations->IsUndefined()) return isolate->heap()->undefined_value();
   // Return array as JS array
   return *isolate->factory()->NewJSArrayWithElements(
@@ -12142,14 +12156,22 @@
 // GetScriptFromScriptData.
 // args[0]: script to set break point in
 // args[1]: number: break source position (within the script source)
-// args[2]: number: break point object
+// args[2]: number, breakpoint position alignment
+// args[3]: number: break point object
 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetScriptBreakPoint) {
   HandleScope scope(isolate);
-  ASSERT(args.length() == 3);
+  ASSERT(args.length() == 4);
   CONVERT_ARG_HANDLE_CHECKED(JSValue, wrapper, 0);
   CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
   RUNTIME_ASSERT(source_position >= 0);
-  Handle<Object> break_point_object_arg = args.at<Object>(2);
+  CONVERT_NUMBER_CHECKED(int32_t, statement_alighned_code, Int32, args[2]);
+  Handle<Object> break_point_object_arg = args.at<Object>(3);
+
+  BreakPositionAlignment alignment =
+      static_cast<BreakPositionAlignment>(statement_alighned_code);
+  if (!IsPositionAlignmentValueCorrect(alignment)) {
+    return isolate->ThrowIllegalOperation();
+  }

   // Get the script from the script wrapper.
   RUNTIME_ASSERT(wrapper->value()->IsScript());
@@ -12157,7 +12179,8 @@

   // Set break point.
if (!isolate->debug()->SetBreakPointForScript(script, break_point_object_arg,
-                                                &source_position)) {
+                                                &source_position,
+                                                alignment)) {
     return  isolate->heap()->undefined_value();
   }

=======================================
--- /branches/bleeding_edge/src/runtime.h       Fri Jun 28 08:48:38 2013
+++ /branches/bleeding_edge/src/runtime.h       Mon Jul  1 05:54:13 2013
@@ -499,9 +499,9 @@
   F(GetThreadCount, 1, 1) \
   F(GetThreadDetails, 2, 1) \
   F(SetDisableBreak, 1, 1) \
-  F(GetBreakLocations, 1, 1) \
+  F(GetBreakLocations, 2, 1) \
   F(SetFunctionBreakPoint, 3, 1) \
-  F(SetScriptBreakPoint, 3, 1) \
+  F(SetScriptBreakPoint, 4, 1) \
   F(ClearBreakPoint, 1, 1) \
   F(ChangeBreakOnException, 2, 1) \
   F(IsBreakOnException, 1, 1) \
=======================================
--- /branches/bleeding_edge/test/cctest/test-debug.cc Thu Jun 27 08:19:04 2013 +++ /branches/bleeding_edge/test/cctest/test-debug.cc Mon Jul 1 05:54:13 2013
@@ -509,7 +509,7 @@
   Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
   CHECK(Debug::HasDebugInfo(shared));
   TestBreakLocationIterator it1(Debug::GetDebugInfo(shared));
-  it1.FindBreakLocationFromPosition(position);
+ it1.FindBreakLocationFromPosition(position, v8::internal::STATEMENT_ALIGNED);
   v8::internal::RelocInfo::Mode actual_mode = it1.it()->rinfo()->rmode();
   if (actual_mode == v8::internal::RelocInfo::CODE_TARGET_WITH_ID) {
     actual_mode = v8::internal::RelocInfo::CODE_TARGET;
@@ -528,7 +528,7 @@
   CHECK(!debug->HasDebugInfo(shared));
   CHECK(debug->EnsureDebugInfo(shared, fun));
   TestBreakLocationIterator it2(Debug::GetDebugInfo(shared));
-  it2.FindBreakLocationFromPosition(position);
+ it2.FindBreakLocationFromPosition(position, v8::internal::STATEMENT_ALIGNED);
   actual_mode = it2.it()->rinfo()->rmode();
   if (actual_mode == v8::internal::RelocInfo::CODE_TARGET_WITH_ID) {
     actual_mode = v8::internal::RelocInfo::CODE_TARGET;
=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-breakpoints.js Fri Jan 14 04:01:57 2011 +++ /branches/bleeding_edge/test/mjsunit/debug-breakpoints.js Mon Jul 1 05:54:13 2013
@@ -29,7 +29,7 @@
 // Get the Debug object exposed from the debug context global object.
 Debug = debug.Debug

-function f() {a=1;b=2};
+function f() {a=1;b=2}
 function g() {
   a=1;
   b=2;
@@ -121,13 +121,13 @@


 // Tests for setting break points by script id and position.
-function setBreakpointByPosition(f, position)
+function setBreakpointByPosition(f, position, opt_position_alignment)
 {
   var break_point = Debug.setBreakPointByScriptIdAndPosition(
       Debug.findScript(f).id,
       position + Debug.sourcePosition(f),
       "",
-      true);
+      true, opt_position_alignment);
   return break_point.number();
 }

@@ -204,3 +204,22 @@
 //b=2;
 //}
 assertTrue(Debug.showBreakPoints(g).indexOf("[B0]") < 0);
+
+// Tests for setting break points without statement aligment.
+// (This may be sensitive to compiler break position map generation).
+function h() {a=f(f2(1,2),f3())+f3();b=f3();}
+var scenario = [
+  [5, "{a[B0]=f"],
+  [6, "{a=[B0]f("],
+  [7, "{a=f([B0]f2("],
+  [16, "f2(1,2),[B0]f3()"],
+  [22, "+[B0]f3()"]
+];
+for(var i = 0; i < scenario.length; i++) {
+  bp1 = setBreakpointByPosition(h, scenario[i][0],
+      Debug.BreakPositionAlignment.BreakPosition);
+  assertTrue(Debug.showBreakPoints(h, undefined,
+ Debug.BreakPositionAlignment.BreakPosition).indexOf(scenario[i][1])
0);
+  Debug.clearBreakPoint(bp1);
+}
+

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to