Skip to content

Commit

Permalink
src/utils/wmicProcessParser.ts: get exe path from wmic
Browse files Browse the repository at this point in the history
Get the executable path from the wmic output to be used
to determine if process is running go.

Updates golang#183

Change-Id: I6894897d8a4744498f14154b03da89110a7ef567
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/288172
Trust: Suzy Mueller <[email protected]>
Run-TryBot: Suzy Mueller <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
suzmue committed Jan 29, 2021
1 parent aa02c3f commit 46a15da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/pickProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export interface ProcessListCommand {

async function getGoProcesses(): Promise<AttachItem[]> {
const processes = await getAllProcesses();
// TODO(suzmue): set the executable path for win32 and darwin.
if (process.platform !== 'linux') {
// TODO(suzmue): set the executable path for and darwin.
if (process.platform === 'darwin') {
return processes;
}

// Run 'go version' on all of /proc/${pid}/exe to find 'go' processes
// Run 'go version' on all executable paths to find 'go' processes
const goRuntimePath = getBinPath('go');
if (!goRuntimePath) {
vscode.window.showErrorMessage(
Expand Down Expand Up @@ -94,7 +94,7 @@ async function getGoProcesses(): Promise<AttachItem[]> {

const goProcesses: AttachItem[] = [];
processes.forEach((item) => {
if (goProcessExes.indexOf(item.id) >= 0) {
if (goProcessExes.indexOf(item.executable) >= 0) {
item.isGo = true;
goProcesses.push(item);
}
Expand Down
10 changes: 7 additions & 3 deletions src/utils/wmicProcessParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------*/

// Taken from:
// https://github.com/microsoft/vscode-python/blob/main/src/client/debugger/extension/attachQuickPick/wmicProcessParser.ts
// Modified from:
// https://github.com/microsoft/vscode-python/blob/main/src/client/debugger/extension/attachQuickPick/wmicProcessParser.ts.
// Added arguments to get the ExecutablePath from wmic.

'use strict';

Expand All @@ -14,6 +15,7 @@ import { AttachItem, ProcessListCommand } from '../pickProcess';
const wmicNameTitle = 'Name';
const wmicCommandLineTitle = 'CommandLine';
const wmicPidTitle = 'ProcessId';
const wmicExecutableTitle = 'ExecutablePath';
const defaultEmptyEntry: AttachItem = {
label: '',
description: '',
Expand All @@ -32,7 +34,7 @@ const defaultEmptyEntry: AttachItem = {
// | 1308 | 1132 |
export const wmicCommand: ProcessListCommand = {
command: 'wmic',
args: ['process', 'get', 'Name,ProcessId,CommandLine', '/FORMAT:list']
args: ['process', 'get', 'Name,ProcessId,CommandLine,ExecutablePath', '/FORMAT:list']
};

export function parseWmicProcesses(processes: string): AttachItem[] {
Expand Down Expand Up @@ -79,6 +81,8 @@ function parseLineFromWmic(line: string, item: AttachItem): AttachItem {

currentItem.detail = value;
currentItem.commandLine = value;
} else if (key === wmicExecutableTitle) {
currentItem.executable = value;
}
}

Expand Down

0 comments on commit 46a15da

Please sign in to comment.