Commit 44c76119 authored by yangguo's avatar yangguo Committed by Commit bot

[debugger] remove remaining uses of the debug command processor.

R=jgruber@chromium.org
BUG=v8:5510

Review-Url: https://codereview.chromium.org/2557043005
Cr-Commit-Position: refs/heads/master@{#41610}
parent dd10d9b1
......@@ -34,55 +34,17 @@ listenerComplete = false;
exception = false;
var breakpoint = -1;
var base_request = '"seq":0,"type":"request","command":"changebreakpoint"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testArguments(dcp, arguments, success) {
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
if (success) {
assertTrue(response.success, json_response);
} else {
assertFalse(response.success, json_response);
}
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test some illegal clearbreakpoint requests.
var request = '{' + base_request + '}'
var response = safeEval(dcp.processDebugJSONRequest(request));
assertFalse(response.success);
testArguments(dcp, '{}', false);
testArguments(dcp, '{"breakpoint":0,"condition":"false"}', false);
testArguments(dcp, '{"breakpoint":' + (breakpoint + 1) + ',"condition":"false"}', false);
testArguments(dcp, '{"breakpoint":"xx","condition":"false"}', false);
// Test some legal clearbreakpoint requests.
var bp_str = '"breakpoint":' + breakpoint;;
testArguments(dcp, '{' + bp_str + '}', true);
testArguments(dcp, '{' + bp_str + ',"enabled":"true"}', true);
testArguments(dcp, '{' + bp_str + ',"enabled":"false"}', true);
testArguments(dcp, '{' + bp_str + ',"condition":"1==2"}', true);
testArguments(dcp, '{' + bp_str + ',"condition":"false"}', true);
// Indicate that all was processed.
listenerComplete = true;
}
if (event == Debug.DebugEvent.Break) {
// Test some legal clearbreakpoint requests.
Debug.enableBreakPoint(breakpoint);
Debug.disableBreakPoint(breakpoint);
Debug.changeBreakPointCondition(breakpoint, "1==2");
Debug.changeBreakPointCondition(breakpoint, "false");
listenerComplete = true;
}
} catch (e) {
exception = e
};
......
......@@ -34,53 +34,15 @@ listenerComplete = false;
exception = false;
var breakpoint = -1;
var base_request = '"seq":0,"type":"request","command":"clearbreakpoint"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testArguments(dcp, arguments, success) {
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
if (success) {
assertTrue(response.success, json_response);
} else {
assertFalse(response.success, json_response);
}
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test some illegal clearbreakpoint requests.
var request = '{' + base_request + '}'
var response = safeEval(dcp.processDebugJSONRequest(request));
assertFalse(response.success);
testArguments(dcp, '{}', false);
testArguments(dcp, '{"breakpoint":0}', false);
testArguments(dcp, '{"breakpoint":' + (breakpoint + 1)+ '}', false);
testArguments(dcp, '{"breakpoint":"xx"}', false);
// Test some legal clearbreakpoint requests.
testArguments(dcp, '{"breakpoint":' + breakpoint + '}', true);
// Cannot clear the same break point twice.
testArguments(dcp, '{"breakpoint":' + breakpoint + '}', false);
// Indicate that all was processed.
listenerComplete = true;
}
if (event == Debug.DebugEvent.Break) {
// Clear once.
Debug.clearBreakPoint(breakpoint);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
......
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object.
var Debug = debug.Debug
// Simple function which stores the last debug event.
var listenerComplete = false;
var exception = false;
var base_request = '"seq":0,"type":"request","command":"clearbreakpointgroup"';
var scriptId = null;
var muteListener = false;
function safeEval(code) {
try {
muteListener = true;
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
} finally {
muteListener = false;
}
}
function testArguments(dcp, arguments, success) {
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
if (success) {
assertTrue(response.success, json_response);
} else {
assertFalse(response.success, json_response);
}
}
function listener(event, exec_state, event_data, data) {
if (muteListener) return;
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Clear breakpoint group 1.
testArguments(dcp, '{"groupId":1}', true);
// Indicate that all was processed.
listenerComplete = true;
} else if (event == Debug.DebugEvent.AfterCompile) {
scriptId = event_data.script().id();
assertEquals(source, event_data.script().source());
}
} catch (e) {
exception = e
};
};
// Add the debug event listener.
Debug.setListener(listener);
var source = 'function f(n) {\nreturn n+1;\n}\nfunction g() {return f(10);}' +
'\nvar r = g(); g;';
eval(source);
assertNotNull(scriptId);
var groupId1 = 1;
var groupId2 = 2;
// Set a break point and call to invoke the debug event listener.
var bp1 = Debug.setScriptBreakPointById(scriptId, 1, null, null, groupId1);
var bp2 = Debug.setScriptBreakPointById(scriptId, 1, null, null, groupId2);
var bp3 = Debug.setScriptBreakPointById(scriptId, 1, null, null, null);
var bp4 = Debug.setScriptBreakPointById(scriptId, 3, null, null, groupId1);
var bp5 = Debug.setScriptBreakPointById(scriptId, 4, null, null, groupId2);
assertEquals(5, Debug.scriptBreakPoints().length);
// Call function 'g' from the compiled script to trigger breakpoint.
g();
// Make sure that the debug event listener vas invoked.
assertTrue(listenerComplete,
"listener did not run to completion: " + exception);
var breakpoints = Debug.scriptBreakPoints();
assertEquals(3, breakpoints.length);
var breakpointNumbers = breakpoints.map(
function(scriptBreakpoint) { return scriptBreakpoint.number(); },
breakpointNumbers);
// Check that all breakpoints from group 1 were deleted and all the
// rest are preserved.
assertEquals([bp2, bp3, bp5].sort(), breakpointNumbers.sort());
assertFalse(exception, "exception in listener");
// Clear all breakpoints to allow the test to run again (--stress-opt).
Debug.clearBreakPoint(bp2);
Debug.clearBreakPoint(bp3);
Debug.clearBreakPoint(bp5);
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
// Simple function which stores the last debug event.
listenerComplete = false;
exception = false;
var base_request = '"seq":0,"type":"request","command":"continue"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testArguments(exec_state, arguments, success) {
// Get the debug command processor in paused state.
var dcp = exec_state.debugCommandProcessor(false);
// Generate request with the supplied arguments
var request;
if (arguments) {
request = '{' + base_request + ',"arguments":' + arguments + '}';
} else {
request = '{' + base_request + '}'
}
var response = safeEval(dcp.processDebugJSONRequest(request));
if (success) {
assertTrue(response.success, request + ' -> ' + response.message);
assertTrue(response.running, request + ' -> expected running');
} else {
assertFalse(response.success, request + ' -> ' + response.message);
assertFalse(response.running, request + ' -> expected not running');
}
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Test simple continue request.
testArguments(exec_state, void 0, true);
// Test some illegal continue requests.
testArguments(exec_state, '{"stepaction":"maybe"}', false);
// Test some legal continue requests.
testArguments(exec_state, '{"stepaction":"in"}', true);
testArguments(exec_state, '{"stepaction":"next"}', true);
testArguments(exec_state, '{"stepaction":"out"}', true);
// Step count argument is ignored.
testArguments(exec_state, '{"stepcount":-1}', true);
testArguments(exec_state, '{"stepcount":1}', true);
testArguments(exec_state, '{"stepcount":10}', true);
testArguments(exec_state, '{"stepcount":"10"}', true);
testArguments(exec_state, '{"stepaction":"next","stepcount":10}', true);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
a=1
};
function g() {
f();
};
// Set a break point and call to invoke the debug event listener.
Debug.setBreakPoint(g, 0, 0);
g();
assertFalse(exception, "exception in listener")
// Make sure that the debug event listener vas invoked.
assertTrue(listenerComplete, "listener did not run to completion");
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
listenerComplete = false;
exception = false;
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
// Send an evaluation request and return the handle of the result.
function evaluateRequest(exec_state, arguments) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// The base part of all evaluate requests.
var base_request = '"seq":0,"type":"request","command":"evaluate"'
// Generate request with the supplied arguments.
var request;
if (arguments) {
request = '{' + base_request + ',"arguments":' + arguments + '}';
} else {
request = '{' + base_request + '}'
}
var response = safeEval(dcp.processDebugJSONRequest(request));
assertTrue(response.success, request + ' -> ' + response.message);
return response.body.handle;
}
// Send a lookup request and return the evaluated JSON response.
function lookupRequest(exec_state, arguments, success) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// The base part of all lookup requests.
var base_request = '"seq":0,"type":"request","command":"lookup"'
// Generate request with the supplied arguments.
var request;
if (arguments) {
request = '{' + base_request + ',"arguments":' + arguments + '}';
} else {
request = '{' + base_request + '}'
}
var response = safeEval(dcp.processDebugJSONRequest(request));
if (success) {
assertTrue(response.success, request + ' -> ' + response.message);
} else {
assertFalse(response.success, request + ' -> ' + response.message);
}
assertEquals(response.running, dcp.isRunning(), request + ' -> expected not running');
return response;
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Test some illegal lookup requests.
lookupRequest(exec_state, void 0, false);
lookupRequest(exec_state, '{"handles":["a"]}', false);
lookupRequest(exec_state, '{"handles":[-1]}', false);
// Evaluate and get some handles.
var handle_o = evaluateRequest(exec_state, '{"expression":"o"}');
var handle_p = evaluateRequest(exec_state, '{"expression":"p"}');
var handle_b = evaluateRequest(exec_state, '{"expression":"a"}');
var handle_a = evaluateRequest(exec_state, '{"expression":"b","frame":1}');
assertEquals(handle_o, handle_a);
assertEquals(handle_a, handle_b);
assertFalse(handle_o == handle_p, "o and p have the same handle");
var response;
var count;
response = lookupRequest(exec_state, '{"handles":[' + handle_o + ']}', true);
var obj = response.body[handle_o];
assertTrue(!!obj, 'Object not found: ' + handle_o);
assertEquals(handle_o, obj.handle);
count = 0;
for (i in obj.properties) {
switch (obj.properties[i].name) {
case 'o':
obj.properties[i].ref = handle_o;
count++;
break;
case 'p':
obj.properties[i].ref = handle_p;
count++;
break;
}
}
assertEquals(2, count, 'Either "o" or "p" not found');
response = lookupRequest(exec_state, '{"handles":[' + handle_p + ']}', true);
obj = response.body[handle_p];
assertTrue(!!obj, 'Object not found: ' + handle_p);
assertEquals(handle_p, obj.handle);
// Check handles for functions on the stack.
var handle_f = evaluateRequest(exec_state, '{"expression":"f"}');
var handle_g = evaluateRequest(exec_state, '{"expression":"g"}');
var handle_caller = evaluateRequest(exec_state, '{"expression":"f.caller"}');
assertFalse(handle_f == handle_g, "f and g have the same handle");
assertEquals(handle_g, handle_caller, "caller for f should be g");
response = lookupRequest(exec_state, '{"handles":[' + handle_f + ']}', true);
obj = response.body[handle_f];
assertEquals(handle_f, obj.handle);
count = 0;
for (i in obj.properties) {
var ref = obj.properties[i].ref;
var arguments = '{"handles":[' + ref + ']}';
switch (obj.properties[i].name) {
case 'name':
var response_name;
response_name = lookupRequest(exec_state, arguments, true);
assertEquals('string', response_name.body[ref].type);
assertEquals("f", response_name.body[ref].value);
count++;
break;
case 'length':
var response_length;
response_length = lookupRequest(exec_state, arguments, true);
assertEquals('number', response_length.body[ref].type);
assertEquals(1, response_length.body[ref].value);
count++;
break;
case 'caller':
assertEquals(handle_g, obj.properties[i].ref);
count++;
break;
}
}
assertEquals(3, count, 'Either "name", "length" or "caller" not found');
// Resolve all at once.
var refs = [];
for (i in obj.properties) {
refs.push(obj.properties[i].ref);
}
var arguments = '{"handles":[' + refs.join(',') + ']}';
response = lookupRequest(exec_state, arguments, true);
count = 0;
for (i in obj.properties) {
var ref = obj.properties[i].ref;
var val = response.body[ref];
assertTrue(!!val, 'Failed to lookup "' + obj.properties[i].name + '"');
switch (obj.properties[i].name) {
case 'name':
assertEquals('string', val.type);
assertEquals("f", val.value);
count++;
break;
case 'length':
assertEquals('number', val.type);
assertEquals(1, val.value);
count++;
break;
case 'caller':
assertEquals('function', val.type);
assertEquals(handle_g, ref);
count++;
break;
}
}
assertEquals(3, count, 'Either "name", "length" or "caller" not found');
count = 0;
for (var handle in response.body) {
assertTrue(refs.indexOf(parseInt(handle)) != -1,
'Handle not in the request: ' + handle);
count++;
}
assertEquals(count, obj.properties.length,
'Unexpected number of resolved objects');
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f(a) {
debugger;
};
function g(b) {
f(b);
};
// Set a break point at return in f and invoke g to hit the breakpoint.
Debug.setBreakPoint(f, 2, 0);
o = {};
p = {}
o.o = o;
o.p = p;
p.o = o;
p.p = p;
g(o);
assertFalse(exception, "exception in listener")
// Make sure that the debug event listener vas invoked.
assertTrue(listenerComplete, "listener did not run to completion: " + exception);
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
// Note: the following tests only checks the debugger handling of the
// setexceptionbreak command. It does not test whether the debugger
// actually breaks on exceptions or not. That functionality is tested
// in test-debug.cc instead.
// Note: The following function g() is purposedly placed here so that
// its line numbers will not change should we add more lines of test code
// below. The test checks for these line numbers.
function g() { // line 40
var x = 5;
var y = 6;
var z = 7;
};
var first_lineno = 40; // Must be the line number of g() above.
// The first line of the file is line 0.
// Simple function which stores the last debug event.
listenerComplete = false;
exception = false;
var breakpoint1 = -1;
var base_request = '"seq":0,"type":"request","command":"listbreakpoints"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function clearBreakpoint(dcp, breakpoint_id) {
var base_request = '"seq":0,"type":"request","command":"clearbreakpoint"'
var arguments = '{"breakpoint":' + breakpoint_id + '}'
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
}
function setBreakOnException(dcp, type, enabled) {
var base_request = '"seq":0,"type":"request","command":"setexceptionbreak"'
var arguments = '{"type":"' + type + '","enabled":' + enabled + '}'
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
}
function testArguments(dcp, success, breakpoint_ids, breakpoint_linenos,
break_on_all, break_on_uncaught) {
var request = '{' + base_request + '}'
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
var num_breakpoints = breakpoint_ids.length;
if (success) {
assertTrue(response.success, json_response);
assertEquals(response.body.breakpoints.length, num_breakpoints);
if (num_breakpoints > 0) {
var breakpoints = response.body.breakpoints;
for (var i = 0; i < breakpoints.length; i++) {
var id = breakpoints[i].number;
var found = false;
for (var j = 0; j < num_breakpoints; j++) {
if (breakpoint_ids[j] == id) {
assertEquals(breakpoints[i].line, breakpoint_linenos[j]);
found = true;
break;
}
}
assertTrue(found, "found unexpected breakpoint " + id);
}
}
assertEquals(response.body.breakOnExceptions, break_on_all);
assertEquals(response.body.breakOnUncaughtExceptions, break_on_uncaught);
} else {
assertFalse(response.success, json_response);
}
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test with the 1 breakpoint already set:
testArguments(dcp, true, [ breakpoint1 ], [ first_lineno ], false, false);
setBreakOnException(dcp, "all", true);
testArguments(dcp, true, [ breakpoint1 ], [ first_lineno ], true, false);
setBreakOnException(dcp, "uncaught", true);
testArguments(dcp, true, [ breakpoint1 ], [ first_lineno ], true, true);
setBreakOnException(dcp, "all", false);
testArguments(dcp, true, [ breakpoint1 ], [ first_lineno ], false, true);
setBreakOnException(dcp, "uncaught", false);
testArguments(dcp, true, [ breakpoint1 ], [ first_lineno ], false, false);
// Clear the one breakpoint and retest:
clearBreakpoint(dcp, breakpoint1);
testArguments(dcp, true, [], [], false, false);
setBreakOnException(dcp, "all", true);
testArguments(dcp, true, [], [], true, false);
setBreakOnException(dcp, "uncaught", true);
testArguments(dcp, true, [], [], true, true);
setBreakOnException(dcp, "all", false);
testArguments(dcp, true, [], [], false, true);
setBreakOnException(dcp, "uncaught", false);
testArguments(dcp, true, [], [], false, false);
// Set some more breakpoints, and clear them in various orders:
var bp2 = Debug.setBreakPoint(g, 1, 0);
testArguments(dcp, true, [ bp2 ],
[ first_lineno + 1 ],
false, false);
var bp3 = Debug.setBreakPoint(g, 2, 0);
testArguments(dcp, true, [ bp2, bp3 ],
[ first_lineno + 1, first_lineno + 2 ],
false, false);
var bp4 = Debug.setBreakPoint(g, 3, 0);
testArguments(dcp, true, [ bp2, bp3, bp4 ],
[ first_lineno + 1, first_lineno + 2, first_lineno + 3 ],
false, false);
clearBreakpoint(dcp, bp3);
testArguments(dcp, true, [ bp2, bp4 ],
[ first_lineno + 1, first_lineno + 3 ],
false, false);
clearBreakpoint(dcp, bp4);
testArguments(dcp, true, [ bp2 ],
[ first_lineno + 1 ],
false, false);
var bp5 = Debug.setBreakPoint(g, 3, 0);
testArguments(dcp, true, [ bp2, bp5 ],
[ first_lineno + 1, first_lineno + 3 ],
false, false);
clearBreakpoint(dcp, bp2);
testArguments(dcp, true, [ bp5 ],
[ first_lineno + 3 ],
false, false);
clearBreakpoint(dcp, bp5);
testArguments(dcp, true, [], [], false, false);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
};
// Add the debug event listener.
Debug.setListener(listener);
// Set a break point and call to invoke the debug event listener.
breakpoint1 = Debug.setBreakPoint(g, 0, 0);
g();
// Make sure that the debug event listener vas invoked.
assertFalse(exception, "exception in listener")
assertTrue(listenerComplete, "listener did not run to completion");
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// The functions used for testing backtraces. They are at the top to make the
// testing of source line/column easier.
function f(x, y) {
a=1;
};
function g() {
new f(1);
};
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
listenerCallCount = 0;
listenerExceptions = [];
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break)
{
listenerCallCount++;
// Check that mirror cache is cleared when entering debugger.
assertTrue(debug.MirrorCacheIsEmpty(), "Mirror cache not cleared");
// Get the debug command processor in paused state.
var dcp = exec_state.debugCommandProcessor(false);
// Make a backtrace request to create some mirrors.
var json;
json = '{"seq":0,"type":"request","command":"backtrace"}'
dcp.processDebugJSONRequest(json);
// Make sure looking up loaded scripts does not clear the cache.
Debug.scripts();
// Some mirrors where cached.
assertFalse(debug.MirrorCacheIsEmpty(), "Mirror cache not used");
}
} catch (e) {
print(e);
listenerExceptions.push(e);
};
};
// Add the debug event listener.
Debug.setListener(listener);
// Enter the debugger twice.
debugger;
debugger;
assertEquals([], listenerExceptions, "Exception in listener");
// Make sure that the debug event listener vas invoked.
assertEquals(2, listenerCallCount, "Listener not called");
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --stack-trace-on-illegal
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
listenerComplete = false;
exception = false;
// The base part of all evaluate requests.
var base_request = '"seq":0,"type":"request","command":"references"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testRequest(dcp, arguments, success, count) {
// Generate request with the supplied arguments.
var request;
if (arguments) {
request = '{' + base_request + ',"arguments":' + arguments + '}';
} else {
request = '{' + base_request + '}'
}
// Process the request and check expectation.
var response = safeEval(dcp.processDebugJSONRequest(request));
if (success) {
assertTrue(response.success, request + ' -> ' + response.message);
assertTrue(response.body instanceof Array);
if (count) {
assertEquals(count, response.body.length);
} else {
assertTrue(response.body.length > 0);
}
} else {
assertFalse(response.success, request + ' -> ' + response.message);
}
assertEquals(response.running, dcp.isRunning(), request + ' -> expected not running');
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test some illegal references requests.
testRequest(dcp, void 0, false);
testRequest(dcp, '{"handle":"a"}', false);
testRequest(dcp, '{"handle":1}', false);
testRequest(dcp, '{"type":"referencedBy"}', false);
testRequest(dcp, '{"type":"constructedBy"}', false);
// Evaluate Point.
var evaluate_point = '{"seq":0,"type":"request","command":"evaluate",' +
'"arguments":{"expression":"Point"}}';
var response = safeEval(dcp.processDebugJSONRequest(evaluate_point));
assertTrue(response.success, "Evaluation of Point failed");
var handle = response.body.handle;
// Test some legal references requests.
testRequest(dcp, '{"handle":' + handle + ',"type":"referencedBy"}', true);
testRequest(dcp, '{"handle":' + handle + ',"type":"constructedBy"}',
true, 2);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e;
print(e + "\n" + e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
// Test constructor and objects.
function Point(x, y) { this.x_ = x; this.y_ = y;}
p = new Point(0,0);
q = new Point(1,2);
// Enter debugger causing the event listener to be called.
debugger;
// Make sure that the debug event listener was invoked.
assertFalse(exception, "exception in listener")
assertTrue(listenerComplete, "listener did not run to completion");
......@@ -29,38 +29,6 @@
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
function ParsedResponse(json) {
this.response_ = eval('(' + json + ')');
this.refs_ = [];
if (this.response_.refs) {
for (var i = 0; i < this.response_.refs.length; i++) {
this.refs_[this.response_.refs[i].handle] = this.response_.refs[i];
}
}
}
ParsedResponse.prototype.response = function() {
return this.response_;
}
ParsedResponse.prototype.body = function() {
return this.response_.body;
}
ParsedResponse.prototype.running = function() {
return this.response_.running;
}
ParsedResponse.prototype.lookup = function(handle) {
return this.refs_[handle];
}
listener_complete = false;
exception = false;
break_count = 0;
......@@ -109,16 +77,6 @@ function listener(event, exec_state, event_data, data) {
assertEquals(expected_return_value,
exec_state.frame(0).returnValue().value());
// Check the same using the JSON commands.
var dcp = exec_state.debugCommandProcessor(false);
var request = '{"seq":0,"type":"request","command":"backtrace"}';
var resp = dcp.processDebugJSONRequest(request);
response = new ParsedResponse(resp);
frames = response.body().frames;
assertTrue(frames[0].atReturn);
assertEquals(expected_return_value,
response.lookup(frames[0].returnValue.ref).value);
listener_complete = true;
}
}
......
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
// State to check that the listener code was invoked and that no exceptions
// occoured.
listenerComplete = false;
exception = false;
var base_request = '"seq":0,"type":"request","command":"scripts"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testArguments(dcp, arguments, success) {
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
if (success) {
assertTrue(response.success, json_response);
} else {
assertFalse(response.success, json_response);
}
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test illegal scripts requests.
testArguments(dcp, '{"types":"xx"}', false);
// Test legal scripts requests.
testArguments(dcp, '{}', true);
testArguments(dcp, '{"types":1}', true);
testArguments(dcp, '{"types":2}', true);
testArguments(dcp, '{"types":4}', true);
testArguments(dcp, '{"types":7}', true);
testArguments(dcp, '{"types":255}', true);
// Test request for all scripts.
var request = '{' + base_request + '}'
var response = safeEval(dcp.processDebugJSONRequest(request));
assertTrue(response.success);
// Test filtering by id. We have to get at least one script back, but
// the exact number depends on the timing of GC.
assertTrue(response.body.length >= 1);
var script = response.body[0];
var request = '{' + base_request + ',"arguments":{"ids":[' +
script.id + ']}}';
var response = safeEval(dcp.processDebugJSONRequest(request));
assertTrue(response.success);
assertEquals(1, response.body.length);
assertEquals(script.id, response.body[0].id);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
};
// Add the debug event listener.
Debug.setListener(listener);
// Call debugger to invoke the debug event listener.
debugger;
// Make sure that the debug event listener vas invoked with no exceptions.
assertTrue(listenerComplete,
"listener did not run to completion, exception: " + exception);
assertFalse(exception, "exception in listener")
Debug.setListener(null);
......@@ -37,95 +37,29 @@ var g_script_id = 0;
var h_script_id = 0;
var f_line = 0;
var g_line = 0;
var base_request = '"seq":0,"type":"request","command":"setbreakpoint"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testArguments(dcp, arguments, success, is_script) {
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
if (success) {
assertTrue(response.success, request + ' -> ' + json_response);
if (is_script) {
assertEquals('scriptName', response.body.type, request + ' -> ' + json_response);
} else {
assertEquals('scriptId', response.body.type, request + ' -> ' + json_response);
}
} else {
assertFalse(response.success, request + ' -> ' + json_response);
}
return response;
}
var h_line = 0;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test some illegal setbreakpoint requests.
var request = '{' + base_request + '}'
var response = safeEval(dcp.processDebugJSONRequest(request));
assertFalse(response.success);
var mirror;
testArguments(dcp, '{}', false);
testArguments(dcp, '{"type":"xx"}', false);
testArguments(dcp, '{"type":"function"}', false);
testArguments(dcp, '{"type":"script"}', false);
testArguments(dcp, '{"target":"f"}', false);
testArguments(dcp, '{"type":"xx","target":"xx"}', false);
testArguments(dcp, '{"type":"function","target":1}', false);
testArguments(dcp, '{"type":"function","target":"f","line":-1}', false);
testArguments(dcp, '{"type":"function","target":"f","column":-1}', false);
testArguments(dcp, '{"type":"handle","target":"-1"}', false);
mirror = debug.MakeMirror(o);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', false);
// Test some legal setbreakpoint requests.
testArguments(dcp, '{"type":"function","target":"f"}', true, false);
testArguments(dcp, '{"type":"function","target":"h"}', true, false);
testArguments(dcp, '{"type":"function","target":"f","line":1}', true, false);
testArguments(dcp, '{"type":"function","target":"f","position":1}', true, false);
testArguments(dcp, '{"type":"function","target":"f","condition":"i == 1"}', true, false);
testArguments(dcp, '{"type":"function","target":"f","enabled":true}', true, false);
testArguments(dcp, '{"type":"function","target":"f","enabled":false}', true, false);
testArguments(dcp, '{"type":"script","target":"test"}', true, true);
testArguments(dcp, '{"type":"script","target":"test"}', true, true);
testArguments(dcp, '{"type":"script","target":"test","line":1}', true, true);
testArguments(dcp, '{"type":"script","target":"test","column":1}', true, true);
testArguments(dcp, '{"type":"scriptId","target":' + f_script_id + ',"line":' + f_line + '}', true, false);
testArguments(dcp, '{"type":"scriptId","target":' + g_script_id + ',"line":' + g_line + '}', true, false);
testArguments(dcp, '{"type":"scriptId","target":' + h_script_id + ',"line":' + h_line + '}', true, false);
mirror = debug.MakeMirror(f);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', true, false);
mirror = debug.MakeMirror(o.a);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', true, false);
testArguments(dcp, '{"type":"script","target":"sourceUrlScript","line":0}', true, true);
// Set a break point on a line with the comment, and check that actual position
// is the next line after the comment.
request = '{"type":"scriptId","target":' + g_script_id + ',"line":' + (g_line + 1) + '}';
response = testArguments(dcp, request, true, false);
assertEquals(g_line + 2, response.body.actual_locations[0].line);
// Indicate that all was processed.
listenerComplete = true;
}
if (event == Debug.DebugEvent.Break) {
Debug.setBreakPoint(exec_state.evaluateGlobal("f").value());
Debug.setBreakPoint(exec_state.evaluateGlobal("h").value());
Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1);
Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1);
Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(),
undefined, undefined, "i == 1");
Debug.setScriptBreakPointByName("test");
Debug.setScriptBreakPointByName("test", 1);
Debug.setScriptBreakPointByName("test", 1, 1);
Debug.setScriptBreakPointByName(f_script_id, f_line);
Debug.setScriptBreakPointByName(g_script_id, g_line);
Debug.setScriptBreakPointByName(h_script_id, h_line);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
......@@ -185,6 +119,8 @@ function breakListener(event) {
breakListenerCalled = true;
}
Debug.setBreakPoint(sourceUrlFunc);
Debug.setListener(breakListener);
sourceUrlFunc();
......
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
// Note: the following tests only checks the debugger handling of the
// setexceptionbreak command. It does not test whether the debugger
// actually breaks on exceptions or not. That functionality is tested
// in test-debug.cc instead.
// Simple function which stores the last debug event.
listenerComplete = false;
exception = false;
var breakpoint = -1;
var base_request = '"seq":0,"type":"request","command":"setexceptionbreak"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testArguments(dcp, arguments, success, type, enabled) {
var request = '{' + base_request + ',"arguments":' + arguments + '}'
var json_response = dcp.processDebugJSONRequest(request);
var response = safeEval(json_response);
if (success) {
assertTrue(response.success, json_response);
assertEquals(response.body.type, type);
assertEquals(response.body.enabled, enabled);
} else {
assertFalse(response.success, json_response);
}
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test some illegal setexceptionbreak requests.
var request = '{' + base_request + '}'
var response = safeEval(dcp.processDebugJSONRequest(request));
assertFalse(response.success);
testArguments(dcp, '{}', false);
testArguments(dcp, '{"type":0}', false);
// Test some legal setexceptionbreak requests with default.
// Note: by default, break on exceptions should be disabled. Hence,
// the first time, we send the command with no enabled arg, the debugger
// should toggle it on. The second time, it should toggle it off.
testArguments(dcp, '{"type":"all"}', true, "all", true);
testArguments(dcp, '{"type":"all"}', true, "all", false);
testArguments(dcp, '{"type":"uncaught"}', true, "uncaught", true);
testArguments(dcp, '{"type":"uncaught"}', true, "uncaught", false);
// Test some legal setexceptionbreak requests with explicit enabled arg.
testArguments(dcp, '{"type":"all","enabled":true}', true, "all", true);
testArguments(dcp, '{"type":"all","enabled":false}', true, "all", false);
testArguments(dcp, '{"type":"uncaught","enabled":true}', true,
"uncaught", true);
testArguments(dcp, '{"type":"uncaught","enabled":false}', true,
"uncaught", false);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
};
// Add the debug event listener.
Debug.setListener(listener);
function g() {};
// Set a break point and call to invoke the debug event listener.
breakpoint = Debug.setBreakPoint(g, 0, 0);
g();
// Make sure that the debug event listener vas invoked.
assertFalse(exception, "exception in listener")
assertTrue(listenerComplete, "listener did not run to completion");
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
// Simple function which stores the last debug event.
listenerComplete = false;
exception = false;
var base_backtrace_request = '"seq":0,"type":"request","command":"backtrace"'
var base_suspend_request = '"seq":0,"type":"request","command":"suspend"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testArguments(exec_state) {
// Get the debug command processor in running state.
var dcp = exec_state.debugCommandProcessor(true);
assertTrue(dcp.isRunning());
var backtrace_request = '{' + base_backtrace_request + '}'
var backtrace_response = safeEval(dcp.processDebugJSONRequest(backtrace_request));
assertTrue(backtrace_response.success);
assertTrue(backtrace_response.running, backtrace_request + ' -> expected running');
assertTrue(dcp.isRunning());
var suspend_request = '{' + base_suspend_request + '}'
var suspend_response = safeEval(dcp.processDebugJSONRequest(suspend_request));
assertTrue(suspend_response.success);
assertFalse(suspend_response.running, suspend_request + ' -> expected not running');
assertFalse(dcp.isRunning());
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Test simple suspend request.
testArguments(exec_state);
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
exception = e
};
};
// Add the debug event listener.
Debug.setListener(listener);
// Stop debugger and check that suspend command changes running flag.
debugger;
assertFalse(exception, "exception in listener")
// Make sure that the debug event listener vas invoked.
assertTrue(listenerComplete, "listener did not run to completion");
......@@ -79,32 +79,6 @@ function CheckScopeChain(scopes, exec_state) {
assertScopeMirrorEquals(all_scopes[i], scope);
}
CheckFastAllScopes(scopes, exec_state);
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Send a scopes request and check the result.
var json;
var request_json = '{"seq":0,"type":"request","command":"scopes"}';
var response_json = dcp.processDebugJSONRequest(request_json);
var response = JSON.parse(response_json);
assertEquals(scopes.length, response.body.scopes.length);
for (var i = 0; i < scopes.length; i++) {
assertEquals(i, response.body.scopes[i].index);
assertEquals(scopes[i], response.body.scopes[i].type);
if (scopes[i] == debug.ScopeType.Local ||
scopes[i] == debug.ScopeType.Script ||
scopes[i] == debug.ScopeType.Closure) {
assertTrue(response.body.scopes[i].object.ref < 0);
} else {
assertTrue(response.body.scopes[i].object.ref >= 0);
}
var found = false;
for (var j = 0; j < response.refs.length && !found; j++) {
found = response.refs[j].handle == response.body.scopes[i].object.ref;
}
assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " not found");
}
}
......@@ -154,31 +128,6 @@ function CheckScopeContent(minimum_content, number, exec_state) {
}
}
assertTrue(scope_size >= minimum_count);
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Send a scope request for information on a single scope and check the
// result.
var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"number":';
request_json += scope.scopeIndex();
request_json += '}}';
var response_json = dcp.processDebugJSONRequest(request_json);
var response = JSON.parse(response_json);
assertEquals(scope.scopeType(), response.body.type);
assertEquals(number, response.body.index);
if (scope.scopeType() == debug.ScopeType.Local ||
scope.scopeType() == debug.ScopeType.Script ||
scope.scopeType() == debug.ScopeType.Closure) {
assertTrue(response.body.object.ref < 0);
} else {
assertTrue(response.body.object.ref >= 0);
}
var found = false;
for (var i = 0; i < response.refs.length && !found; i++) {
found = response.refs[i].handle == response.body.object.ref;
}
assertTrue(found, "Scope object " + response.body.object.ref + " not found");
}
......
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