@@ -7,11 +7,10 @@ import { inject, injectable } from 'inversify';
77import { DebugConfiguration , DebugSession , WorkspaceFolder } from 'vscode' ;
88import { IApplicationShell , IDebugService , IWorkspaceService } from '../../../common/application/types' ;
99import { noop } from '../../../common/utils/misc' ;
10- import { SystemVariables } from '../../../common/variables/systemVariables' ;
1110import { captureTelemetry } from '../../../telemetry' ;
1211import { 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}
0 commit comments