OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Library used by debugger wire protocol tests (standalone VM debugging). | 5 // Library used by debugger wire protocol tests (standalone VM debugging). |
6 | 6 |
7 library DartDebugger; | 7 library DartDebugger; |
8 | 8 |
9 import "dart:async"; | 9 import "dart:async"; |
10 import "dart:convert"; | 10 import "dart:convert"; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (response["id"] != id) { | 177 if (response["id"] != id) { |
178 debugger.error("Error: expected messaged id $id but got ${response["id"]}.
"); | 178 debugger.error("Error: expected messaged id $id but got ${response["id"]}.
"); |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 class FrameMatcher extends Command { | 184 class FrameMatcher extends Command { |
185 int frameIndex; | 185 int frameIndex; |
186 List<String> functionNames; | 186 List<String> functionNames; |
| 187 bool exactMatch; |
187 | 188 |
188 FrameMatcher(this.frameIndex, this.functionNames) { | 189 FrameMatcher(this.frameIndex, this.functionNames, this.exactMatch) { |
189 template = {"id": 0, "command": "getStackTrace", "params": {"isolateId": 0}}
; | 190 template = {"id": 0, "command": "getStackTrace", "params": {"isolateId": 0}}
; |
190 } | 191 } |
191 | 192 |
192 void matchResponse(Debugger debugger) { | 193 void matchResponse(Debugger debugger) { |
193 super.matchResponse(debugger); | 194 super.matchResponse(debugger); |
194 var msg = debugger.currentMessage; | 195 var msg = debugger.currentMessage; |
195 List frames = getJsonValue(msg, "result:callFrames"); | 196 List frames = getJsonValue(msg, "result:callFrames"); |
196 assert(frames != null); | 197 assert(frames != null); |
197 if (debugger.scriptUrl == null) { | 198 if (debugger.scriptUrl == null) { |
198 var name = frames[0]["functionName"]; | 199 var name = frames[0]["functionName"]; |
199 if (name == "main") { | 200 if (name == "main") { |
200 // Extract script url of debugged script. | 201 // Extract script url of debugged script. |
201 debugger.scriptUrl = frames[0]["location"]["url"]; | 202 debugger.scriptUrl = frames[0]["location"]["url"]; |
202 assert(debugger.scriptUrl != null); | 203 assert(debugger.scriptUrl != null); |
203 } | 204 } |
204 } | 205 } |
205 if (frames.length < functionNames.length) { | 206 if (frames.length < functionNames.length) { |
206 debugger.error("Error: stack trace not long enough " | 207 debugger.error("Error: stack trace not long enough " |
207 "to match ${functionNames.length} frames"); | 208 "to match ${functionNames.length} frames"); |
208 return; | 209 return; |
209 } | 210 } |
210 for (int i = 0; i < functionNames.length; i++) { | 211 for (int i = 0; i < functionNames.length; i++) { |
211 var idx = i + frameIndex; | 212 var idx = i + frameIndex; |
212 var name = frames[idx]["functionName"]; | 213 var name = frames[idx]["functionName"]; |
213 assert(name != null); | 214 assert(name != null); |
214 if (name != functionNames[i]) { | 215 bool isMatch = exactMatch ? name == functionNames[i] |
| 216 : name.contains(functionNames[i]); |
| 217 if (!isMatch) { |
215 debugger.error("Error: call frame $idx: " | 218 debugger.error("Error: call frame $idx: " |
216 "expected function name '${functionNames[i]}' but found '$name'"); | 219 "expected function name '${functionNames[i]}' but found '$name'"); |
217 return; | 220 return; |
218 } | 221 } |
219 } | 222 } |
220 } | 223 } |
221 } | 224 } |
222 | 225 |
223 | 226 |
224 MatchFrame(int frameIndex, String functionName) { | 227 MatchFrame(int frameIndex, String functionName, {exactMatch: false}) { |
225 return new FrameMatcher(frameIndex, [ functionName ]); | 228 return new FrameMatcher(frameIndex, [functionName], exactMatch); |
226 } | 229 } |
227 | 230 |
228 MatchFrames(List<String> functionNames) { | 231 MatchFrames(List<String> functionNames, {exactMatch: false}) { |
229 return new FrameMatcher(0, functionNames); | 232 return new FrameMatcher(0, functionNames, exactMatch); |
230 } | 233 } |
231 | 234 |
232 | 235 |
233 class LocalsMatcher extends Command { | 236 class LocalsMatcher extends Command { |
234 Map locals = {}; | 237 Map locals = {}; |
235 | 238 |
236 LocalsMatcher(this.locals) { | 239 LocalsMatcher(this.locals) { |
237 template = {"id": 0, "command": "getStackTrace", "params": {"isolateId": 0}}
; | 240 template = {"id": 0, "command": "getStackTrace", "params": {"isolateId": 0}}
; |
238 } | 241 } |
239 | 242 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 targetOpts.add("--debuggee"); | 614 targetOpts.add("--debuggee"); |
612 print('args: ${targetOpts.join(" ")}'); | 615 print('args: ${targetOpts.join(" ")}'); |
613 | 616 |
614 Process.start(Platform.executable, targetOpts).then((Process process) { | 617 Process.start(Platform.executable, targetOpts).then((Process process) { |
615 print("Debug target process started, pid ${process.pid}."); | 618 print("Debug target process started, pid ${process.pid}."); |
616 process.stdin.close(); | 619 process.stdin.close(); |
617 var debugger = new Debugger(process, new DebugScript(script)); | 620 var debugger = new Debugger(process, new DebugScript(script)); |
618 }); | 621 }); |
619 return true; | 622 return true; |
620 } | 623 } |
OLD | NEW |