Chromium Code Reviews| 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 return new FrameMatcher(frameIndex, [functionName], exactMatch); | 292 return new FrameMatcher(frameIndex, [functionName], exactMatch); |
| 293 } | 293 } |
| 294 | 294 |
| 295 MatchFrames(List<String> functionNames, {exactMatch: false}) { | 295 MatchFrames(List<String> functionNames, {exactMatch: false}) { |
| 296 return new FrameMatcher(0, functionNames, exactMatch); | 296 return new FrameMatcher(0, functionNames, exactMatch); |
| 297 } | 297 } |
| 298 | 298 |
| 299 | 299 |
| 300 class LocalsMatcher extends Command { | 300 class LocalsMatcher extends Command { |
| 301 Map locals = {}; | 301 Map locals = {}; |
| 302 int frame_index; | |
| 302 | 303 |
| 303 LocalsMatcher(this.locals) { | 304 LocalsMatcher(this.locals, this.frame_index) { |
| 304 template = {"id": 0, "command": "getStackTrace", "params": {"isolateId": 0}} ; | 305 template = {"id": 0, "command": "getStackTrace", "params": {"isolateId": 0}} ; |
| 305 } | 306 } |
| 306 | 307 |
| 307 void matchResponse(Debugger debugger) { | 308 void matchResponse(Debugger debugger) { |
| 308 super.matchResponse(debugger); | 309 super.matchResponse(debugger); |
| 309 | 310 |
| 310 List frames = getJsonValue(debugger.currentMessage, "result:callFrames"); | 311 List frames = getJsonValue(debugger.currentMessage, "result:callFrames"); |
| 311 assert(frames != null); | 312 assert(frames != null); |
| 312 | 313 |
| 313 String functionName = frames[0]['functionName']; | 314 String functionName = frames[frame_index]['functionName']; |
| 314 List localsList = frames[0]['locals']; | 315 List localsList = frames[frame_index]['locals']; |
| 315 Map reportedLocals = {}; | 316 Map reportedLocals = {}; |
| 316 localsList.forEach((local) => reportedLocals[local['name']] = local['value'] ); | 317 localsList.forEach((local) => reportedLocals[local['name']] = local['value'] ); |
| 317 for (String key in locals.keys) { | 318 for (String key in locals.keys) { |
| 318 if (reportedLocals[key] == null) { | 319 if (reportedLocals[key] == null) { |
| 319 debugger.error("Error in $functionName(): no value reported for local " | 320 debugger.error("Error in $functionName(): no value reported for local " |
| 320 "variable $key"); | 321 "variable $key"); |
| 321 return; | 322 return; |
| 322 } | 323 } |
| 323 String expected = locals[key]; | 324 String expected = locals[key]; |
| 324 String actual = reportedLocals[key]['text']; | 325 String actual = reportedLocals[key]['text']; |
| 325 if (expected != actual) { | 326 if (expected != actual) { |
| 326 debugger.error("Error in $functionName(): got '$actual' for local " | 327 debugger.error("Error in $functionName(): got '$actual' for local " |
| 327 "variable $key, but expected '$expected'"); | 328 "variable $key, but expected '$expected'"); |
| 328 return; | 329 return; |
| 329 } | 330 } |
| 330 } | 331 } |
| 331 print("Matched locals ${locals.keys}"); | 332 print("Matched locals ${locals.keys}"); |
| 332 } | 333 } |
| 333 } | 334 } |
| 334 | 335 |
| 335 | 336 |
| 336 MatchLocals(Map localValues) { | 337 MatchLocals(Map localValues, [int frame_index = 0]) { |
|
hausner
2015/02/18 18:32:29
It doesn't look like you are using MatchLocals wit
Florian Schneider
2015/02/18 18:45:23
Yes, I only used to while testing. I'll remove it
| |
| 337 return new LocalsMatcher(localValues); | 338 return new LocalsMatcher(localValues, frame_index); |
| 339 } | |
| 340 | |
| 341 | |
| 342 class InvertedLocalsMatcher extends Command { | |
|
hausner
2015/02/18 18:32:28
Would you mind adding a one-liner comment what thi
Florian Schneider
2015/02/18 18:45:23
Added comment and renamed to AssertLocalsNotVisibl
| |
| 343 List<String> locals; | |
| 344 int frame_index; | |
| 345 | |
| 346 InvertedLocalsMatcher(this.locals, this.frame_index) { | |
| 347 template = {"id": 0, "command": "getStackTrace", "params": {"isolateId": 0}} ; | |
| 348 } | |
| 349 | |
| 350 void matchResponse(Debugger debugger) { | |
| 351 super.matchResponse(debugger); | |
| 352 | |
| 353 List frames = getJsonValue(debugger.currentMessage, "result:callFrames"); | |
| 354 assert(frames != null); | |
| 355 | |
| 356 String functionName = frames[frame_index]['functionName']; | |
| 357 List localsList = frames[frame_index]['locals']; | |
| 358 Map reportedLocals = {}; | |
| 359 localsList.forEach((local) => reportedLocals[local['name']] = local['value'] ); | |
| 360 for (String key in locals) { | |
| 361 if (reportedLocals[key] != null) { | |
| 362 debugger.error("Error in $functionName(): local variable $key not " | |
| 363 "expected in scope (reported value " | |
| 364 "${reportedLocals[key]['text']})"); | |
| 365 return; | |
| 366 } | |
| 367 } | |
| 368 print("Matched locals $locals"); | |
| 369 } | |
| 370 } | |
| 371 | |
| 372 | |
| 373 AssertLocalsNotVisible(List<String> locals, [int frame_index = 0]) { | |
| 374 return new InvertedLocalsMatcher(locals, frame_index); | |
| 338 } | 375 } |
| 339 | 376 |
| 340 | 377 |
| 341 class EventMatcher { | 378 class EventMatcher { |
| 342 String eventName; | 379 String eventName; |
| 343 Map params; | 380 Map params; |
| 344 | 381 |
| 345 EventMatcher(this.eventName, this.params); | 382 EventMatcher(this.eventName, this.params); |
| 346 | 383 |
| 347 void matchEvent(Debugger debugger) { | 384 void matchEvent(Debugger debugger) { |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 targetOpts.add("--debuggee"); | 740 targetOpts.add("--debuggee"); |
| 704 print('args: ${targetOpts.join(" ")}'); | 741 print('args: ${targetOpts.join(" ")}'); |
| 705 | 742 |
| 706 Process.start(Platform.executable, targetOpts).then((Process process) { | 743 Process.start(Platform.executable, targetOpts).then((Process process) { |
| 707 print("Debug target process started, pid ${process.pid}."); | 744 print("Debug target process started, pid ${process.pid}."); |
| 708 process.stdin.close(); | 745 process.stdin.close(); |
| 709 var debugger = new Debugger(process, new DebugScript(script)); | 746 var debugger = new Debugger(process, new DebugScript(script)); |
| 710 }); | 747 }); |
| 711 return true; | 748 return true; |
| 712 } | 749 } |
| OLD | NEW |