Skip to content

Commit

Permalink
src/goDebugFactory: add support for asRoot property
Browse files Browse the repository at this point in the history
On Linux/MacOS, this will look up the sudo utility and prepend it
to the runInTerminal args.

Not updated packages.json yet.

Updates #558

Change-Id: I021194e0fd8dc2ae1bdd54ddefb5ea3b6df356d8
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/361100
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
hyangah committed Jan 4, 2022
1 parent c4f5c25 commit a807c61
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/goDebugFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Logger, logVerbose, TimestampedLogger } from './goLogging';
import { DebugProtocol } from 'vscode-debugprotocol';
import { getWorkspaceFolderPath } from './util';
import { toolExecutionEnvironment } from './goEnv';
import { envPath, getBinPathFromEnvVar } from './utils/pathUtils';

export class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFactory {
constructor(private outputChannel?: vscode.OutputChannel) {}
Expand Down Expand Up @@ -402,13 +403,23 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
dlvArgs.push(`--log-dest=${logDest}`);
}

dlvArgs.unshift(dlvPath);

if (launchAttachArgs.asRoot === true && process.platform !== 'win32') {
const sudo = getSudo();
if (sudo) {
dlvArgs.unshift(sudo);
} else {
throw new Error('Failed to find "sudo" utility');
}
}

try {
const port = await getPort();
const rendezvousServerPromise = waitForDAPServer(port, 30_000);

dlvArgs.push(`--client-addr=:${port}`);

dlvArgs.unshift(dlvPath);
super.sendMessageToClient({
seq: 0,
type: 'request',
Expand All @@ -430,6 +441,14 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
}
}

let sudoPath: string | null | undefined = undefined;
function getSudo(): string | null {
if (sudoPath === undefined) {
sudoPath = getBinPathFromEnvVar('sudo', envPath, false);
}
return sudoPath;
}

function waitForDAPServer(port: number, timeoutMs: number): Promise<net.Socket> {
return new Promise((resolve, reject) => {
let s: net.Server = undefined;
Expand Down

0 comments on commit a807c61

Please sign in to comment.