Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Bug Fixes:
- Update terminal's environment variables when the kit is changed. [#2364](https://github.com/microsoft/vscode-cmake-tools/issues/2364)
- Add timeouts for compiler scanning. [#1289](https://github.com/microsoft/vscode-cmake-tools/issues/1289)
- Fix schema validation for presets version 4. [#2490](https://github.com/microsoft/vscode-cmake-tools/issues/2490)
- Remove problematic environment variables from the debugger environment. [#2442](https://github.com/microsoft/vscode-cmake-tools/issues/2442)

## 1.10.5
Bug Fixes:
Expand Down
4 changes: 1 addition & 3 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ function searchForCompilerPathInCache(cache: CMakeCache): string | null {
return null;
}

export async function getDebugConfigurationFromCache(cache: CMakeCache, target: ExecutableTarget, platform: string,
modeOverride?: MIModes, debuggerPathOverride?: string):
Promise<VSCodeDebugConfiguration | null> {
export async function getDebugConfigurationFromCache(cache: CMakeCache, target: ExecutableTarget, platform: string, modeOverride?: MIModes, debuggerPathOverride?: string): Promise<VSCodeDebugConfiguration | null> {
const entry = cache.get('CMAKE_LINKER');
if (entry !== null) {
const linker = entry.value as string;
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,10 @@ export function makeDebuggerEnvironmentVars(env?: Environment): DebuggerEnvironm
if (!env) {
return [];
}
const filter: RegExp = /\$\{.+?\}/; // Disallow env variables that have variable expansion values
const converted_env: DebuggerEnvironmentVariable[] = [];
for (const [key, value] of Object.entries(env)) {
if (value !== undefined) {
if (value !== undefined && !value.match(filter)) {
converted_env.push({
name: key,
value
Expand Down
16 changes: 16 additions & 0 deletions test/unit-tests/debugger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fromDebuggerEnvironmentVars, makeDebuggerEnvironmentVars } from "@cmt/util";
import { expect } from "@test/util";

suite('debugger tests', () => {
test('No variable expansion env vars', () => {
const env: {[key: string]: string} = {};
env['foo'] = 'bar';
env['other'] = '${hey';
Copy link
Contributor

Choose a reason for hiding this comment

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

A question: So our assumption is that all the env variables are resolved by this point, and if they are not (or if not expanded), we just don't send them to the debugger?

Copy link
Member Author

@bobbrow bobbrow Apr 12, 2022

Choose a reason for hiding this comment

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

Yes. The output of makeDebuggerEnvironmentVars gets put into the environment of the debug config object and sent to VS Code. I call fromDebuggerEnvironmentVars to convert it into a dictionary object that's easier to validate.

env['BASH_FUNC_which%%'] = '() { ( alias;\n eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot \"$@\"\n}';
env['BASH_FUNC_module()'] = '() { eval $($LMOD_CMD bash "$@") && eval $(${LMOD_SETTARG_CMD:-:} -s sh';

const debugEnv = fromDebuggerEnvironmentVars(makeDebuggerEnvironmentVars(env));
expect(debugEnv).to.contain.keys('foo', 'other');
expect(debugEnv).to.not.contain.keys('BASH_FUNC_which%%', 'BASH_FUNC_module()');
});
});