Skip to content

Commit 97ab888

Browse files
DanTupCommit Queue
authored andcommitted
Remove spawning of DDS from DAP and let the spawned dart run/dart test do it
Fixes #56733 Change-Id: I23acd9ba4cd48dd7fe5e23fc388d143db8779754 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386500 Reviewed-by: Ben Konyi <[email protected]> Reviewed-by: Elliott Brooks <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 46475d1 commit 97ab888

File tree

13 files changed

+46
-151
lines changed

13 files changed

+46
-151
lines changed

pkg/dartdev/lib/src/commands/debug_adapter.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,22 @@ class DebugAdapterCommand extends DartdevCommand {
3434
help: 'Whether to bind DAP/VM Service/DDS to IPv6 addresses.',
3535
)
3636
..addFlag(
37+
// Deprecated - DAP never spawns DDS now, but this flag is left
38+
// temporarily to not crash clients passing it.
39+
// TODO(dantup): Remove this after verifying nobody uses it.
3740
argDds,
3841
defaultsTo: true,
3942
help: 'Whether to enable DDS for debug sessions.',
43+
hide: true,
4044
)
4145
..addFlag(
46+
// Deprecated - DAP never spawns DDS now, but this flag is left
47+
// temporarily to not crash clients passing it.
48+
// TODO(dantup): Remove this after verifying nobody uses it.
4249
argAuthCodes,
4350
defaultsTo: true,
4451
help: 'Whether to enable authentication codes for VM Services.',
52+
hide: true,
4553
)
4654
..addFlag(
4755
argTest,
@@ -60,8 +68,6 @@ class DebugAdapterCommand extends DartdevCommand {
6068
stdin,
6169
stdout.nonBlocking,
6270
ipv6: ipv6,
63-
enableDds: args.flag(argDds),
64-
enableAuthCodes: args.flag(argAuthCodes),
6571
test: args.flag(argTest),
6672
// Protocol errors should be written to stderr to help debug (or in the
6773
// case of a user running this command to explain it's for tools).

pkg/dds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# 5.0.0-wip
2+
- [DAP] The debug adapter no longer spawns its own in-process copy of DDS, instead relying on one started by the Dart VM (or `Flutter`). This means the `enableDds` and `enableAuthCodes` arguments to the `DartDebugAdapter` base class have been deprecated and have any effect. Suppressing DDS (or auth codes) should be done in launch configuration (for example using `vmAdditionalArgs` or `toolArgs` depending on the target tool).
23
- Updated the `devtools_shared` dependency to version `^11.0.0`.
34
- Made `runDartDevelopmentServiceFromCLI` pass the specified bind address
45
directly into `startDartDevelopmentService` without resolving the address.

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

Lines changed: 5 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import 'package:path/path.dart' as path;
1515
import 'package:vm_service/vm_service.dart' as vm;
1616

1717
import '../../../dds.dart';
18-
import '../../../dds_launcher.dart';
1918
import '../../rpc_error_codes.dart';
2019
import '../base_debug_adapter.dart';
2120
import '../isolate_manager.dart';
@@ -354,12 +353,6 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
354353
/// value should contain trailing slashes.
355354
final orgDartlangSdkMappings = <String, Uri>{};
356355

357-
/// The DDS instance that was started and that [vmService] is connected to.
358-
///
359-
/// `null` if the session is running in noDebug mode of the connection has not
360-
/// yet been made or has been shut down.
361-
DartDevelopmentServiceLauncher? _dds;
362-
363356
/// The [DartInitializeRequestArguments] provided by the client in the
364357
/// `initialize` request.
365358
///
@@ -369,12 +362,6 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
369362
/// Whether to use IPv6 for DAP/Debugger services.
370363
final bool ipv6;
371364

372-
/// Whether to enable DDS for launched applications.
373-
final bool enableDds;
374-
375-
/// Whether to enable authentication codes for the VM Service/DDS.
376-
final bool enableAuthCodes;
377-
378365
/// A logger for printing diagnostic information.
379366
final Logger? logger;
380367

@@ -491,8 +478,10 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
491478
DartDebugAdapter(
492479
ByteStreamServerChannel channel, {
493480
this.ipv6 = false,
494-
this.enableDds = true,
495-
this.enableAuthCodes = true,
481+
@Deprecated('DAP never spawns DDS now, this `enableDds` does nothing')
482+
bool enableDds = true,
483+
@Deprecated('DAP never spawns DDS now, this `enableAuthCodes` does nothing')
484+
bool enableAuthCodes = true,
496485
this.logger,
497486
Function? onError,
498487
}) : super(channel, onError: onError) {
@@ -649,59 +638,12 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
649638
}
650639
}
651640

652-
/// Attempts to start a DDS instance to connect to the VM Service at [uri].
653-
///
654-
/// Returns the URI to connect the debugger to (whether it's a newly spawned
655-
/// DDS or there was an existing one).
656-
///
657-
/// If we failed to start DDS for a reason other than one already existed for
658-
/// that VM Service we will return `null` and initiate a shutdown with the
659-
/// exception printed to the user.
660-
///
661-
/// If a new DDS instance was started, it is assigned to [_dds].
662-
Future<Uri?> _startOrReuseDds(Uri uri) async {
663-
try {
664-
final dds = await startDds(uri);
665-
_dds = dds;
666-
return dds.wsUri;
667-
} catch (error, stack) {
668-
if (error is DartDevelopmentServiceException &&
669-
error.errorCode ==
670-
DartDevelopmentServiceException.existingDdsInstanceError) {
671-
// If there's an existing DDS instance, we will just continue
672-
// but need to map the URI to the ws: version.
673-
return vmServiceUriToWebSocket(uri);
674-
} else {
675-
// Otherwise, we failed to start DDS for an unknown reason and
676-
// consider this a fatal error. Handle terminating here (so we can
677-
// print this error/stack)...
678-
_handleDebuggerInitializationError(
679-
'Failed to start DDS for $uri', error, stack);
680-
// ... and return no URI as a signal to the caller.
681-
return null;
682-
}
683-
}
684-
}
685-
686641
/// Connects to the VM Service at [uri] and initializes debugging.
687642
///
688643
/// This is the implementation for [connectDebugger] which is executed in a
689644
/// try/catch.
690645
Future<void> _connectDebuggerImpl(Uri uri) async {
691-
if (enableDds) {
692-
// Start up a DDS instance for this VM.
693-
logger?.call('Starting a DDS instance for $uri');
694-
final targetUri = await _startOrReuseDds(uri);
695-
if (targetUri == null) {
696-
// If we got no URI, this is a fatal error and we can skip everything
697-
// else. The detailed error would have been printed from
698-
// [_startOrReuseDds].
699-
return;
700-
}
701-
uri = targetUri;
702-
} else {
703-
uri = vmServiceUriToWebSocket(uri);
704-
}
646+
uri = vmServiceUriToWebSocket(uri);
705647

706648
logger?.call('Connecting to debugger at $uri');
707649
sendConsoleOutput('Connecting to VM Service at $uri');
@@ -771,31 +713,6 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
771713
_debuggerInitializedCompleter.complete();
772714
}
773715

774-
/// Handlers an error during debugger initialization (such as exceptions
775-
/// trying to call `getSupportedProtocols` or `getVM`) by sending it to the
776-
/// client and shutting down.
777-
///
778-
/// Without this, the exceptions may go unhandled and just terminate the debug
779-
/// adapter, which may not be visible to the user. For example VS Code does
780-
/// not expose stderr of a debug adapter process. With this change, the
781-
/// exception will show up in the Debug Console before the debug session
782-
/// terminates.
783-
void _handleDebuggerInitializationError(
784-
String reason, Object? error, StackTrace stack) {
785-
final message = '$reason\n$error\n$stack';
786-
logger?.call(message);
787-
isTerminating = true;
788-
sendConsoleOutput(message);
789-
shutdown();
790-
}
791-
792-
Future<DartDevelopmentServiceLauncher> startDds(Uri uri) {
793-
return DartDevelopmentServiceLauncher.start(
794-
remoteVmServiceUri: vmServiceUriToHttp(uri),
795-
enableAuthCodes: enableAuthCodes,
796-
);
797-
}
798-
799716
// This is intended for subclasses to override to provide a URI converter to
800717
// resolve package URIs to local paths.
801718
UriConverter? uriConverter() {
@@ -1070,7 +987,6 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
1070987
isTerminating = true;
1071988

1072989
await disconnectImpl();
1073-
await shutdownDebugee();
1074990
sendResponse();
1075991

1076992
await shutdown();
@@ -1688,25 +1604,11 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
16881604
sendResponse(SetExceptionBreakpointsResponseBody());
16891605
}
16901606

1691-
/// Shuts down/detaches from the debugee and cleans up.
1692-
///
1693-
/// This is called by [disconnectRequest] and [terminateRequest] but may also
1694-
/// be called if the client just disconnects from the server without calling
1695-
/// either.
1696-
///
1697-
/// This method must tolerate being called multiple times.
1698-
@nonVirtual
1699-
Future<void> shutdownDebugee() async {
1700-
await _dds?.shutdown();
1701-
_dds = null;
1702-
}
1703-
17041607
/// Shuts down the debug adapter, including terminating/detaching from the
17051608
/// debugee if required.
17061609
@override
17071610
@nonVirtual
17081611
Future<void> shutdown() async {
1709-
await shutdownDebugee();
17101612
await _waitForPendingOutputEvents();
17111613
handleSessionTerminate();
17121614

@@ -2008,7 +1910,6 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
20081910
isTerminating = true;
20091911

20101912
await terminateImpl();
2011-
await shutdownDebugee();
20121913
sendResponse();
20131914

20141915
await shutdown();

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class DartCliDebugAdapter extends DartDebugAdapter<DartLaunchRequestArguments,
3030
DartCliDebugAdapter(
3131
super.channel, {
3232
super.ipv6,
33-
super.enableDds,
34-
super.enableAuthCodes,
3533
super.logger,
3634
super.onError,
3735
});
@@ -106,12 +104,10 @@ class DartCliDebugAdapter extends DartDebugAdapter<DartLaunchRequestArguments,
106104

107105
final vmArgs = <String>[
108106
...?args.vmAdditionalArgs,
107+
'--no-serve-devtools',
109108
if (debug) ...[
110109
'--enable-vm-service=${args.vmServicePort ?? 0}${ipv6 ? '/::1' : ''}',
111-
if (!enableAuthCodes) '--disable-service-auth-codes'
112110
],
113-
'--disable-dart-dev',
114-
'--no-dds',
115111
if (debug && vmServiceInfoFile != null) ...[
116112
'-DSILENT_VM_SERVICE=true',
117113
'--write-service-info=${Uri.file(vmServiceInfoFile.path)}'

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class DartTestDebugAdapter extends DartDebugAdapter<DartLaunchRequestArguments,
2929
DartTestDebugAdapter(
3030
super.channel, {
3131
super.ipv6,
32-
super.enableDds,
33-
super.enableAuthCodes,
3432
super.logger,
3533
super.onError,
3634
});
@@ -83,7 +81,6 @@ class DartTestDebugAdapter extends DartDebugAdapter<DartLaunchRequestArguments,
8381
...?args.vmAdditionalArgs,
8482
if (debug) ...[
8583
'--enable-vm-service=${args.vmServicePort ?? 0}${ipv6 ? '/::1' : ''}',
86-
if (!enableAuthCodes) '--disable-service-auth-codes'
8784
],
8885
if (debug && vmServiceInfoFile != null) ...[
8986
'-DSILENT_VM_SERVICE=true',
@@ -113,7 +110,6 @@ class DartTestDebugAdapter extends DartDebugAdapter<DartLaunchRequestArguments,
113110
// We should also ensure DDS is disabled (this may need a new flag since
114111
// we can't disable-dart-dev to get "dart test") and devtools is not
115112
// served.
116-
// '--disable-dart-dev',
117113
'run',
118114
'--no-serve-devtools',
119115
'test:test',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class DdsHostedAdapter extends DartDebugAdapter<DartLaunchRequestArguments,
3737
(message) {},
3838
),
3939
ipv6: true,
40-
enableDds: false,
4140
);
4241

4342
/// Whether the VM Service closing should be used as a signal to terminate the

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@ class DapServer {
2020
final ByteStreamServerChannel channel;
2121
late final DartDebugAdapter adapter;
2222
final bool ipv6;
23-
final bool enableDds;
24-
final bool enableAuthCodes;
2523
final bool test;
2624
final Logger? logger;
2725

2826
DapServer(
2927
Stream<List<int>> input,
3028
StreamSink<List<int>> output, {
3129
this.ipv6 = false,
32-
this.enableDds = true,
33-
this.enableAuthCodes = true,
3430
this.test = false,
3531
this.logger,
3632
Function? onError,
@@ -39,16 +35,12 @@ class DapServer {
3935
? DartTestDebugAdapter(
4036
channel,
4137
ipv6: ipv6,
42-
enableDds: enableDds,
43-
enableAuthCodes: enableAuthCodes,
4438
logger: logger,
4539
onError: onError,
4640
)
4741
: DartCliDebugAdapter(
4842
channel,
4943
ipv6: ipv6,
50-
enableDds: enableDds,
51-
enableAuthCodes: enableAuthCodes,
5244
logger: logger,
5345
onError: onError,
5446
);

pkg/dds/test/dap/dart_cli_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ main() {
8787

8888
expect(adapter.executable, equals('/custom/dart'));
8989
// a standard built-in arg should be present.
90-
expect(adapter.processArgs, contains('--disable-dart-dev'));
90+
expect(adapter.processArgs, contains('--no-serve-devtools'));
9191
});
9292

9393
test('with all args replaced', () async {
@@ -109,7 +109,9 @@ main() {
109109
expect(adapter.executable, equals('/custom/dart'));
110110
// normal built-in args are replaced by customToolReplacesArgs, but
111111
// user-provided toolArgs are not.
112-
expect(adapter.processArgs, isNot(contains('--disable-dart-dev')));
112+
// The argument here should match the one verified in the test above to
113+
// ensure it's real.
114+
expect(adapter.processArgs, isNot(contains('--no-serve-devtools')));
113115
expect(adapter.processArgs, contains('tool_args'));
114116
});
115117
});

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ main() {
128128

129129
expect(
130130
outputEvents.map((e) => e.output).join(),
131-
contains('Invalid --vm-service-uri argument: http://bogus.local'),
131+
allOf(
132+
contains(
133+
'Failed to connect/initialize debugger for ws://bogus.local/',
134+
),
135+
contains('Failed host lookup'),
136+
),
132137
);
133138
});
134139

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -851,34 +851,34 @@ main() {
851851
}, timeout: Timeout.none);
852852

853853
group('debug mode', () {
854-
test(
855-
'can run without DDS',
856-
() async {
857-
final dap = await DapTestSession.setUp(additionalArgs: ['--no-dds']);
858-
addTearDown(dap.tearDown);
854+
test('can be run without DDS using vmAdditionalArgs', () async {
855+
final dap = await DapTestSession.setUp();
856+
addTearDown(dap.tearDown);
859857

860-
final client = dap.client;
861-
final testFile = dap.createTestFile(simpleBreakpointProgram);
862-
final breakpointLine = lineWith(testFile, breakpointMarker);
858+
final client = dap.client;
859+
final testFile = dap.createTestFile(simpleBreakpointProgram);
860+
final breakpointLine = lineWith(testFile, breakpointMarker);
863861

864-
await client.hitBreakpoint(testFile, breakpointLine);
862+
await client.hitBreakpoint(testFile, breakpointLine,
863+
vmAdditionalArgs: ['--no-dds']);
865864

866-
expect(await client.ddsAvailable, isFalse);
867-
},
868-
);
865+
expect(await client.ddsAvailable, isFalse);
866+
});
869867

870-
test('can run without auth codes', () async {
871-
final dap =
872-
await DapTestSession.setUp(additionalArgs: ['--no-auth-codes']);
868+
test('can run without auth codes using vmAdditionalArgs', () async {
869+
final dap = await DapTestSession.setUp();
873870
addTearDown(dap.tearDown);
874871

875872
final testFile = dap.createTestFile(emptyProgram);
876-
final outputEvents = await dap.client.collectOutput(file: testFile);
873+
final outputEvents = await dap.client.collectOutput(
874+
launch: () => dap.client.launch(testFile.path,
875+
vmAdditionalArgs: ['--disable-service-auth-codes']),
876+
);
877877
final vmServiceUri = _extractVmServiceUri(outputEvents.first);
878878
expect(vmServiceUri.path, isNot(matches(vmServiceAuthCodePathPattern)));
879879
});
880880

881-
test('can run with ipv6', () async {
881+
test('can run with ipv6 with a DAP flag', () async {
882882
final dap = await DapTestSession.setUp(additionalArgs: ['--ipv6']);
883883
addTearDown(dap.tearDown);
884884

0 commit comments

Comments
 (0)