Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally enable backtick command substitution for pickRemoteProcess #5053

Merged
merged 12 commits into from
Mar 10, 2020
6 changes: 6 additions & 0 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@
"default": true,
"description": "%c_cpp.configuration.renameRequiresIdentifier.description%",
"scope": "application"
},
"C_Cpp.debugger.useBacktickCommandSubstitution": {
"type": "boolean",
"default": false,
pieandcakes marked this conversation as resolved.
Show resolved Hide resolved
"description": "%c_cpp.configuration.debugger.useBacktickCommandSubstitution.description%",
"scope": "window"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"c_cpp.configuration.enhancedColorization.description": "If enabled, code is colorized based on IntelliSense. This setting has no effect if IntelliSense is disabled or if using the Default High Contrast theme.",
"c_cpp.configuration.vcpkg.enabled.markdownDescription": "Enable integration services for the [vcpkg dependency manager](https://aka.ms/vcpkg/).",
"c_cpp.configuration.renameRequiresIdentifier.description": "If true, 'Rename Symbol' will require a valid C/C++ identifier.",
"c_cpp.configuration.debugger.useBacktickCommandSubstitution.description": "If true, debugger shell command substitution will use obsolete backtick (`)",
"c_cpp.contributes.views.cppReferencesView.title": "C/C++: Other references results",
"c_cpp.contributes.viewsContainers.activitybar.CppRenameActivityBar.title": "C/C++ Rename",
"c_cpp.contributes.views.cppRenamePendingView.title": "PENDING RENAME",
Expand Down
14 changes: 13 additions & 1 deletion Extension/src/Debugger/attachToProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { PsProcessParser } from './nativeAttach';
import { AttachItem, showQuickPick } from './attachQuickPick';
import { CppSettings } from '../LanguageServer/settings';

import * as debugUtils from './utils';
import * as fs from 'fs';
Expand Down Expand Up @@ -108,6 +109,16 @@ export class RemoteAttachPicker {
private getRemoteProcessCommand(): string {
let innerQuote: string = `'`;
let outerQuote: string = `"`;
let parameterBegin: string = `$(`;
let parameterEnd: string = `)`;
let escapedQuote: string = `\\\"`;

let settings: CppSettings = new CppSettings();
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
if (settings.useBacktickCommandSubstitution) {
parameterBegin = `\``;
parameterEnd = `\``;
escapedQuote = `\"`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does backtick substitution mean that we don't need to escape the \ symbol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally with the escaped \ the command failed with an unmatched " error. I've just looked into this again and it seems to actually be a quirk in csh where stuff in single quotes doesn't get expanded: Stack Overflow answer

}

// 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.
Expand All @@ -116,7 +127,8 @@ export class RemoteAttachPicker {
outerQuote = `'`;
}

return `${outerQuote}sh -c ${innerQuote}uname && if [ $(uname) = \\\"Linux\\\" ] ; then ${PsProcessParser.psLinuxCommand} ; elif [ $(uname) = \\\"Darwin\\\" ] ; ` +
return `${outerQuote}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
1 change: 1 addition & 0 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class CppSettings extends Settings {
public get defaultLimitSymbolsToIncludedHeaders(): boolean | undefined { return super.Section.get<boolean>("default.browse.limitSymbolsToIncludedHeaders"); }
public get defaultSystemIncludePath(): string[] | undefined { return super.Section.get<string[]>("default.systemIncludePath"); }
public get defaultEnableConfigurationSquiggles(): boolean | undefined { return super.Section.get<boolean>("default.enableConfigurationSquiggles"); }
public get useBacktickCommandSubstitution(): boolean | undefined { return super.Section.get<boolean>("debugger.useBacktickCommandSubstitution"); }

public get enhancedColorization(): boolean {
return super.Section.get<string>("enhancedColorization") === "Enabled"
Expand Down