Skip to content

Commit 99a2a60

Browse files
committed
Only connect the VM in noDebug mode for Flutter run
Fixes #1673.
1 parent 80e4edd commit 99a2a60

5 files changed

Lines changed: 47 additions & 12 deletions

File tree

‎src/debug/dart_debug_impl.ts‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ export class DartDebugSession extends DebugSession {
3333
// We normally track the pid from Observatory to terminate the VM afterwards, but for Flutter Run it's
3434
// a remote PID and therefore doesn't make sense to try and terminate.
3535
protected allowTerminatingObservatoryVmPid = true;
36+
// Normally we don't connect to the VM when running no noDebug mode, but for
37+
// Flutter, this means we can't call service extensions (for ex. toggling
38+
// debug modes) so we allow it to override this (and then we skip things
39+
// like breakpoints). We can't do it always, because some functionality
40+
// (such as running multiple test suites) will break by having multiple
41+
// potential VM services come and go.
42+
// https://github.com/Dart-Code/Dart-Code/issues/1673
43+
protected connectVmEvenForNoDebug = false;
3644
protected processExited = false;
3745
public observatory?: ObservatoryConnection;
3846
protected cwd?: string;
@@ -55,6 +63,10 @@ export class DartDebugSession extends DebugSession {
5563
protected logCategory = LogCategory.General; // This isn't used as General, since both Flutter and FlutterWeb override it.
5664
// protected observatoryUriIsProbablyReconnectable = false;
5765

66+
protected get shouldConnectDebugger() {
67+
return !this.noDebug || this.connectVmEvenForNoDebug;
68+
}
69+
5870
public constructor() {
5971
super();
6072

@@ -113,7 +125,7 @@ export class DartDebugSession extends DebugSession {
113125
process.stdout.setEncoding("utf8");
114126
process.stdout.on("data", (data) => {
115127
let match: RegExpExecArray | null = null;
116-
if (this.parseObservatoryUriFromStdOut && !this.observatory) {
128+
if (this.shouldConnectDebugger && this.parseObservatoryUriFromStdOut && !this.observatory) {
117129
match = ObservatoryConnection.bannerRegex.exec(data.toString());
118130
}
119131
if (match) {
@@ -137,6 +149,9 @@ export class DartDebugSession extends DebugSession {
137149
this.logToUser(`Exited (${signal ? `${signal}`.toLowerCase() : code})\n`);
138150
this.sendEvent(new TerminatedEvent());
139151
});
152+
153+
if (!this.shouldConnectDebugger)
154+
this.sendEvent(new InitializedEvent());
140155
}
141156

142157
protected async attachRequest(response: DebugProtocol.AttachResponse, args: DartAttachRequestArguments): Promise<void> {
@@ -181,8 +196,10 @@ export class DartDebugSession extends DebugSession {
181196

182197
protected spawnProcess(args: DartLaunchRequestArguments) {
183198
let appArgs = [];
184-
appArgs.push(`--enable-vm-service=${args.vmServicePort}`);
185-
appArgs.push("--pause_isolates_on_start=true");
199+
if (!this.shouldConnectDebugger) {
200+
appArgs.push(`--enable-vm-service=${args.vmServicePort}`);
201+
appArgs.push("--pause_isolates_on_start=true");
202+
}
186203
if (args.enableAsserts !== false) { // undefined = on
187204
appArgs.push("--enable-asserts");
188205
}
@@ -255,6 +272,9 @@ export class DartDebugSession extends DebugSession {
255272
vmServiceUri: browserFriendlyUri.toString(),
256273
}));
257274

275+
if (!this.shouldConnectDebugger)
276+
return;
277+
258278
return new Promise<void>((resolve, reject) => {
259279
this.log(`Connecting to VM Service at ${uri}`);
260280
this.observatory = new ObservatoryConnection(uri);

‎src/debug/dart_test_debug_impl.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ export class DartTestDebugSession extends DartDebugSession {
2525
// deifferent to the isolates being paused). To do that, we need to change
2626
// how our "unpause" logic works in the base debug adapter (since it won't
2727
// be paused at startup).
28-
// appArgs.push("--pause-after-load");
28+
// if (this.shouldConnectDebugger) {
29+
// appArgs.push("--pause-after-load");
30+
// }
2931

3032
// Instead, we do it the VM way for now...
31-
appArgs.push("--enable-vm-service=0");
32-
appArgs.push("--pause_isolates_on_start=true");
33+
if (this.shouldConnectDebugger) {
34+
appArgs.push("--enable-vm-service=0");
35+
appArgs.push("--pause_isolates_on_start=true");
36+
}
3337

3438
if (args.vmAdditionalArgs) {
3539
appArgs = appArgs.concat(args.vmAdditionalArgs);

‎src/debug/flutter_debug_impl.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export class FlutterDebugSession extends DartDebugSession {
3535
this.parseObservatoryUriFromStdOut = false;
3636
this.requiresProgram = false;
3737
this.logCategory = LogCategory.FlutterRun;
38+
39+
// Enable connecting the VM even for noDebug mode so that service
40+
// extensions can be used.
41+
this.connectVmEvenForNoDebug = true;
3842
}
3943

4044
protected initializeRequest(
@@ -158,10 +162,13 @@ export class FlutterDebugSession extends DartDebugSession {
158162
}
159163
}
160164

161-
appArgs.push("--start-paused");
162-
if (args.vmServicePort && appArgs.indexOf("--observatory-port") === -1) {
163-
appArgs.push("--observatory-port");
164-
appArgs.push(args.vmServicePort.toString());
165+
if (this.shouldConnectDebugger) {
166+
appArgs.push("--start-paused");
167+
168+
if (args.vmServicePort && appArgs.indexOf("--observatory-port") === -1) {
169+
appArgs.push("--observatory-port");
170+
appArgs.push(args.vmServicePort.toString());
171+
}
165172
}
166173
}
167174

‎src/debug/flutter_test_debug_impl.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export class FlutterTestDebugSession extends DartTestDebugSession {
88
protected spawnProcess(args: FlutterLaunchRequestArguments): any {
99
let appArgs: string[] = [];
1010

11-
appArgs.push("--start-paused");
11+
if (this.shouldConnectDebugger) {
12+
appArgs.push("--start-paused");
13+
}
1214

1315
if (args.args) {
1416
appArgs = appArgs.concat(args.args);

‎src/debug/flutter_web_debug_impl.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export class FlutterWebDebugSession extends FlutterDebugSession {
3030
// }
3131
// }
3232

33-
// appArgs.push("--start-paused");
33+
// if (this.shouldConnectDebugger) {
34+
// appArgs.push("--start-paused");
35+
// }
3436
// }
3537

3638
if (args.args) {

0 commit comments

Comments
 (0)