Skip to content

Commit 8a52285

Browse files
author
Anna Gringauze
committed
Add columns to breakpoints
1 parent 05c0218 commit 8a52285

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

dwds/lib/src/debugging/debugger.dart

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ class Debugger extends Domain {
228228
int line, {
229229
int column,
230230
}) async {
231+
column ??= 0;
231232
checkIsolate('addBreakpoint', isolateId);
232-
final breakpoint = await _breakpoints.add(scriptId, line);
233+
final breakpoint = await _breakpoints.add(scriptId, line, column);
233234
_notifyBreakpoint(breakpoint);
234235
return breakpoint;
235236
}
@@ -249,7 +250,9 @@ class Debugger extends Domain {
249250
for (var breakpoint in previousBreakpoints) {
250251
var scriptRef = await _updatedScriptRefFor(breakpoint);
251252
var updatedLocation = await _locations.locationForDart(
252-
DartUri(scriptRef.uri, _root), _lineNumberFor(breakpoint));
253+
DartUri(scriptRef.uri, _root),
254+
_lineNumberFor(breakpoint),
255+
_columnNumberFor(breakpoint));
253256
var updatedBreakpoint = _breakpoints._dartBreakpoint(
254257
scriptRef, updatedLocation, breakpoint.id);
255258
_breakpoints._note(
@@ -263,7 +266,8 @@ class Debugger extends Domain {
263266
await addBreakpoint(
264267
inspector.isolate.id,
265268
(await _updatedScriptRefFor(breakpoint)).id,
266-
_lineNumberFor(breakpoint));
269+
_lineNumberFor(breakpoint),
270+
column: _columnNumberFor(breakpoint));
267271
}
268272
}
269273

@@ -324,10 +328,11 @@ class Debugger extends Domain {
324328
var frame = e.params['callFrames'][0];
325329
var location = frame['location'];
326330
var scriptId = location['scriptId'] as String;
327-
var lineNumber = location['lineNumber'] as int;
331+
var line = location['lineNumber'] as int;
332+
var column = location['columnNumber'] as int;
328333

329334
var url = _urlForScriptId(scriptId);
330-
return _locations.locationForJs(url, lineNumber + 1);
335+
return _locations.locationForJs(url, line + 1, column + 1);
331336
}
332337

