Index: runtime/observatory/lib/src/elements/debugger.dart |
diff --git a/runtime/observatory/lib/src/elements/debugger.dart b/runtime/observatory/lib/src/elements/debugger.dart |
index f652da149d62e88451cb54ac8ad6978582950488..fdac4df9f6c4f5dc4a1a8f3e4a2c9420a3eef43f 100644 |
--- a/runtime/observatory/lib/src/elements/debugger.dart |
+++ b/runtime/observatory/lib/src/elements/debugger.dart |
@@ -637,7 +637,7 @@ class BreakCommand extends DebuggerCommand { |
Future run(List<String> args) async { |
if (args.length > 1) { |
debugger.console.print('not implemented'); |
- return new Future.value(null); |
+ return; |
} |
var arg = (args.length == 0 ? '' : args[0]); |
var loc = await DebuggerLocation.parse(debugger, arg); |
@@ -654,14 +654,15 @@ class BreakCommand extends DebuggerCommand { |
} |
} else { |
assert(loc.script != null); |
- if (loc.col != null) { |
- // TODO(turnidge): Add tokenPos breakpoint support. |
+ var script = loc.script; |
+ await script.load(); |
+ if (loc.line < 1 || loc.line > script.lines.length) { |
debugger.console.print( |
- 'Ignoring column: ' |
- 'adding breakpoint at a specific column not yet implemented'); |
- } |
+ 'line number must be in range [1,${script.lines.length}]'); |
+ return; |
+ } |
try { |
- await debugger.isolate.addBreakpoint(loc.script, loc.line); |
+ await debugger.isolate.addBreakpoint(script, loc.line, loc.col); |
} on ServerRpcException catch(e) { |
if (e.code == ServerRpcException.kCannotAddBreakpoint) { |
debugger.console.print('Unable to set breakpoint at ${loc}'); |
@@ -718,48 +719,50 @@ class BreakCommand extends DebuggerCommand { |
class ClearCommand extends DebuggerCommand { |
ClearCommand(Debugger debugger) : super(debugger, 'clear', []); |
- Future run(List<String> args) { |
+ Future run(List<String> args) async { |
if (args.length > 1) { |
debugger.console.print('not implemented'); |
- return new Future.value(null); |
+ return; |
} |
var arg = (args.length == 0 ? '' : args[0]); |
- return DebuggerLocation.parse(debugger, arg).then((loc) { |
- if (loc.valid) { |
- if (loc.function != null) { |
- debugger.console.print( |
- 'Ignoring breakpoint at $loc: ' |
- 'Function entry breakpoints not yet implemented'); |
- return null; |
- } |
- if (loc.col != null) { |
- // TODO(turnidge): Add tokenPos clear support. |
- debugger.console.print( |
- 'Ignoring column: ' |
- 'clearing breakpoint at a specific column not yet implemented'); |
- } |
+ var loc = await DebuggerLocation.parse(debugger, arg); |
+ if (!loc.valid) { |
+ debugger.console.print(loc.errorMessage); |
+ return; |
+ } |
+ if (loc.function != null) { |
+ debugger.console.print( |
+ 'Ignoring breakpoint at $loc: ' |
+ 'Clearing function breakpoints not yet implemented'); |
+ return; |
+ } |
- for (var bpt in debugger.isolate.breakpoints.values) { |
- var script = bpt.location.script; |
- if (script.id == loc.script.id) { |
- assert(script.loaded); |
- var line = script.tokenToLine(bpt.location.tokenPos); |
- if (line == loc.line) { |
- return debugger.isolate.removeBreakpoint(bpt).then((result) { |
- if (result is DartError) { |
- debugger.console.print( |
- 'Unable to clear breakpoint at ${loc}: ${result.message}'); |
- return; |
- } |
- }); |
- } |
+ var script = loc.script; |
+ if (loc.line < 1 || loc.line > script.lines.length) { |
+ debugger.console.print( |
+ 'line number must be in range [1,${script.lines.length}]'); |
+ return; |
+ } |
+ var lineInfo = script.getLine(loc.line); |
+ var bpts = lineInfo.breakpoints; |
+ var foundBreakpoint = false; |
+ if (bpts != null) { |
+ var bptList = bpts.toList(); |
+ for (var bpt in bptList) { |
+ if (loc.col == null || |
+ loc.col == script.tokenToCol(bpt.location.tokenPos)) { |
+ foundBreakpoint = true; |
+ var result = await debugger.isolate.removeBreakpoint(bpt); |
+ if (result is DartError) { |
+ debugger.console.print( |
+ 'Error clearing breakpoint ${bpt.number}: ${result.message}'); |
} |
} |
- debugger.console.print('No breakpoint found at ${loc}'); |
- } else { |
- debugger.console.print(loc.errorMessage); |
} |
- }); |
+ } |
+ if (!foundBreakpoint) { |
+ debugger.console.print('No breakpoint found at ${loc}'); |
+ } |
} |
Future<List<String>> complete(List<String> args) { |
@@ -846,7 +849,7 @@ class InfoBreakpointsCommand extends DebuggerCommand { |
InfoBreakpointsCommand(Debugger debugger) |
: super(debugger, 'breakpoints', []); |
- Future run(List<String> args) { |
+ Future run(List<String> args) async { |
if (debugger.isolate.breakpoints.isEmpty) { |
debugger.console.print('No breakpoints'); |
} |
@@ -854,19 +857,15 @@ class InfoBreakpointsCommand extends DebuggerCommand { |
bpts.sort((a, b) => a.number - b.number); |
for (var bpt in bpts) { |
var bpId = bpt.number; |
- var script = bpt.location.script; |
- var tokenPos = bpt.location.tokenPos; |
- var line = script.tokenToLine(tokenPos); |
- var col = script.tokenToCol(tokenPos); |
+ var locString = await bpt.location.toUserString(); |
if (!bpt.resolved) { |
debugger.console.print( |
- 'Future breakpoint ${bpId} at ${script.name}:${line}:${col}'); |
+ 'Future breakpoint ${bpId} at ${locString}'); |
} else { |
debugger.console.print( |
- 'Breakpoint ${bpId} at ${script.name}:${line}:${col}'); |
+ 'Breakpoint ${bpId} at ${locString}'); |
} |
} |
- return new Future.value(null); |
} |
String helpShort = 'List all breakpoints'; |
@@ -1388,7 +1387,7 @@ class ObservatoryDebugger extends Debugger { |
} |
} |
- Future _reportBreakpointEvent(ServiceEvent event) { |
+ Future _reportBreakpointEvent(ServiceEvent event) async { |
var bpt = event.breakpoint; |
var verb = null; |
switch (event.kind) { |
@@ -1405,19 +1404,17 @@ class ObservatoryDebugger extends Debugger { |
break; |
} |
var script = bpt.location.script; |
- return script.load().then((_) { |
- var bpId = bpt.number; |
- var tokenPos = bpt.location.tokenPos; |
- var line = script.tokenToLine(tokenPos); |
- var col = script.tokenToCol(tokenPos); |
- if (bpt.resolved) { |
- console.print( |
- 'Breakpoint ${bpId} ${verb} at ${script.name}:${line}:${col}'); |
- } else { |
- console.print( |
- 'Future breakpoint ${bpId} ${verb} at ${script.name}:${line}:${col}'); |
- } |
- }); |
+ await script.load(); |
+ |
+ var bpId = bpt.number; |
+ var locString = await bpt.location.toUserString(); |
+ if (bpt.resolved) { |
+ console.print( |
+ 'Breakpoint ${bpId} ${verb} at ${locString}'); |
+ } else { |
+ console.print( |
+ 'Future breakpoint ${bpId} ${verb} at ${locString}'); |
+ } |
} |
void onEvent(ServiceEvent event) { |