Skip to content

feat: Support program parameter in attach configurations (#14046)#14108

Open
Subham-KRLX wants to merge 12 commits intomicrosoft:mainfrom
Subham-KRLX:feature/attach-by-program-name
Open

feat: Support program parameter in attach configurations (#14046)#14108
Subham-KRLX wants to merge 12 commits intomicrosoft:mainfrom
Subham-KRLX:feature/attach-by-program-name

Conversation

@Subham-KRLX
Copy link

Fixes #14046

Add support for program parameter in attach configurations to attach to processes by executable name, similar to LLDB extension.

Example:

json
{
"type": "cppvsdbg",
"request": "attach",
"program": "myprogram.exe"
}
Automatically finds matching process, prompts if multiple matches. Backward compatible with existing processId configurations.

@Subham-KRLX Subham-KRLX requested a review from a team as a code owner December 14, 2025 07:25
@github-project-automation github-project-automation bot moved this to Pull Request in cpptools Dec 14, 2025
@sean-mcmanus
Copy link
Contributor

@Subham-KRLX It looks like there are compile errors: src/Debugger/configurationProvider.ts(361,40): error TS2339: Property 'findProcessByProgramName' does not exist on type 'DebugConfigurationProvider'.
src/Debugger/configurationProvider.ts(1340,19): error TS6133: 'findProcessByProgramName' is declared but its value is never read.

Subham-KRLX and others added 2 commits December 19, 2025 11:52
Move the findProcessByProgramName private method from ConfigurationSnippetProvider
class to DebugConfigurationProvider class where it belongs and is called.

This fixes:
- TS2339: Property 'findProcessByProgramName' does not exist on type 'DebugConfigurationProvider'
- TS6133: 'findProcessByProgramName' is declared but its value is never read
@Subham-KRLX
Copy link
Author

@sean-mcmanus We've resolved both compilation errors by moving the findProcessByProgramName method to the correct location inside the DebugConfigurationProvider class. The fix has been committed and pushed to the feature/attach-by-program-name branch. The TypeScript compilation errors are now resolved.

@Som1Lse
Copy link

Som1Lse commented Jan 26, 2026

@sean-mcmanus I just want to add that I am also really interested in this feature.

It seems to have been sitting for over a month waiting for a review, so I'm bumping this in case people forgot.

Copy link
Contributor

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

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

Why are there Code Sample changes? Can you remove those? Aren't those changes in a separate PR already?

Why is there an MIEngine_Debug subproject added? Can that be removed?

@Subham-KRLX
Copy link
Author

@sean-mcmanus I have cleaned up the PR by reverting the unrelated Code Samples changes and removing the MIEngine_Debug subproject. The PR now only contains the relevant changes for supporting the program parameter in attach configurations.

@sean-mcmanus
Copy link
Contributor

@sean-mcmanus I have cleaned up the PR by reverting the unrelated Code Samples changes and removing the MIEngine_Debug subproject. The PR now only contains the relevant changes for supporting the program parameter in attach configurations.

@Subham-KRLX I still see the Code Sample changes, not reverted.

@Subham-KRLX
Copy link
Author

@sean-mcmanus I have thoroughly reverted all unrelated Code Samples changes by syncing with upstream/main and removed the MIEngine_Debug subproject.

@sean-mcmanus sean-mcmanus added this to the 1.31.0 milestone Jan 30, 2026
@sean-mcmanus
Copy link
Contributor

@Subham-KRLX I've started reviewing this. I think I can finish tomorrow.

},
"c_cpp.debuggers.symbolSearchPath.description": "Semicolon separated list of directories to use to search for symbol (that is, pdb) files. Example: \"c:\\dir1;c:\\dir2\".",
"c_cpp.debuggers.program.attach.markdownDescription": {
"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.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should executable name be executable path?

Copy link
Author

Choose a reason for hiding this comment

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

Changed "executable name" to "executable path"

const remoteAttachPicker: RemoteAttachPicker = new RemoteAttachPicker();
processId = await remoteAttachPicker.ShowAttachEntries(config);

// If program is specified, try to find matching process by name
Copy link
Contributor

Choose a reason for hiding this comment

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

matching process by name->the matching process by name.

Copy link
Author

Choose a reason for hiding this comment

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

Updated comment to "try to find the matching process by name"

const processName: string = p.label.toLowerCase();
const targetName: string = programBaseName.toLowerCase();
// Match if the process name exactly matches or starts with the target name
return processName === targetName || processName.startsWith(targetName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this startsWith to prevent the an unintended process from being accidentally attached to?

return matchingProcesses[0].id;
} else {
// Multiple matches - let user choose
void logger.getOutputChannelLogger().appendLine(
Copy link
Contributor

Choose a reason for hiding this comment

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

This logging is unnecessary -- users will see the quick pick UI and not see the logging.

@sean-mcmanus sean-mcmanus requested a review from Colengms January 31, 2026 01:07
- 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
@sean-mcmanus sean-mcmanus self-requested a review February 5, 2026 02:50
@sean-mcmanus
Copy link
Contributor

Sorry, I've been busy with other stuff. I'll try to get to this tomorrow.


// Fall back to process picker if program wasn't specified or didn't match
if (!processId) {
// Show the process picker if no program is specified
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should be removed. The comment on line 364 appears to replace it.

"required": [
"program"
],
"required": [],
Copy link
Contributor

Choose a reason for hiding this comment

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

I am seeing "program" being required for GDB debugging.

Image

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put it back as a requirement or why should it be removed as a requirement? I think it can stay as a required field.

Copy link
Author

Choose a reason for hiding this comment

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

The "required": [] is correct both program and processId are optional. Users can specify either or neither (falls back to process picker). The implementation in configurationProvider.ts(lines 356-382) handles all cases.

Copy link
Contributor

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

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

Also, there are some linter errors: Trailing spaces not allowed

Per Sean's feedback, check for remote attach scenarios before calling
findProcessByProgramName to avoid unnecessary function calls and
potential errors for remote attach users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

Support "program" for {"request": "attach"} instead of only "processId"

3 participants