[dds/dap] Increase number of toStrings() per evaluation from 11 to 100

This was an apparently error when moving to the SDK DAPs. The original DAPs performed 100 toStrings() (and 100 is the batch size for VS Code, so the user wouldn't usually see the limit) but we'd done 10 (actually 11) here.

Fixes https://github.com/Dart-Code/Dart-Code/issues/4995

Change-Id: Ie3ca74c9189a725adb971646db2defaf1ffa9627
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353104
Reviewed-by: Helin Shiah <helinx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Danny Tuppeny 2024-02-20 19:24:12 +00:00 committed by Commit Queue
parent 6ee5474a62
commit 30b9238561
4 changed files with 55 additions and 8 deletions

View file

@ -38,7 +38,7 @@ const dartMimeType = 'text/x-dart';
///
/// Setting this too high can have a performance impact, for example if the
/// client requests 500 items in a variablesRequest for a list.
const maxToStringsPerEvaluation = 10;
const maxToStringsPerEvaluation = 100;
/// An expression that evaluates to the exception for the current thread.
///
@ -1909,7 +1909,7 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
variable.value,
name: variable.name,
allowCallingToString: evaluateToStringInDebugViews &&
index <= maxToStringsPerEvaluation,
index < maxToStringsPerEvaluation,
evaluateName: variable.name,
format: format,
);
@ -1927,8 +1927,8 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
return _converter.convertFieldRefToVariable(
thread,
fieldRef,
allowCallingToString: evaluateToStringInDebugViews &&
index <= maxToStringsPerEvaluation,
allowCallingToString:
evaluateToStringInDebugViews && index < maxToStringsPerEvaluation,
format: format,
);
}

View file

@ -162,7 +162,7 @@ class ProtocolConverter {
name: name,
evaluateName: itemEvaluateName,
allowCallingToString:
allowCallingToString && index <= maxToStringsPerEvaluation,
allowCallingToString && index < maxToStringsPerEvaluation,
format: format,
);
},
@ -178,7 +178,7 @@ class ProtocolConverter {
final key = mapEntry.key;
final value = mapEntry.value;
final callToString =
allowCallingToString && index <= maxToStringsPerEvaluation;
allowCallingToString && index < maxToStringsPerEvaluation;
final keyDisplay = await convertVmResponseToDisplayString(
thread,
@ -250,7 +250,7 @@ class ProtocolConverter {
name: name ?? '<unnamed field>',
evaluateName: fieldEvaluateName,
allowCallingToString:
allowCallingToString && index <= maxToStringsPerEvaluation,
allowCallingToString && index < maxToStringsPerEvaluation,
format: format,
);
},
@ -283,7 +283,7 @@ class ProtocolConverter {
getterName: getterName,
evaluateName: evaluateName,
allowCallingToString: allowCallingToString &&
index <= maxToStringsPerEvaluation,
index < maxToStringsPerEvaluation,
format: format,
);
} catch (e) {

View file

@ -329,6 +329,51 @@ void main(List<String> args) {
);
});
test('only calls toString() for 100 items in a list', () async {
final client = dap.client;
// Generate a file that assigns a list of 150 items
// so we can request a subset and ensure only the first 100 items had
// toString() evaluated.
final testFile = dap.createTestFile('''
class S {
final int i;
S(this.i);
@override
String toString() => 'Item \$i';
}
void main(List<String> args) {
final myList = List.generate(150, S.new);
print('Hello!'); $breakpointMarker
}
''');
final breakpointLine = lineWith(testFile, breakpointMarker);
final stop = await client.hitBreakpoint(
testFile,
breakpointLine,
evaluateToStringInDebugViews: true,
);
await client.expectLocalVariable(
stop.threadId!,
expectedName: 'myList',
expectedDisplayString: 'List (150 items)',
expectedIndexedItems: 150,
// Fetch 105 items starting at 5.
start: 5,
count: 105,
expectedVariables: [
for (int i = 5; i < 110; i++)
i < 105
// For items < 105 (100 from the start), toString() is called
// so we include "Item x"
? '[$i]: S (Item $i), eval: myList[$i]'
// For rest, toString is skipped
: '[$i]: S, eval: myList[$i]',
].join('\n'),
);
});
/// Helper to verify variables types of list.
checkList(
String typeName, {

View file

@ -660,6 +660,7 @@ extension DapTestClientExtension on DapTestClient {
String? cwd,
List<String>? args,
List<String>? toolArgs,
bool? evaluateToStringInDebugViews,
Future<Response> Function()? launch,
}) async {
assert(condition == null || additionalBreakpoints == null,
@ -679,6 +680,7 @@ extension DapTestClientExtension on DapTestClient {
cwd: cwd,
args: args,
toolArgs: toolArgs,
evaluateToStringInDebugViews: evaluateToStringInDebugViews,
),
], eagerError: true);