333338
/// The variables visible in a frame in Dart protocol [BoundVariable] form.
@@ -723,14 +728,23 @@ bool isNativeJsObject(InstanceRef instanceRef) {
723728

724729
/// Returns the Dart line number for the provided breakpoint.
725730
int _lineNumberFor(Breakpoint breakpoint) =>
726-
int.parse(breakpoint.id.split('#').last);
731+
int.parse(breakpoint.id.split('#').last.split(':').first);
732+
733+
/// Returns the Dart line number for the provided breakpoint.
734+
int _columnNumberFor(Breakpoint breakpoint) =>
735+
int.parse(breakpoint.id.split('#').last.split(':').last);
727736

728737
/// Returns the breakpoint ID for the provided Dart script ID and Dart line
729738
/// number.
730-
String breakpointIdFor(String scriptId, int line) => 'bp/$scriptId#$line';
739+
String breakpointIdFor(String scriptId, int line, int column) {
740+
var id = 'bp/$scriptId#$line:$column';
741+
print('breakpointIdFor: $scriptId, $line, $column: $id');
742+
return id;
743+
}
731744

732745
/// Keeps track of the Dart and JS breakpoint Ids that correspond.
733746
class _Breakpoints extends Domain {
747+
final _logger = Logger('_Breakpoints');
734748
final _dartIdByJsId = <String, String>{};
735749
final _jsIdByDartId = <String, String>{};
736750

@@ -752,11 +766,12 @@ class _Breakpoints extends Domain {
752766
}) : super(provider);
753767

754768
Future<Breakpoint> _createBreakpoint(
755-
String id, String scriptId, int line) async {
769+
String id, String scriptId, int line, int column) async {
756770
var dartScript = inspector.scriptWithId(scriptId);
757771
var dartUri = DartUri(dartScript.uri, root);
758-
var location = await locations.locationForDart(dartUri, line);
759-
772+
var location = await locations.locationForDart(dartUri, line, column);
773+
_logger.warning(
774+
'_createBreakpoint: uri: $dartUri, line: $line, column :$column, location: $location');
760775
// TODO: Handle cases where a breakpoint can't be set exactly at that line.
761776
if (location == null) {
762777
throw RPCError(
@@ -779,10 +794,10 @@ class _Breakpoints extends Domain {
779794

780795
/// Adds a breakpoint at [scriptId] and [line] or returns an existing one if
781796
/// present.
782-
Future<Breakpoint> add(String scriptId, int line) async {
783-
final id = breakpointIdFor(scriptId, line);
797+
Future<Breakpoint> add(String scriptId, int line, int column) async {
798+
final id = breakpointIdFor(scriptId, line, column);
784799
return _bpByDartId.putIfAbsent(
785-
id, () => _createBreakpoint(id, scriptId, line));
800+
id, () => _createBreakpoint(id, scriptId, line, column));
786801
}
787802

788803
/// Create a Dart breakpoint at [location] in [dartScript] with [id].
@@ -812,6 +827,7 @@ class _Breakpoints extends Domain {
812827
.sendCommand('Debugger.setBreakpointByUrl', params: {
813828
'urlRegex': urlRegex,
814829
'lineNumber': location.jsLocation.line - 1,
830+
'columnNumber': location.jsLocation.column - 1,
815831
});
816832
return response.result['breakpointId'] as String;
817833
});

dwds/lib/src/debugging/location.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Location {
4040
var dartColumn = entry.sourceColumn;
4141
var jsLine = lineEntry.line;
4242
var jsColumn = entry.column;
43+
print('Location: $jsLine:$jsColumn');
4344
// lineEntry data is 0 based according to:
4445
// https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k
4546
return Location._(
@@ -155,17 +156,21 @@ class Locations {
155156
/// Find the [Location] for the given Dart source position.
156157
///
157158
/// The [line] number is 1-based.
158-
Future<Location> locationForDart(DartUri uri, int line) async =>
159+
Future<Location> locationForDart(DartUri uri, int line, int column) async =>
159160
(await locationsForDart(uri.serverPath)).firstWhere(
160-
(location) => location.dartLocation.line == line,
161+
(location) =>
162+
location.dartLocation.line == line &&
163+
location.dartLocation.column >= column,
161164
orElse: () => null);
162165

163166
/// Find the [Location] for the given JS source position.
164167
///
165168
/// The [line] number is 1-based.
166-
Future<Location> locationForJs(String url, int line) async =>
169+
Future<Location> locationForJs(String url, int line, int column) async =>
167170
(await locationsForUrl(url)).firstWhere(
168-
(location) => location.jsLocation.line == line,
171+
(location) =>
172+
location.jsLocation.line == line &&
173+
location.jsLocation.column >= column,
169174
orElse: () => null);
170175

171176
/// Returns the tokenPosTable for the provided Dart script path as defined

dwds/lib/src/services/expression_evaluator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class ExpressionEvaluator {
161161
var functionName = jsFrame.functionName;
162162
var jsLine = jsFrame.location.lineNumber + 1;
163163
var jsScriptId = jsFrame.location.scriptId;
164+
var jsColumn = jsFrame.location.columnNumber + 1;
164165
var jsScope = await _collectLocalJsScope(jsFrame);
165166

166167
// Find corresponding dart location and scope.
@@ -171,7 +172,7 @@ class ExpressionEvaluator {
171172
// cases. Invent location matching strategy for those cases.
172173
// [issue 890](https://github.com/dart-lang/webdev/issues/890)
173174
var url = _urlForScriptId(jsScriptId);
174-
var locationMap = await _locations.locationForJs(url, jsLine);
175+
var locationMap = await _locations.locationForJs(url, jsLine, jsColumn);
175176
if (locationMap == null) {
176177
return _createError(
177178
ErrorKind.internal,

dwds/test/frontend_server_breakpoint_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void main() {
8888

8989
// Remove breakpoint so it doesn't impact other tests.
9090
await service.removeBreakpoint(isolate.id, bp.id);
91-
});
91+
}, solo: true);
9292

9393
test('set breakpoint again', () async {
9494
var line = await context.findBreakpointLine(

0 commit comments

Comments
 (0)