Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // If true, prints all messages sent and received by inspector. | 5 // If true, prints all messages sent and received by inspector. |
| 6 const printProtocolMessages = false; | 6 const printProtocolMessages = false; |
| 7 | 7 |
| 8 // The active wrapper instance. | 8 // The active wrapper instance. |
| 9 let activeWrapper = undefined; | 9 let activeWrapper = undefined; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 class DebugWrapper { | 26 class DebugWrapper { |
| 27 constructor() { | 27 constructor() { |
| 28 // Message dictionary storing {id, message} pairs. | 28 // Message dictionary storing {id, message} pairs. |
| 29 this.receivedMessages = {}; | 29 this.receivedMessages = {}; |
| 30 | 30 |
| 31 // Each message dispatched by the Debug wrapper is assigned a unique number | 31 // Each message dispatched by the Debug wrapper is assigned a unique number |
| 32 // using nextMessageId. | 32 // using nextMessageId. |
| 33 this.nextMessageId = 0; | 33 this.nextMessageId = 0; |
| 34 | 34 |
| 35 // The listener method called on certain events. | 35 // The listener method called on certain events. |
| 36 this.listener = () => undefined; | 36 this.listener = undefined; |
| 37 | 37 |
| 38 // Register as the active wrapper. | 38 // Register as the active wrapper. |
| 39 assertTrue(activeWrapper === undefined); | 39 assertTrue(activeWrapper === undefined); |
| 40 activeWrapper = this; | 40 activeWrapper = this; |
| 41 } | 41 } |
| 42 | 42 |
| 43 enable() { | 43 enable() { this.sendMessageForMethodChecked("Debugger.enable"); } |
| 44 const {msgid, msg} = this.createMessage("Debugger.enable"); | 44 disable() { this.sendMessageForMethodChecked("Debugger.disable"); } |
| 45 | |
| 46 setListener(listener) { this.listener = listener; } | |
| 47 | |
| 48 stepOver() { this.sendMessageForMethodChecked("Debugger.stepOver"); } | |
| 49 stepInto() { this.sendMessageForMethodChecked("Debugger.stepInto"); } | |
| 50 stepOut() { this.sendMessageForMethodChecked("Debugger.stepOut"); } | |
| 51 | |
| 52 // Returns the resulting breakpoint id. | |
| 53 setBreakPoint(func, opt_line, opt_column, opt_condition) { | |
| 54 assertTrue(%IsFunction(func)); | |
| 55 assertFalse(%FunctionIsAPIFunction(func)); | |
| 56 | |
| 57 // TODO(jgruber): We handle only script breakpoints for now. | |
| 58 // TODO(jgruber): Handle conditions. | |
| 59 | |
| 60 const script = %FunctionGetScript(func); | |
| 61 assertTrue(!!script.id); | |
|
Yang
2016/10/28 05:51:06
This still relies on the script wrapper object, wh
jgruber
2016/10/28 07:36:27
Done.
| |
| 62 | |
| 63 const offset = %FunctionGetScriptSourcePosition(func); | |
| 64 const loc = %ScriptLocationFromLine(script, opt_line, opt_column, offset); | |
| 65 | |
| 66 const {msgid, msg} = this.createMessage( | |
| 67 "Debugger.setBreakpoint", | |
| 68 { location : { scriptId : script.id.toString() | |
| 69 , lineNumber : loc.line | |
| 70 , columnNumber : loc.column | |
| 71 } | |
| 72 }); | |
| 73 this.sendMessage(msg); | |
| 74 | |
| 75 const reply = this.receivedMessages[msgid]; | |
| 76 const breakid = reply.result.breakpointId; | |
| 77 assertTrue(breakid !== undefined); | |
| 78 | |
| 79 return breakid; | |
| 80 } | |
| 81 | |
| 82 clearBreakPoint(breakid) { | |
| 83 const {msgid, msg} = this.createMessage( | |
| 84 "Debugger.removeBreakpoint", { breakpointId : breakid }); | |
| 45 this.sendMessage(msg); | 85 this.sendMessage(msg); |
| 46 assertTrue(this.receivedMessages[msgid] !== undefined); | 86 assertTrue(this.receivedMessages[msgid] !== undefined); |
| 47 } | 87 } |
| 48 | 88 |
| 49 disable() { | 89 // Returns the serialized result of the given expression. For example: |
| 50 const {msgid, msg} = this.createMessage("Debugger.disable"); | 90 // {"type":"number", "value":33, "description":"33"}. |
| 91 evaluate(frameid, expression) { | |
| 92 const {msgid, msg} = this.createMessage( | |
| 93 "Debugger.evaluateOnCallFrame", | |
| 94 { callFrameId : frameid | |
| 95 , expression : expression | |
| 96 }); | |
| 51 this.sendMessage(msg); | 97 this.sendMessage(msg); |
| 52 assertTrue(this.receivedMessages[msgid] !== undefined); | |
| 53 } | |
| 54 | 98 |
| 55 setListener(listener) { | 99 const reply = this.receivedMessages[msgid]; |
| 56 this.listener = listener; | 100 return reply.result.result; |
| 57 } | 101 } |
| 58 | 102 |
| 59 // --- Internal methods. ----------------------------------------------------- | 103 // --- Internal methods. ----------------------------------------------------- |
| 60 | 104 |
| 61 getNextMessageId() { | 105 getNextMessageId() { |
| 62 return this.nextMessageId++; | 106 return this.nextMessageId++; |
| 63 } | 107 } |
| 64 | 108 |
| 65 createMessage(method, params) { | 109 createMessage(method, params) { |
| 66 const id = this.getNextMessageId(); | 110 const id = this.getNextMessageId(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 81 } | 125 } |
| 82 | 126 |
| 83 this.dispatchMessage(parsedMessage); | 127 this.dispatchMessage(parsedMessage); |
| 84 } | 128 } |
| 85 | 129 |
| 86 sendMessage(message) { | 130 sendMessage(message) { |
| 87 if (printProtocolMessages) print(message); | 131 if (printProtocolMessages) print(message); |
| 88 send(message); | 132 send(message); |
| 89 } | 133 } |
| 90 | 134 |
| 135 sendMessageForMethodChecked(method) { | |
| 136 const {msgid, msg} = this.createMessage(method); | |
| 137 this.sendMessage(msg); | |
| 138 assertTrue(this.receivedMessages[msgid] !== undefined); | |
| 139 } | |
| 140 | |
| 91 // --- Message handlers. ----------------------------------------------------- | 141 // --- Message handlers. ----------------------------------------------------- |
| 92 | 142 |
| 93 dispatchMessage(message) { | 143 dispatchMessage(message) { |
| 94 const method = message.method; | 144 const method = message.method; |
| 95 if (method == "Debugger.scriptParsed") { | 145 if (method == "Debugger.paused") { |
| 146 this.handleDebuggerPaused(message); | |
| 147 } else if (method == "Debugger.scriptParsed") { | |
| 96 this.handleDebuggerScriptParsed(message); | 148 this.handleDebuggerScriptParsed(message); |
| 97 } | 149 } |
| 98 } | 150 } |
| 99 | 151 |
| 152 handleDebuggerPaused(message) { | |
| 153 const params = message.params; | |
| 154 | |
| 155 // TODO(jgruber): Arguments as needed. | |
| 156 let execState = { frames: params.callFrames }; | |
| 157 this.invokeListener(DebugEvent.Break, execState); | |
| 158 } | |
| 159 | |
| 100 handleDebuggerScriptParsed(message) { | 160 handleDebuggerScriptParsed(message) { |
| 101 const params = message.params; | 161 const params = message.params; |
| 102 let eventData = { scriptId : params.scriptId | 162 let eventData = { scriptId : params.scriptId |
| 103 , eventType : DebugEvent.AfterCompile | 163 , eventType : DebugEvent.AfterCompile |
| 104 } | 164 } |
| 105 | 165 |
| 106 // TODO(jgruber): Arguments as needed. Still completely missing exec_state, | 166 // TODO(jgruber): Arguments as needed. Still completely missing exec_state, |
| 107 // and eventData used to contain the script mirror instead of its id. | 167 // and eventData used to contain the script mirror instead of its id. |
| 108 this.listener(DebugEvent.AfterCompile, undefined, eventData, undefined); | 168 this.invokeListener(DebugEvent.AfterCompile, undefined, eventData, |
| 169 undefined); | |
| 170 } | |
| 171 | |
| 172 invokeListener(event, exec_state, event_data, data) { | |
| 173 if (this.listener) { | |
| 174 this.listener(event, exec_state, event_data, data); | |
| 175 } | |
| 109 } | 176 } |
| 110 } | 177 } |
| OLD | NEW |