Skip to content

Commit 438cbb2

Browse files
Copilotsnehara99
andauthored
Honor debugger.workingDirectory from CMake File API when debugging targets (#4753)
* Initial plan * feat: honor debugger.workingDirectory from CMake File API when debugging targets - Add `debugger` property to CodeModelKind.TargetObject to parse the debugger.workingDirectory field from CMake File API target JSON - Thread debuggerWorkingDirectory through RichTarget and ExecutableTarget - Use debuggerWorkingDirectory as cwd in GDB, LLDB, and MSVC debug configurations, falling back to the target's build directory - Add DEBUGGER_WORKING_DIRECTORY and CMAKE_DEBUGGER_WORKING_DIRECTORY entries to assets/variables.json Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com> * revert: undo changes to assets/variables.json (updated via script separately) Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com> * Add changelog entry for debugger.workingDirectory support (#4595) Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: snehara99 <113148726+snehara99@users.noreply.github.com>
1 parent 7d781aa commit 438cbb2

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Improvements:
2424
- Allow preset modification commands to target CMakeUserPresets.json. The target file is determined by the focused editor, or by prompting the user when both files exist. [#4564](https://github.com/microsoft/vscode-cmake-tools/issues/4564)
2525
- Display info tooltip when hovering over CMake policy identifiers (e.g., `CMP0177`), showing the CMake version that introduced the policy, a short description, and a link to the official documentation. [#4544](https://github.com/microsoft/vscode-cmake-tools/issues/4544)
2626
- Append `cmake` to diagnostics that this extension contributes to the Problems Pane. [PR #4766](https://github.com/microsoft/vscode-cmake-tools/pull/4766)
27+
- Honor `debugger.workingDirectory` from the CMake File API when debugging a target, so that the `DEBUGGER_WORKING_DIRECTORY` target property is used as the debugger working directory. [#4595](https://github.com/microsoft/vscode-cmake-tools/issues/4595)
2728

2829
Bug Fixes:
2930
- Fix configure/build sometimes using stale preset values when unsaved changes to included preset files are auto-saved before configure. The extension now explicitly refreshes presets from disk after saving, instead of relying solely on the asynchronous file watcher. [#4502](https://github.com/microsoft/vscode-cmake-tools/issues/4502)

src/debug/debugger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function createGDBDebugConfiguration(debuggerPath: string, target: Executa
9595
type: 'cppdbg',
9696
name: `Debug ${target.name}`,
9797
request: 'launch',
98-
cwd: path.dirname(target.path),
98+
cwd: target.debuggerWorkingDirectory || path.dirname(target.path),
9999
args: [],
100100
MIMode: MIModes.gdb,
101101
miDebuggerPath: debuggerPath,
@@ -127,7 +127,7 @@ async function createLLDBDebugConfiguration(debuggerPath: string, target: Execut
127127
type: 'cppdbg',
128128
name: `Debug ${target.name}`,
129129
request: 'launch',
130-
cwd: path.dirname(target.path),
130+
cwd: target.debuggerWorkingDirectory || path.dirname(target.path),
131131
args: [],
132132
MIMode: MIModes.lldb,
133133
miDebuggerPath: debuggerPath,
@@ -146,7 +146,7 @@ function createMsvcDebugConfiguration(target: ExecutableTarget): VSCodeDebugConf
146146
type: 'cppvsdbg',
147147
name: `Debug ${target.name}`,
148148
request: 'launch',
149-
cwd: path.dirname(target.path),
149+
cwd: target.debuggerWorkingDirectory || path.dirname(target.path),
150150
args: [],
151151
program: target.path
152152
};

src/drivers/cmakeDriver.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export interface ExecutableTarget {
9595
* The install locations of the target.
9696
*/
9797
isInstallTarget?: boolean;
98+
/**
99+
* The working directory for the debugger, from the DEBUGGER_WORKING_DIRECTORY target property.
100+
*/
101+
debuggerWorkingDirectory?: string;
98102
}
99103

100104
/**
@@ -124,6 +128,7 @@ export interface RichTarget {
124128
targetType: string;
125129
folder?: CodeModelKind.TargetObject;
126130
installPaths?: InstallPath[];
131+
debuggerWorkingDirectory?: string;
127132
}
128133

129134
export type Target = NamedTarget | RichTarget;

src/drivers/cmakeFileApi.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export namespace CodeModelKind {
171171
name: string;
172172
}
173173

174+
export interface DebuggerInfo {
175+
workingDirectory?: string;
176+
}
177+
174178
export interface TargetObject {
175179
name: string;
176180
type: string;
@@ -183,6 +187,7 @@ export namespace CodeModelKind {
183187
folder?: Folder;
184188
isGeneratorProvided?: boolean;
185189
install?: InstallInfo;
190+
debugger?: DebuggerInfo;
186191
}
187192
}
188193

@@ -427,7 +432,8 @@ async function convertTargetObjectFileToExtensionTarget(buildDirectory: string,
427432
targetType: targetObject.type,
428433
folder: targetObject.folder,
429434
type: 'rich' as 'rich',
430-
installPaths: installPaths
435+
installPaths: installPaths,
436+
debuggerWorkingDirectory: targetObject.debugger?.workingDirectory
431437
} as RichTarget;
432438
}
433439

src/drivers/cmakeFileApiDriver.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ export class CMakeFileApiDriver extends CMakeDriver {
428428
const executableTargetsWithInstall = uniqueExecTargets.map(t => ({
429429
name: t.name,
430430
path: (t as RichTarget).filepath,
431-
isInstallTarget: false
431+
isInstallTarget: false,
432+
debuggerWorkingDirectory: (t as RichTarget).debuggerWorkingDirectory
432433
}));
433434

434435
const installLoc = localize("cmake.install.name", "Install");
@@ -440,7 +441,8 @@ export class CMakeFileApiDriver extends CMakeDriver {
440441
executableTargetsWithInstall.push({
441442
name: `${target.name} (${installLoc}${includePath ? ` - ${installPath.subPath}` : ''})`,
442443
path: installPath.path,
443-
isInstallTarget: true
444+
isInstallTarget: true,
445+
debuggerWorkingDirectory: target.debuggerWorkingDirectory
444446
});
445447
}
446448
}

0 commit comments

Comments
 (0)