Skip to content

Commit 4046187

Browse files
committed
Fix: Address all PR review feedback from sean-mcmanus
- Move remote attach check to beginning (silent fallback) - Validate program path before processing - Make case-sensitive matching OS-specific (Windows only) - Remove startsWith matching (exact match only) - Optimize targetName outside lambda with .exe suffix on Windows - Remove all logging statements - Fall back to process picker instead of showing errors - Fix grammar in comments (add 'the' articles) - Update descriptions in package.nls.json for clarity
1 parent 050503c commit 4046187

2 files changed

Lines changed: 30 additions & 31 deletions

File tree

Extension/package.nls.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,12 +932,12 @@
932932
]
933933
},
934934
"c_cpp.debuggers.program.attach.markdownDescription": {
935-
"message": "Optional full path to program executable. When specified, the debugger will search for a running process matching this executable name and attach to it. If multiple processes match, a selection prompt will be shown. Use either `program` or `processId`, not both.",
935+
"message": "Optional full path to the program executable. When specified, the debugger will search for a running process matching this executable path and attach to it. If multiple processes match, a selection prompt will be shown. Use either `program` or `processId`, not both.",
936936
"comment": [
937937
"{Locked=\"`program`\"} {Locked=\"`processId`\"}"
938938
]
939939
},
940-
"c_cpp.debuggers.symbolSearchPath.description": "Semicolon separated list of directories to use to search for .so files. Example: \"c:\\dir1;c:\\dir2\".",
940+
"c_cpp.debuggers.symbolSearchPath.description": "Semicolon separated list of directories to use to search for symbol (that is, pdb or .so) files. Example: \"c:\\dir1;c:\\dir2\".",
941941
"c_cpp.debuggers.dumpPath.description": "Optional full path to a dump file for the specified program. Example: \"c:\\temp\\app.dmp\". Defaults to null.",
942942
"c_cpp.debuggers.enableDebugHeap.description": "If false, the process will be launched with debug heap disabled. This sets the environment variable '_NO_DEBUG_HEAP' to '1'.",
943943
"c_cpp.debuggers.symbolLoadInfo.description": "Explicit control of symbol loading.",

Extension/src/Debugger/configurationProvider.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,14 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
356356
if (config.request === "attach" && !config.processId) {
357357
let processId: string | undefined;
358358

359-
// If program is specified, try to find matching process by name
359+
// If program is specified, try to find the matching process by name
360360
if (config.program) {
361361
processId = await this.findProcessByProgramName(config.program, config, token);
362-
if (!processId) {
363-
void logger.getOutputChannelLogger().showErrorMessage(`No running process found matching "${config.program}".`);
364-
return undefined;
365-
}
366-
} else {
367-
// Show process picker if no program specified
362+
}
363+
364+
// Fall back to process picker if program wasn't specified or didn't match
365+
if (!processId) {
366+
// Show the process picker if no program is specified
368367
if (config.pipeTransport || config.useExtendedRemote) {
369368
const remoteAttachPicker: RemoteAttachPicker = new RemoteAttachPicker();
370369
processId = await remoteAttachPicker.ShowAttachEntries(config);
@@ -1175,41 +1174,41 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
11751174
config: CppDebugConfiguration,
11761175
token?: vscode.CancellationToken
11771176
): Promise<string | undefined> {
1178-
const programBaseName: string = path.basename(programPath);
1179-
let processes: AttachItem[];
1180-
1181-
// Get process list using the same logic as interactive attach
1177+
// Remote attach is not supported for program-based matching
11821178
if (config.pipeTransport || config.useExtendedRemote) {
1183-
// For remote attach, we need to use RemoteAttachPicker's methods
1184-
void logger.getOutputChannelLogger().showErrorMessage(
1185-
"Finding process by program name is not yet supported for remote attach. Please use processId instead."
1186-
);
11871179
return undefined;
1188-
} else {
1189-
const attachItemsProvider: AttachItemsProvider = NativeAttachItemsProviderFactory.Get();
1190-
processes = await attachItemsProvider.getAttachItems(token);
1180+
}
1181+
1182+
// Validate that the program path is valid
1183+
if (!await util.checkExecutableWithoutExtensionExists(programPath)) {
1184+
return undefined;
1185+
}
1186+
1187+
const programBaseName: string = path.basename(programPath);
1188+
1189+
// Get the process list using the same logic as interactive attach
1190+
const attachItemsProvider: AttachItemsProvider = NativeAttachItemsProviderFactory.Get();
1191+
const processes: AttachItem[] = await attachItemsProvider.getAttachItems(token);
1192+
1193+
// Prepare target name for matching (case-insensitive on Windows only)
1194+
let targetName: string = programBaseName;
1195+
if (isWindows) {
1196+
targetName = targetName.toLowerCase();
1197+
targetName = targetName.endsWith(".exe") ? targetName : (targetName + ".exe");
11911198
}
11921199

11931200
// Find processes matching the program name
11941201
const matchingProcesses: AttachItem[] = processes.filter(p => {
1195-
const processName: string = p.label.toLowerCase();
1196-
const targetName: string = programBaseName.toLowerCase();
1197-
// Match if the process name exactly matches or starts with the target name
1198-
return processName === targetName || processName.startsWith(targetName);
1202+
const processName: string = isWindows ? p.label.toLowerCase() : p.label;
1203+
return processName === targetName;
11991204
});
12001205

12011206
if (matchingProcesses.length === 0) {
12021207
return undefined;
12031208
} else if (matchingProcesses.length === 1) {
1204-
void logger.getOutputChannelLogger().appendLine(
1205-
`Found process "${matchingProcesses[0].label}" with PID ${matchingProcesses[0].id}`
1206-
);
12071209
return matchingProcesses[0].id;
12081210
} else {
1209-
// Multiple matches - let user choose
1210-
void logger.getOutputChannelLogger().appendLine(
1211-
`Multiple processes found matching "${programBaseName}". Please select one:`
1212-
);
1211+
// Multiple matches - let the user choose
12131212
return showQuickPick(() => Promise.resolve(matchingProcesses));
12141213
}
12151214
}

0 commit comments

Comments
 (0)