Reviewers: ulan,

Description:
Fix break location calculation.

[email protected]
BUG=chromium:419663
LOG=Y

Please review this at https://codereview.chromium.org/658723005/

Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+42, -5 lines):
  M src/debug.cc
  A test/mjsunit/regress/regress-419663.js


Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index 2329b250f3e9ffdfd3e8bb5fac19f9a9958c505d..15c1a8bc709f791003917402a8efd6344dacb46a 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -1096,7 +1096,7 @@ bool Debug::SetBreakPoint(Handle<JSFunction> function,
   it.FindBreakLocationFromPosition(*source_position, STATEMENT_ALIGNED);
   it.SetBreakPoint(break_point_object);

-  *source_position = it.position();
+  *source_position = it.statement_position();

   // At least one active break point now.
   return debug_info->GetBreakPointCount() > 0;
@@ -1140,7 +1140,10 @@ bool Debug::SetBreakPointForScript(Handle<Script> script,
   it.FindBreakLocationFromPosition(position, alignment);
   it.SetBreakPoint(break_point_object);

-  *source_position = it.position() + shared->start_position();
+  position = (alignment == STATEMENT_ALIGNED) ? it.statement_position()
+                                              : it.position();
+
+  *source_position = position + shared->start_position();

   // At least one active break point now.
   DCHECK(debug_info->GetBreakPointCount() > 0);
@@ -1566,9 +1569,6 @@ Handle<Object> Debug::GetSourceBreakLocations(
         case BREAK_POSITION_ALIGNED:
           position = break_point_info->source_position();
           break;
-        default:
-          UNREACHABLE();
-          position = break_point_info->statement_position();
         }

         locations->set(count++, position);
Index: test/mjsunit/regress/regress-419663.js
diff --git a/test/mjsunit/regress/regress-419663.js b/test/mjsunit/regress/regress-419663.js
new file mode 100644
index 0000000000000000000000000000000000000000..2655e2cdd0d39241f1d89312884abef7867a85ea
--- /dev/null
+++ b/test/mjsunit/regress/regress-419663.js
@@ -0,0 +1,37 @@
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug
+
+var o = {
+  f: function(x) {
+    var a = x + 1;
+    o = 1;
+  }
+}
+
+function sentinel() {}
+
+var Debug = debug.Debug;
+
+Debug.setListener(function() {});
+
+var script = Debug.findScript(sentinel);
+
+// Used in Debug.setScriptBreakPointById.
+var p1 = Debug.findScriptSourcePosition(script, 9, 0);
+var p2 = Debug.setBreakPointByScriptIdAndPosition(script.id, p1).actual_position; +var p3 = Debug.setBreakPointByScriptIdAndPosition(script.id, p2).actual_position;
+
+assertEquals(p2, p3);
+
+function assertLocation(p, l, c) {
+  var location = script.locationFromPosition(p, false);
+  assertEquals(l, location.line);
+  assertEquals(c, location.column);
+}
+
+assertLocation(p1, 9, 0);
+assertLocation(p2, 9, 4);
+assertLocation(p3, 9, 4);


--
--
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/d/optout.

Reply via email to