Skip to content

Commit

Permalink
remote attach: use absolute /bin/sh path on Linux
Browse files Browse the repository at this point in the history
When using machinectl as a transport to connect the debugger to
a nspawn container, we need to pass full paths when running commands,
as that's what machinectl expects. Use /bin/sh when running on Linux.
This allows connecting VSCode to nspawn containers.

https://www.freedesktop.org/software/systemd/man/machinectl.html
https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html
  • Loading branch information
bluca committed Mar 31, 2023
1 parent 8334b15 commit f0bfbf9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Extension/src/Debugger/attachToProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class RemoteAttachPicker {
let parameterBegin: string = `$(`;
let parameterEnd: string = `)`;
let escapedQuote: string = `\\\"`;
let shPrefix: string = ``;

const settings: CppSettings = new CppSettings();
if (settings.useBacktickCommandSubstitution) {
Expand All @@ -122,12 +123,14 @@ export class RemoteAttachPicker {

// Must use single quotes around the whole command and double quotes for the argument to `sh -c` because Linux evaluates $() inside of double quotes.
// Having double quotes for the outerQuote will have $(uname) replaced before it is sent to the remote machine.
// Also use a full path on Linux, so that we can use transports that need a full patch such as 'machinectl' to connect to nspawn containers.
if (os.platform() !== "win32") {
innerQuote = `"`;
outerQuote = `'`;
shPrefix = `/bin/`;
}

return `${outerQuote}sh -c ${innerQuote}uname && if [ ${parameterBegin}uname${parameterEnd} = ${escapedQuote}Linux${escapedQuote} ] ; ` +
return `${outerQuote}${shPrefix}sh -c ${innerQuote}uname && if [ ${parameterBegin}uname${parameterEnd} = ${escapedQuote}Linux${escapedQuote} ] ; ` +
`then ${PsProcessParser.psLinuxCommand} ; elif [ ${parameterBegin}uname${parameterEnd} = ${escapedQuote}Darwin${escapedQuote} ] ; ` +
`then ${PsProcessParser.psDarwinCommand}; fi${innerQuote}${outerQuote}`;
}
Expand Down

0 comments on commit f0bfbf9

Please sign in to comment.