Commit 0cb38971 authored by jgruber's avatar jgruber Committed by Commit bot

[debugger] Basic scope functionality and exception events in wrapper

BUG=v8:5530

Review-Url: https://codereview.chromium.org/2487673002
Cr-Commit-Position: refs/heads/master@{#40840}
parent bdf04d99
......@@ -2,22 +2,16 @@
// 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;
var break_count = 0;
const expected_breaks = 8;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
// Count number of expected breakpoints in this source file.
if (!break_count) {
var source_text = exec_state.frame(0).func().script().source();
expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length;
print("Expected breaks: " + expected_breaks);
}
var frameMirror = exec_state.frame(0);
frameMirror.allScopes();
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
// Test debug events when we only listen to uncaught exceptions and a
// Promise p3 created by Promise.all has a catch handler, and is rejected
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
// Test debug events when we only listen to uncaught exceptions and a
// Promise p3 created by Promise.race has a catch handler, and is rejected
......
......@@ -2,7 +2,6 @@
// 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
// Test reentry of special try catch for Promises.
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
// Test debug events when we only listen to uncaught exceptions, the Promise
// is rejected, and a catch handler is installed right before the rejection.
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
// Test debug events when we only listen to uncaught exceptions and
// there is a catch handler for the to-be-rejected Promise.
......
......@@ -8,18 +8,12 @@
Debug = debug.Debug
var exception = null;
var break_count = 0;
var expected_breaks = -1;
const expected_breaks = 9;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
if (!break_count) {
// Count number of expected breakpoints in this source file.
var source_text = exec_state.frame(0).func().script().source();
expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length;
print("Expected breaks: " + expected_breaks);
}
var source = exec_state.frame(0).sourceLineText();
print("paused at: " + source);
assertTrue(source.indexOf("// Break " + break_count + ".") > 0,
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
// Test debug events when we only listen to uncaught exceptions, the Promise
// throws, and a catch handler is installed right before throwing.
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
// Test debug events when we only listen to uncaught exceptions and
// there is a catch handler for the exception thrown in a Promise.
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
// Test debug events when we only listen to uncaught exceptions and
// there is a catch handler for the to-be-rejected Promise.
......
......@@ -2,7 +2,6 @@
// 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 Debug = debug.Debug;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug
// Flags: --harmony-async-await
Debug = debug.Debug
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug
// Files: test/mjsunit/harmony/async-debug-caught-exception-cases.js
// Flags: --harmony-async-await
// Files: test/debugger/debug/harmony/async-debug-caught-exception-cases.js
runPart(0);
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug
// Files: test/mjsunit/harmony/async-debug-caught-exception-cases.js
// Flags: --harmony-async-await
// Files: test/debugger/debug/harmony/async-debug-caught-exception-cases.js
runPart(1);
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug
// Files: test/mjsunit/harmony/async-debug-caught-exception-cases.js
// Flags: --harmony-async-await
// Files: test/debugger/debug/harmony/async-debug-caught-exception-cases.js
runPart(2);
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug
// Files: test/mjsunit/harmony/async-debug-caught-exception-cases.js
// Flags: --harmony-async-await
// Files: test/debugger/debug/harmony/async-debug-caught-exception-cases.js
runPart(3);
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug
// Flags: --harmony-async-await
Debug = debug.Debug
......
......@@ -2,7 +2,7 @@
// 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 --allow-natives-syntax --harmony-async-await
// Flags: --harmony-async-await
var Debug = debug.Debug;
var step_count = 0;
......
......@@ -2,7 +2,7 @@
// 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 --allow-natives-syntax --harmony-async-await
// Flags: --harmony-async-await
var Debug = debug.Debug;
var step_count = 0;
......
......@@ -2,7 +2,7 @@
// 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 --allow-natives-syntax --harmony-async-await
// Flags: --harmony-async-await
var Debug = debug.Debug;
var step_count = 0;
......
......@@ -2,7 +2,7 @@
// 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 --allow-natives-syntax --harmony-async-await
// Flags: --harmony-async-await
var Debug = debug.Debug;
var step_count = 0;
......
......@@ -2,7 +2,7 @@
// 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 --allow-natives-syntax --harmony-async-await
// Flags: --harmony-async-await
var Debug = debug.Debug;
var step_count = 0;
......
......@@ -2,7 +2,7 @@
// 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 --allow-natives-syntax --harmony-async-await
// Flags: --harmony-async-await
var Debug = debug.Debug;
var step_count = 0;
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
var Debug = debug.Debug;
......
......@@ -2,7 +2,6 @@
// 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 --allow-natives-syntax
var Debug = debug.Debug;
......
......@@ -2,7 +2,6 @@
// 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 exception = null;
......
......@@ -2,7 +2,6 @@
// 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
// Test that hidden scopes are correctly walked in the scope chain.
......
......@@ -2,7 +2,7 @@
// 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 --allow-natives-syntax --noturbo
// Flags: --noturbo
var Debug = debug.Debug
var exception = null;
......
......@@ -220,10 +220,33 @@ class DebugWrapper {
}
}
execStateScopeType(type) {
switch (type) {
case "global": return this.ScopeType.Global;
case "local": return this.ScopeType.Local;
case "with": return this.ScopeType.With;
case "closure": return this.ScopeType.Closure;
case "catch": return this.ScopeType.Catch;
case "block": return this.ScopeType.Block;
case "script": return this.ScopeType.Script;
default: %AbortJS("Unexpected scope type");
}
}
// Returns an array of property descriptors of the scope object.
// This is in contrast to the original API, which simply passed object
// mirrors.
execStateScopeObject(obj) {
const {msgid, msg} = this.createMessage(
"Runtime.getProperties", { objectId : obj.objectId });
this.sendMessage(msg);
const reply = this.takeReplyChecked(msgid);
return { value : () => reply.result.result };
}
execStateScope(scope) {
// TODO(jgruber): Mapping
return { scopeType: () => scope.type,
scopeObject: () => scope.object
return { scopeType : () => this.execStateScopeType(scope.type),
scopeObject : () => this.execStateScopeObject(scope.object)
};
}
......@@ -237,7 +260,9 @@ class DebugWrapper {
functionName : () => frame.functionName,
func : () => func,
scopeCount : () => frame.scopeChain.length,
scope : (index) => this.execStateScope(frame.scopeChain[index])
scope : (index) => this.execStateScope(frame.scopeChain[index]),
allScopes : () => frame.scopeChain.map(
this.execStateScope.bind(this))
};
}
......@@ -255,6 +280,18 @@ class DebugWrapper {
handleDebuggerPaused(message) {
const params = message.params;
var debugEvent;
switch (params.reason) {
case "exception":
case "promiseRejection":
debugEvent = this.DebugEvent.Exception;
break;
default:
// TODO(jgruber): More granularity.
debugEvent = this.DebugEvent.Break;
break;
}
// Skip break events in this file.
if (params.callFrames[0].location.scriptId == this.thisScriptId) return;
......@@ -267,7 +304,7 @@ class DebugWrapper {
frameCount : () => params.callFrames.length
};
let eventData = this.execStateFrame(params.callFrames[0]);
this.invokeListener(this.DebugEvent.Break, execState, eventData);
this.invokeListener(debugEvent, execState, eventData);
}
handleDebuggerScriptParsed(message) {
......@@ -291,6 +328,7 @@ class DebugWrapper {
// Simulate the debug object generated by --expose-debug-as debug.
var debug = { instance : undefined };
Object.defineProperty(debug, 'Debug', { get: function() {
if (!debug.instance) {
debug.instance = new DebugWrapper();
......@@ -298,3 +336,8 @@ Object.defineProperty(debug, 'Debug', { get: function() {
}
return debug.instance;
}});
Object.defineProperty(debug, 'ScopeType', { get: function() {
const instance = debug.Debug;
return instance.ScopeType;
}});
......@@ -8,6 +8,7 @@ import re
from testrunner.local import testsuite
from testrunner.objects import testcase
FILES_PATTERN = re.compile(r"//\s+Files:(.*)")
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
class DebuggerTestSuite(testsuite.TestSuite):
......@@ -38,9 +39,21 @@ class DebuggerTestSuite(testsuite.TestSuite):
for match in flags_match:
flags += match.strip().split()
files_list = [] # List of file names to append to command arguments.
files_match = FILES_PATTERN.search(source);
# Accept several lines of 'Files:'.
while True:
if files_match:
files_list += files_match.group(1).strip().split()
files_match = FILES_PATTERN.search(source, files_match.end())
else:
break
files = []
files.append(os.path.normpath(os.path.join(self.root, "..", "mjsunit", "mjsunit.js")))
files.append(os.path.join(self.root, "test-api.js"))
files.extend([ os.path.normpath(os.path.join(self.root, '..', '..', f))
for f in files_list ])
files.append(os.path.join(self.root, testcase.path + self.suffix()))
flags += files
......
......@@ -7,18 +7,12 @@
Debug = debug.Debug
var exception = null;
var break_count = 0;
var expected_breaks = -1;
const expected_breaks = 9;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
if (!break_count) {
// Count number of expected breakpoints in this source file.
var source_text = exec_state.frame(0).func().script().source();
expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length;
print("Expected breaks: " + expected_breaks);
}
var source = exec_state.frame(0).sourceLineText();
print("paused at: " + source);
assertTrue(source.indexOf("// Break " + break_count + ".") > 0,
......
......@@ -7,6 +7,7 @@
Debug = debug.Debug
var exception = null;
var break_count = 0;
const expected_breaks = 9;
var expected_values =
[ReferenceError, undefined, 0, 0, 0, 0, 1,
......@@ -16,12 +17,6 @@ function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
// Count number of expected breakpoints in this source file.
if (!break_count) {
var source_text = exec_state.frame(0).func().script().source();
expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length;
print("Expected breaks: " + expected_breaks);
}
var frameMirror = exec_state.frame(0);
var v = null;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment