Skip to content

Commit 0eff545

Browse files
committed
Remove TS debug adapter subprocess support (microsoft#12008)
* Remove TS debug adapter subprocess support * Address comments
1 parent 6dc38e5 commit 0eff545

File tree

6 files changed

+54
-314
lines changed

6 files changed

+54
-314
lines changed

src/client/debugger/extension/hooks/childProcessAttachHandler.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DebugConfiguration, DebugSessionCustomEvent } from 'vscode';
88
import { swallowExceptions } from '../../../common/utils/decorators';
99
import { AttachRequestArguments } from '../../types';
1010
import { DebuggerEvents } from './constants';
11-
import { ChildProcessLaunchData, IChildProcessAttachService, IDebugSessionEventHandlers } from './types';
11+
import { IChildProcessAttachService, IDebugSessionEventHandlers } from './types';
1212

1313
/**
1414
* This class is responsible for automatically attaching the debugger to any
@@ -29,10 +29,8 @@ export class ChildProcessAttachEventHandler implements IDebugSessionEventHandler
2929
return;
3030
}
3131

32-
let data: ChildProcessLaunchData | (AttachRequestArguments & DebugConfiguration);
33-
if (event.event === DebuggerEvents.ChildProcessLaunched) {
34-
data = event.body! as ChildProcessLaunchData;
35-
} else if (
32+
let data: AttachRequestArguments & DebugConfiguration;
33+
if (
3634
event.event === DebuggerEvents.PtvsdAttachToSubprocess ||
3735
event.event === DebuggerEvents.DebugpyAttachToSubprocess
3836
) {

src/client/debugger/extension/hooks/childProcessAttachService.ts

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { inject, injectable } from 'inversify';
77
import { DebugConfiguration, DebugSession, WorkspaceFolder } from 'vscode';
88
import { IApplicationShell, IDebugService, IWorkspaceService } from '../../../common/application/types';
99
import { noop } from '../../../common/utils/misc';
10-
import { SystemVariables } from '../../../common/variables/systemVariables';
1110
import { captureTelemetry } from '../../../telemetry';
1211
import { EventName } from '../../../telemetry/constants';
13-
import { AttachRequestArguments, LaunchRequestArguments } from '../../types';
14-
import { ChildProcessLaunchData, IChildProcessAttachService } from './types';
12+
import { AttachRequestArguments } from '../../types';
13+
import { IChildProcessAttachService } from './types';
1514

1615
/**
1716
* This class is responsible for attaching the debugger to any
@@ -29,49 +28,16 @@ export class ChildProcessAttachService implements IChildProcessAttachService {
2928
) {}
3029

3130
@captureTelemetry(EventName.DEBUGGER_ATTACH_TO_CHILD_PROCESS)
32-
public async attach(
33-
data: ChildProcessLaunchData | (AttachRequestArguments & DebugConfiguration),
34-
parentSession: DebugSession
35-
): Promise<void> {
36-
let debugConfig: AttachRequestArguments & DebugConfiguration;
37-
let processId: number;
38-
if (this.isChildProcessLaunchData(data)) {
39-
processId = data.processId;
40-
debugConfig = this.getAttachConfiguration(data);
41-
} else {
42-
debugConfig = data;
43-
processId = debugConfig.subProcessId!;
44-
}
31+
public async attach(data: AttachRequestArguments & DebugConfiguration, parentSession: DebugSession): Promise<void> {
32+
const debugConfig: AttachRequestArguments & DebugConfiguration = data;
33+
const processId = debugConfig.subProcessId!;
4534
const folder = this.getRelatedWorkspaceFolder(debugConfig);
4635
const launched = await this.debugService.startDebugging(folder, debugConfig, parentSession);
4736
if (!launched) {
4837
this.appShell.showErrorMessage(`Failed to launch debugger for child process ${processId}`).then(noop, noop);
4938
}
5039
}
51-
/**
52-
* Since we're attaching we need to provide path mappings.
53-
* If not provided, we cannot add breakpoints as we don't have mappings to the actual source.
54-
* This is because attach automatically assumes remote debugging.
55-
* Also remember, this code gets executed only when dynamically attaching to child processes.
56-
* Resolves https://github.com/microsoft/vscode-python/issues/3568
57-
*/
58-
public fixPathMappings(config: LaunchRequestArguments & AttachRequestArguments & DebugConfiguration) {
59-
if (!config.workspaceFolder) {
60-
return;
61-
}
62-
if (Array.isArray(config.pathMappings) && config.pathMappings.length > 0) {
63-
return;
64-
}
65-
// If user has provided a `cwd` in their `launch.json`, then we need to use
66-
// the `cwd` as the localRoot.
67-
// We cannot expect the debugger to assume remote root is the same as the cwd,
68-
// As debugger doesn't necessarily know whether the process being attached to is
69-
// a child process or not.
70-
const systemVariables = new SystemVariables(undefined, config.workspaceFolder);
71-
const localRoot =
72-
config.cwd && config.cwd.length > 0 ? systemVariables.resolveAny(config.cwd) : config.workspaceFolder;
73-
config.pathMappings = [{ remoteRoot: '.', localRoot }];
74-
}
40+
7541
private getRelatedWorkspaceFolder(
7642
config: AttachRequestArguments & DebugConfiguration
7743
): WorkspaceFolder | undefined {
@@ -81,21 +47,4 @@ export class ChildProcessAttachService implements IChildProcessAttachService {
8147
}
8248
return this.workspaceService.workspaceFolders!.find((ws) => ws.uri.fsPath === workspaceFolder);
8349
}
84-
private getAttachConfiguration(data: ChildProcessLaunchData): AttachRequestArguments & DebugConfiguration {
85-
const args = data.rootStartRequest.arguments;
86-
// tslint:disable-next-line:no-any
87-
const config = (JSON.parse(JSON.stringify(args)) as any) as AttachRequestArguments & DebugConfiguration;
88-
// tslint:disable-next-line: no-any
89-
this.fixPathMappings(config as any);
90-
config.host = args.request === 'attach' ? args.host! : 'localhost';
91-
config.port = data.port;
92-
config.name = `Child Process ${data.processId}`;
93-
config.request = 'attach';
94-
return config;
95-
}
96-
private isChildProcessLaunchData(
97-
data: ChildProcessLaunchData | (AttachRequestArguments & DebugConfiguration)
98-
): data is ChildProcessLaunchData {
99-
return data.rootStartRequest !== undefined;
100-
}
10150
}

src/client/debugger/extension/hooks/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
export enum DebuggerEvents {
77
// Event sent by PTVSD when a child process is launched and ready to be attached to for multi-proc debugging.
8-
ChildProcessLaunched = 'ptvsd_subprocess',
98
PtvsdAttachToSubprocess = 'ptvsd_attach',
109
DebugpyAttachToSubprocess = 'debugpyAttach'
1110
}

src/client/debugger/extension/hooks/types.ts

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,15 @@
44
'use strict';
55

66
import { DebugConfiguration, DebugSession, DebugSessionCustomEvent } from 'vscode';
7-
import { AttachRequestArguments, LaunchRequestArguments } from '../../types';
7+
import { AttachRequestArguments } from '../../types';
88

99
export const IDebugSessionEventHandlers = Symbol('IDebugSessionEventHandlers');
1010
export interface IDebugSessionEventHandlers {
1111
handleCustomEvent?(e: DebugSessionCustomEvent): Promise<void>;
1212
handleTerminateEvent?(e: DebugSession): Promise<void>;
1313
}
1414

15-
export type ChildProcessLaunchData = {
16-
/**
17-
* The main process (that in turn starts child processes).
18-
* @type {number}
19-
*/
20-
rootProcessId: number;
21-
/**
22-
* The immediate parent of the current process (identified by `processId`).
23-
* This could be the same as `parentProcessId`, or something else.
24-
* @type {number}
25-
*/
26-
parentProcessId: number;
27-
/**
28-
* The process id of the child process launched.
29-
* @type {number}
30-
*/
31-
processId: number;
32-
/**
33-
* Port on which the child process is listening and waiting for the debugger to attach.
34-
* @type {number}
35-
*/
36-
port: number;
37-
/**
38-
* The request object sent to the PTVSD by the main process.
39-
* If main process was launched, then `arguments` would be the launch request arsg,
40-
* else it would be the attach request args.
41-
* @type {({
42-
* // tslint:disable-next-line:no-banned-terms
43-
* arguments: LaunchRequestArguments | AttachRequestArguments;
44-
* command: 'attach' | 'request';
45-
* seq: number;
46-
* type: string;
47-
* })}
48-
*/
49-
rootStartRequest: {
50-
// tslint:disable-next-line:no-banned-terms
51-
arguments: LaunchRequestArguments | AttachRequestArguments;
52-
command: 'attach' | 'request';
53-
seq: number;
54-
type: string;
55-
};
56-
};
57-
5815
export const IChildProcessAttachService = Symbol('IChildProcessAttachService');
5916
export interface IChildProcessAttachService {
60-
attach(
61-
data: ChildProcessLaunchData | (AttachRequestArguments & DebugConfiguration),
62-
parentSession: DebugSession
63-
): Promise<void>;
17+
attach(data: AttachRequestArguments & DebugConfiguration, parentSession: DebugSession): Promise<void>;
6418
}

src/test/debugger/extension/hooks/childProcessAttachHandler.unit.test.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { anything, capture, instance, mock, verify, when } from 'ts-mockito';
1010
import { ChildProcessAttachEventHandler } from '../../../../client/debugger/extension/hooks/childProcessAttachHandler';
1111
import { ChildProcessAttachService } from '../../../../client/debugger/extension/hooks/childProcessAttachService';
1212
import { DebuggerEvents } from '../../../../client/debugger/extension/hooks/constants';
13-
import { ChildProcessLaunchData } from '../../../../client/debugger/extension/hooks/types';
13+
import { AttachRequestArguments } from '../../../../client/debugger/types';
1414

1515
suite('Debug - Child Process', () => {
1616
test('Do not attach if the event is undefined', async () => {
@@ -27,14 +27,6 @@ suite('Debug - Child Process', () => {
2727
await handler.handleCustomEvent({ event: 'abc', body, session });
2828
verify(attachService.attach(body, session)).never();
2929
});
30-
test('Do not attach to child process if ptvsd_subprocess event is invalid', async () => {
31-
const attachService = mock(ChildProcessAttachService);
32-
const handler = new ChildProcessAttachEventHandler(instance(attachService));
33-
const body: any = {};
34-
const session: any = {};
35-
await handler.handleCustomEvent({ event: DebuggerEvents.ChildProcessLaunched, body, session });
36-
verify(attachService.attach(body, session)).never();
37-
});
3830
test('Do not attach to child process if ptvsd_attach event is invalid', async () => {
3931
const attachService = mock(ChildProcessAttachService);
4032
const handler = new ChildProcessAttachEventHandler(instance(attachService));
@@ -54,25 +46,16 @@ suite('Debug - Child Process', () => {
5446
test('Exceptions are not bubbled up if exceptions are thrown', async () => {
5547
const attachService = mock(ChildProcessAttachService);
5648
const handler = new ChildProcessAttachEventHandler(instance(attachService));
57-
const body: ChildProcessLaunchData = {
58-
rootProcessId: 0,
59-
parentProcessId: 0,
60-
processId: 0,
61-
port: 0,
62-
rootStartRequest: {
63-
arguments: {
64-
type: 'python',
65-
name: '',
66-
request: 'attach'
67-
},
68-
command: 'attach',
69-
seq: 0,
70-
type: 'python'
71-
}
49+
const body: AttachRequestArguments = {
50+
name: 'Attach',
51+
type: 'python',
52+
request: 'attach',
53+
port: 1234,
54+
subProcessId: 2
7255
};
7356
const session: any = {};
7457
when(attachService.attach(body, session)).thenThrow(new Error('Kaboom'));
75-
await handler.handleCustomEvent({ event: DebuggerEvents.ChildProcessLaunched, body, session: {} as any });
58+
await handler.handleCustomEvent({ event: DebuggerEvents.DebugpyAttachToSubprocess, body, session: {} as any });
7659
verify(attachService.attach(body, anything())).once();
7760
const [, secondArg] = capture(attachService.attach).last();
7861
expect(secondArg).to.deep.equal(session);

0 commit comments

Comments
 (0)