Reviewers: ulan,

Description:
Do not break in native code (including non-builtin debugger code).


[email protected]

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

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

Affected files (+61, -6 lines):
  M src/debug.cc
  M src/objects.h
  M src/objects-inl.h
  A test/mjsunit/debug-break-native.js


Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index 058ec358735cf6a0152c6e8e99353d7f8851cfe0..932b58aac890fcb4679b723fb532eae66733da16 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -805,6 +805,7 @@ bool Debug::Load() {

 void Debug::Unload() {
   ClearAllBreakPoints();
+  ClearStepping();

   // Match unmatched PromiseHandlePrologue calls.
   while (thread_local_.promise_on_stack_) PromiseHandleEpilogue();
@@ -1209,7 +1210,7 @@ void Debug::FloodBoundFunctionWithOneShot(Handle<JSFunction> function) {
                         isolate_);

   if (!bindee.is_null() && bindee->IsJSFunction() &&
-      !JSFunction::cast(*bindee)->IsBuiltin()) {
+      !JSFunction::cast(*bindee)->IsNative()) {
     Handle<JSFunction> bindee_function(JSFunction::cast(*bindee));
     Debug::FloodWithOneShot(bindee_function);
   }
@@ -1430,7 +1431,7 @@ void Debug::PrepareStep(StepAction step_action,
       frames_it.Advance();
     }
     // Skip builtin functions on the stack.
- while (!frames_it.done() && frames_it.frame()->function()->IsBuiltin()) { + while (!frames_it.done() && frames_it.frame()->function()->IsNative()) {
       frames_it.Advance();
     }
     // Step out: If there is a JavaScript caller frame, we need to
@@ -1517,7 +1518,7 @@ void Debug::PrepareStep(StepAction step_action,
         Handle<JSFunction> js_function(JSFunction::cast(fun));
         if (js_function->shared()->bound()) {
           Debug::FloodBoundFunctionWithOneShot(js_function);
-        } else if (!js_function->IsBuiltin()) {
+        } else if (!js_function->IsNative()) {
           // Don't step into builtins.
           // It will also compile target function if it's not compiled yet.
           FloodWithOneShot(js_function);
@@ -1731,7 +1732,7 @@ void Debug::HandleStepIn(Handle<JSFunction> function,
     if (function->shared()->bound()) {
       // Handle Function.prototype.bind
       Debug::FloodBoundFunctionWithOneShot(function);
-    } else if (!function->IsBuiltin()) {
+    } else if (!function->IsNative()) {
       // Don't allow step into functions in the native context.
       if (function->shared()->code() ==
           isolate->builtins()->builtin(Builtins::kFunctionApply) ||
@@ -1743,7 +1744,7 @@ void Debug::HandleStepIn(Handle<JSFunction> function,
         // function.
         if (!holder.is_null() && holder->IsJSFunction()) {
Handle<JSFunction> js_function = Handle<JSFunction>::cast(holder);
-          if (!js_function->IsBuiltin()) {
+          if (!js_function->IsNative()) {
             Debug::FloodWithOneShot(js_function);
           } else if (js_function->shared()->bound()) {
             // Handle Function.prototype.bind
@@ -2085,7 +2086,7 @@ void Debug::PrepareForBreakPoints() {

           if (!shared->allows_lazy_compilation()) continue;
           if (!shared->script()->IsScript()) continue;
-          if (function->IsBuiltin()) continue;
+          if (function->IsNative()) continue;
if (shared->code()->gc_metadata() == active_code_marker) continue;

           if (shared->is_generator()) {
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 31ebbb18c8a42bf0399208099e20ac7f910c2d8c..58c9c966b088205b2e6a2013d55f9485bc1d3c8b 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -5418,6 +5418,15 @@ bool JSFunction::IsBuiltin() {
 }


+bool JSFunction::IsNative() {
+  Object* script = shared()->script();
+  bool native = script->IsScript() &&
+ Script::cast(script)->type()->value() == Script::TYPE_NATIVE;
+  ASSERT(!IsBuiltin() || native);  // All builtins are also native.
+  return native;
+}
+
+
 bool JSFunction::NeedsArgumentsAdaption() {
   return shared()->formal_parameter_count() !=
       SharedFunctionInfo::kDontAdaptArgumentsSentinel;
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index e89efdf471a5d624595e45acf7c074a824bc66a2..0c9afd7f474ba267b6506cf9a9e683df031a2fe8 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -7492,6 +7492,9 @@ class JSFunction: public JSObject {
   // Tells whether this function is builtin.
   inline bool IsBuiltin();

+  // Tells whether this function is defined in a native script.
+  inline bool IsNative();
+
   // Tells whether or not the function needs arguments adaption.
   inline bool NeedsArgumentsAdaption();

Index: test/mjsunit/debug-break-native.js
diff --git a/test/mjsunit/debug-break-native.js b/test/mjsunit/debug-break-native.js
new file mode 100644
index 0000000000000000000000000000000000000000..11d7274929c5bbc989bb7890e0c07c0d91d0492b
--- /dev/null
+++ b/test/mjsunit/debug-break-native.js
@@ -0,0 +1,42 @@
+// Copyright 2014 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
+
+Debug = debug.Debug
+var exception = null;
+
+function breakListener(event, exec_state, event_data, data) {
+  if (event != Debug.DebugEvent.Break) return;
+  try {
+    exec_state.prepareStep(Debug.StepAction.StepIn, 1);
+    // Assert that the break happens at an intended location.
+ assertTrue(exec_state.frame(0).sourceLineText().indexOf("// break") > 0);
+  } catch (e) {
+    exception = e;
+  }
+}
+
+Debug.setListener(breakListener);
+
+debugger;                          // break
+
+function f(x) {
+  return x;                        // break
+}                                  // break
+
+Debug.setBreakPoint(f, 0, 0);      // break
+Debug.scripts();                   // break
+debug.MakeMirror(f);               // break
+
+new Error("123").stack;            // break
+Math.sin(0);                       // break
+
+f("this should break");            // break
+
+Debug.setListener(null);           // break
+
+f("this should not break");
+
+assertNull(exception);


--
--
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