Skip to content

Commit 63e23ce

Browse files
authored
Merge pull request #1 from ZA139/new-process_tree
Integrate windows-process-tree for Windows process enumeration
2 parents 413ba5a + 4a5f3d7 commit 63e23ce

File tree

5 files changed

+276
-34
lines changed

5 files changed

+276
-34
lines changed

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@
682682
"@vscode/debugprotocol": "^1.65.0",
683683
"@vscode/extension-telemetry": "^0.8.4",
684684
"@vscode/python-extension": "^1.0.6",
685+
"@vscode/windows-process-tree": "^0.7.0",
685686
"fs-extra": "^11.2.0",
686687
"iconv-lite": "^0.6.3",
687688
"jsonc-parser": "^3.0.0",

src/extension/debugger/attachQuickPick/provider.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'use strict';
55

66
import { l10n } from 'vscode';
7+
import * as wpc from '@vscode/windows-process-tree';
78
import { getOSType, OSType } from '../../common/platform';
89
import { PsProcessParser } from './psProcessParser';
910
import { IAttachItem, IAttachProcessProvider, ProcessListCommand } from './types';
@@ -58,24 +59,46 @@ export class AttachProcessProvider implements IAttachProcessProvider {
5859
}
5960

6061
public async _getInternalProcessEntries(): Promise<IAttachItem[]> {
61-
let processCmd: ProcessListCommand;
6262
const osType = getOSType();
63+
64+
if (osType === OSType.Windows) {
65+
try {
66+
const processList = await new Promise<wpc.IProcessInfo[]>((resolve) => {
67+
wpc.getAllProcesses((processes) => resolve(processes), wpc.ProcessDataFlag.CommandLine);
68+
});
69+
return processList.map((p) => ({
70+
label: p.name,
71+
description: String(p.pid),
72+
detail: p.commandLine || '',
73+
id: String(p.pid),
74+
processName: p.name,
75+
commandLine: p.commandLine || '',
76+
}));
77+
} catch {
78+
const customEnvVars = await getEnvironmentVariables();
79+
const output = await plainExec(
80+
WmicProcessParser.wmicCommand.command,
81+
WmicProcessParser.wmicCommand.args,
82+
{ throwOnStdErr: true },
83+
customEnvVars,
84+
);
85+
logProcess(WmicProcessParser.wmicCommand.command, WmicProcessParser.wmicCommand.args, { throwOnStdErr: true });
86+
return WmicProcessParser.parseProcesses(output.stdout);
87+
}
88+
}
89+
90+
let processCmd: ProcessListCommand;
6391
if (osType === OSType.OSX) {
6492
processCmd = PsProcessParser.psDarwinCommand;
6593
} else if (osType === OSType.Linux) {
6694
processCmd = PsProcessParser.psLinuxCommand;
67-
} else if (osType === OSType.Windows) {
68-
processCmd = WmicProcessParser.wmicCommand;
6995
} else {
7096
throw new Error(l10n.t("Operating system '{0}' not supported.", osType));
7197
}
7298

7399
const customEnvVars = await getEnvironmentVariables();
74100
const output = await plainExec(processCmd.command, processCmd.args, { throwOnStdErr: true }, customEnvVars);
75101
logProcess(processCmd.command, processCmd.args, { throwOnStdErr: true });
76-
77-
return osType === OSType.Windows
78-
? WmicProcessParser.parseProcesses(output.stdout)
79-
: PsProcessParser.parseProcesses(output.stdout);
102+
return PsProcessParser.parseProcesses(output.stdout);
80103
}
81104
}

0 commit comments

Comments
 (0)