From 1e8bf9db94a1d372547554f49dd0dacb73ae030b Mon Sep 17 00:00:00 2001 From: "peter.rybin@gmail.com" Date: Fri, 14 May 2010 15:24:25 +0000 Subject: [PATCH] Add listbreakpoints command to protocol Review URL: http://codereview.chromium.org/2050007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4656 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/d8.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/debug-debugger.js | 31 ++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/d8.js b/src/d8.js index b9ff09c..455aa6f 100644 --- a/src/d8.js +++ b/src/d8.js @@ -341,6 +341,11 @@ function DebugRequest(cmd_line) { this.request_ = this.breakCommandToJSONRequest_(args); break; + case 'breakpoints': + case 'bb': + this.request_ = this.breakpointsCommandToJSONRequest_(args); + break; + case 'clear': this.request_ = this.clearCommandToJSONRequest_(args); break; @@ -770,6 +775,15 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { }; +DebugRequest.prototype.breakpointsCommandToJSONRequest_ = function(args) { + if (args && args.length > 0) { + throw new Error('Unexpected arguments.'); + } + var request = this.createRequest('listbreakpoints'); + return request.toJSONProtocol(); +}; + + // Create a JSON request for the clear command. DebugRequest.prototype.clearCommandToJSONRequest_ = function(args) { // Build a evaluate request from the text command. @@ -947,6 +961,39 @@ function DebugResponseDetails(response) { result += body.breakpoint; details.text = result; break; + + case 'listbreakpoints': + result = 'breakpoints: (' + body.breakpoints.length + ')'; + for (var i = 0; i < body.breakpoints.length; i++) { + var breakpoint = body.breakpoints[i]; + result += '\n id=' + breakpoint.number; + result += ' type=' + breakpoint.type; + if (breakpoint.script_id) { + result += ' script_id=' + breakpoint.script_id; + } + if (breakpoint.script_name) { + result += ' script_name=' + breakpoint.script_name; + } + result += ' line=' + breakpoint.line; + if (breakpoint.column != null) { + result += ' column=' + breakpoint.column; + } + if (breakpoint.groupId) { + result += ' groupId=' + breakpoint.groupId; + } + if (breakpoint.ignoreCount) { + result += ' ignoreCount=' + breakpoint.ignoreCount; + } + if (breakpoint.active === false) { + result += ' inactive'; + } + if (breakpoint.condition) { + result += ' condition=' + breakpoint.condition; + } + result += ' hit_count=' + breakpoint.hit_count; + } + details.text = result; + break; case 'backtrace': if (body.totalFrames == 0) { @@ -1136,8 +1183,8 @@ function DebugResponseDetails(response) { default: details.text = - 'Response for unknown command \'' + response.command + '\'' + - ' (' + json_response + ')'; + 'Response for unknown command \'' + response.command() + '\'' + + ' (' + response.raw_json() + ')'; } } catch (e) { details.text = 'Error: "' + e + '" formatting response'; @@ -1153,6 +1200,7 @@ function DebugResponseDetails(response) { * @constructor */ function ProtocolPackage(json) { + this.raw_json_ = json; this.packet_ = JSON.parse(json); this.refs_ = []; if (this.packet_.refs) { @@ -1243,6 +1291,11 @@ ProtocolPackage.prototype.lookup = function(handle) { } +ProtocolPackage.prototype.raw_json = function() { + return this.raw_json_; +} + + function ProtocolValue(value, packet) { this.value_ = value; this.packet_ = packet; diff --git a/src/debug-debugger.js b/src/debug-debugger.js index e94cee4..369a02c 100644 --- a/src/debug-debugger.js +++ b/src/debug-debugger.js @@ -1266,6 +1266,8 @@ DebugCommandProcessor.prototype.processDebugJSONRequest = function(json_request) this.clearBreakPointRequest_(request, response); } else if (request.command == 'clearbreakpointgroup') { this.clearBreakPointGroupRequest_(request, response); + } else if (request.command == 'listbreakpoints') { + this.listBreakpointsRequest_(request, response); } else if (request.command == 'backtrace') { this.backtraceRequest_(request, response); } else if (request.command == 'frame') { @@ -1581,6 +1583,35 @@ DebugCommandProcessor.prototype.clearBreakPointRequest_ = function(request, resp response.body = { breakpoint: break_point } } +DebugCommandProcessor.prototype.listBreakpointsRequest_ = function(request, response) { + var array = []; + for (var i = 0; i < script_break_points.length; i++) { + var break_point = script_break_points[i]; + + var description = { + number: break_point.number(), + line: break_point.line(), + column: break_point.column(), + groupId: break_point.groupId(), + hit_count: break_point.hit_count(), + active: break_point.active(), + condition: break_point.condition(), + ignoreCount: break_point.ignoreCount() + } + + if (break_point.type() == Debug.ScriptBreakPointType.ScriptId) { + description.type = 'scriptId'; + description.script_id = break_point.script_id(); + } else { + description.type = 'scriptName'; + description.script_name = break_point.script_name(); + } + array.push(description); + } + + response.body = { breakpoints: array } +} + DebugCommandProcessor.prototype.backtraceRequest_ = function(request, response) { // Get the number of frames. -- 2.7.4