Skip to content

Commit 9756ab9

Browse files
DanTupCommit Queue
authored andcommitted
[dds/dap] Include paging data for variables returned as top-level results to evaluateRequest
This reuses the existing code for child variables for building responses to `evaluate` so that we compute lengths for paging data. We have to copy them over from the variable to the EvaluateResponse because these are two unrelated types that happen to have the same fields for this data. Fixes Dart-Code/Dart-Code#5532 Change-Id: I7ca4c522cdb27ce8dce3f7c3a78189417eb93bf1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432941 Reviewed-by: Ben Konyi <[email protected]> Reviewed-by: Derek Xu <[email protected]> Commit-Queue: Derek Xu <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 25b9978 commit 9756ab9

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

pkg/dds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 5.0.3
22
- [DAP] Stack frames with dots in paths will now be parsed and have locations attached to `OutputEvents`s.
3+
- [DAP] Responses to `evaluateRequest` that are lists now include `indexedVariables` to allow for client-side paging.
34

45
# 5.0.2
56
- [DAP] Handle possible race condition when interacting with web applications

pkg/dds/lib/src/dap/adapters/dart.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,26 +1148,34 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
11481148
} else if (result is vm.Sentinel) {
11491149
throw DebugAdapterException(result.valueAsString ?? '<collected>');
11501150
} else if (result is vm.InstanceRef && thread != null) {
1151-
final resultString = await _converter.convertVmInstanceRefToDisplayString(
1151+
final variable = await _converter.convertVmResponseToVariable(
11521152
thread,
11531153
result,
1154+
name: null,
1155+
evaluateName: expression,
11541156
allowCallingToString:
11551157
evaluateToStringInDebugViews || shouldExpandTruncatedValues,
1156-
format: format,
11571158
allowTruncatedValue: !shouldExpandTruncatedValues,
1159+
format: format,
11581160
);
11591161

1160-
final variablesReference = _converter.isSimpleKind(result.kind)
1161-
? 0
1162-
: thread.storeData(VariableData(result, format));
1163-
11641162
// Store the expression that gets this object as we may need it to
11651163
// compute evaluateNames for child objects later.
11661164
storeEvaluateName(result, expression);
11671165

11681166
sendResponse(EvaluateResponseBody(
1169-
result: resultString,
1170-
variablesReference: variablesReference,
1167+
// EvaluateResponse is mostly the same as a Variable response but
1168+
// do not share a class, so copy all fields off manually (this allows
1169+
// us to have a single implementation of building these fields for
1170+
// an instance instead of duplicating logic here).
1171+
result: variable.value,
1172+
variablesReference: variable.variablesReference,
1173+
indexedVariables: variable.indexedVariables,
1174+
namedVariables: variable.namedVariables,
1175+
memoryReference: variable.memoryReference,
1176+
presentationHint: variable.presentationHint,
1177+
type: variable.type,
1178+
valueLocationReference: variable.valueLocationReference,
11711179
));
11721180
} else {
11731181
throw DebugAdapterException(

pkg/dds/lib/src/dap/protocol_converter.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ class ProtocolConverter {
446446
ThreadInfo thread,
447447
vm.Response response, {
448448
required bool allowCallingToString,
449+
bool allowTruncatedValue = true,
449450
VariableFormat? format,
450451
}) async {
451452
if (response is vm.InstanceRef) {
@@ -454,6 +455,7 @@ class ProtocolConverter {
454455
response,
455456
allowCallingToString: allowCallingToString,
456457
format: format,
458+
allowTruncatedValue: allowTruncatedValue,
457459
);
458460
} else if (response is vm.ErrorRef) {
459461
final errorMessage = response.message;
@@ -505,6 +507,7 @@ class ProtocolConverter {
505507
required String? name,
506508
required String? evaluateName,
507509
required bool allowCallingToString,
510+
bool allowTruncatedValue = true,
508511
VariableFormat? format,
509512
}) async {
510513
if (response is vm.InstanceRef) {
@@ -521,6 +524,7 @@ class ProtocolConverter {
521524
thread,
522525
response,
523526
allowCallingToString: allowCallingToString,
527+
allowTruncatedValue: allowTruncatedValue,
524528
format: format,
525529
),
526530
indexedVariables:

pkg/dds/test/dap/integration/debug_eval_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,43 @@ void foo() {
694694
);
695695
});
696696
});
697+
698+
group('provides paging data for', () {
699+
// Additional paging tests are in debug_variables_test.dart
700+
test('Lists', () async {
701+
final client = dap.client;
702+
final testFile = dap.createTestFile('''
703+
void main(List<String> args) {
704+
var myList = List.generate(10000, (i) => i);
705+
print('Hello!'); $breakpointMarker
706+
}''');
707+
final breakpointLine = lineWith(testFile, breakpointMarker);
708+
709+
final stop = await client.hitBreakpoint(testFile, breakpointLine);
710+
final topFrameId = await client.getTopFrameId(stop.threadId!);
711+
final evalResult = await client.expectEvalResult(
712+
topFrameId, 'myList', 'List (10000 items)');
713+
expect(evalResult.indexedVariables, 10000);
714+
});
715+
716+
test('Uint8List', () async {
717+
final client = dap.client;
718+
final testFile = dap.createTestFile('''
719+
import 'dart:typed_data';
720+
721+
void main(List<String> args) {
722+
var myList = Uint8List(10000);
723+
print('Hello!'); $breakpointMarker
724+
}''');
725+
final breakpointLine = lineWith(testFile, breakpointMarker);
726+
727+
final stop = await client.hitBreakpoint(testFile, breakpointLine);
728+
final topFrameId = await client.getTopFrameId(stop.threadId!);
729+
final evalResult = await client.expectEvalResult(
730+
topFrameId, 'myList', 'Uint8List (10000 items)');
731+
expect(evalResult.indexedVariables, 10000);
732+
});
733+
});
697734
// These tests can be slow due to starting up the external server process.
698735
}, timeout: Timeout.none);
699736
}

0 commit comments

Comments
 (0)