Unverified Commit 76758ef9 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

[dap] Don't use --start-paused when running in Profile/Release mode (#98926)

parent 37a1aaf8
......@@ -85,30 +85,55 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
/// Whether or not the user requested debugging be enabled.
///
/// debug/noDebug here refers to the DAP "debug" mode and not the Flutter
/// debug mode (vs Profile/Release). It is provided by the client editor based
/// on whether a user chooses to "Run" or "Debug" their app.
/// For debugging to be enabled, the user must have chosen "Debug" (and not
/// "Run") in the editor (which maps to the DAP `noDebug` field) _and_ must
/// not have requested to run in Profile or Release mode. Profile/Release
/// modes will always disable debugging.
///
/// This is always enabled for attach requests, but can be disabled for launch
/// requests via DAP's `noDebug` flag. If `noDebug` is not provided, will
/// default to debugging.
/// This is always `true` for attach requests.
///
/// When not debugging, we will not connect to the VM Service so some
/// functionality (breakpoints, evaluation, etc.) will not be available.
/// Functionality provided via the daemon (hot reload/restart) will still be
/// available.
bool get debug {
bool get enableDebugger {
final DartCommonLaunchAttachRequestArguments args = this.args;
if (args is FlutterLaunchRequestArguments) {
// Invert DAP's noDebug flag, treating it as false (so _do_ debug) if not
// provided.
return !(args.noDebug ?? false);
return !(args.noDebug ?? false) && !profileMode && !releaseMode;
}
// Otherwise (attach), always debug.
return true;
}
/// Whether the launch configuration arguments specify `--profile`.
///
/// Always `false` for attach requests.
bool get profileMode {
final DartCommonLaunchAttachRequestArguments args = this.args;
if (args is FlutterLaunchRequestArguments) {
return args.toolArgs?.contains('--profile') ?? false;
}
// Otherwise (attach), always false.
return false;
}
/// Whether the launch configuration arguments specify `--release`.
///
/// Always `false` for attach requests.
bool get releaseMode {
final DartCommonLaunchAttachRequestArguments args = this.args;
if (args is FlutterLaunchRequestArguments) {
return args.toolArgs?.contains('--release') ?? false;
}
// Otherwise (attach), always false.
return false;
}
/// Called by [attachRequest] to request that we actually connect to the app to be debugged.
@override
Future<void> attachImpl() async {
......@@ -214,7 +239,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
final List<String> toolArgs = <String>[
'run',
'--machine',
if (debug) '--start-paused',
if (enableDebugger) '--start-paused',
];
await _startProcess(
......@@ -258,7 +283,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
// Delay responding until the app is launched and (optionally) the debugger
// is connected.
await appStartedCompleter.future;
if (debug) {
if (enableDebugger) {
await debuggerInitialized;
}
}
......@@ -363,7 +388,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
void _handleDebugPort(Map<String, Object?> params) {
// When running in noDebug mode, Flutter may still provide us a VM Service
// URI, but we will not connect it because we don't want to do any debugging.
if (!debug) {
if (!enableDebugger) {
return;
}
......@@ -494,7 +519,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
await sendFlutterRequest('app.restart', <String, Object?>{
'appId': _appId,
'fullRestart': fullRestart,
'pause': debug,
'pause': enableDebugger,
'reason': reason,
'debounce': true,
});
......
......@@ -13,8 +13,83 @@ import 'mocks.dart';
void main() {
group('flutter adapter', () {
final String expectedFlutterExecutable = globals.platform.isWindows
? r'C:\fake\flutter\bin\flutter.bat'
: '/fake/flutter/bin/flutter';
setUpAll(() {
Cache.flutterRoot = '/fake/flutter';
Cache.flutterRoot = globals.platform.isWindows
? r'C:\fake\flutter'
: '/fake/flutter';
});
group('--start-paused', () {
test('is passed for debug mode', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, contains('--start-paused'));
});
test('is not passed for noDebug mode', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
noDebug: true,
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, isNot(contains('--start-paused')));
});
test('is not passed if toolArgs contains --profile', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
toolArgs: <String>['--profile'],
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, isNot(contains('--start-paused')));
});
test('is not passed if toolArgs contains --release', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
toolArgs: <String>['--release'],
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, isNot(contains('--start-paused')));
});
});
test('includes toolArgs', () async {
......@@ -32,7 +107,7 @@ void main() {
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.executable, equals('/fake/flutter/bin/flutter'));
expect(adapter.executable, equals(expectedFlutterExecutable));
expect(adapter.processArgs, contains('tool_arg'));
});
......
......@@ -13,8 +13,14 @@ import 'mocks.dart';
void main() {
group('flutter test adapter', () {
final String expectedFlutterExecutable = globals.platform.isWindows
? r'C:\fake\flutter\bin\flutter.bat'
: '/fake/flutter/bin/flutter';
setUpAll(() {
Cache.flutterRoot = '/fake/flutter';
Cache.flutterRoot = globals.platform.isWindows
? r'C:\fake\flutter'
: '/fake/flutter';
});
test('includes toolArgs', () async {
......@@ -35,7 +41,7 @@ void main() {
await adapter.launchRequest(request, args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.executable, equals('/fake/flutter/bin/flutter'));
expect(adapter.executable, equals(expectedFlutterExecutable));
expect(adapter.processArgs, contains('tool_arg'));
});
......
......@@ -52,6 +52,14 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
// launchRequest will complete.
appStartedCompleter.complete();
}
@override
Future<void> get debuggerInitialized {
// If we were mocking debug mode, then simulate the debugger initializing.
return enableDebugger
? Future<void>.value()
: throw StateError('Invalid attempt to wait for debuggerInitialized when not debugging');
}
}
/// A [FlutterTestDebugAdapter] that captures what process/args will be launched.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment