-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Support program parameter in attach configurations (#14046) #14108
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
base: main
Are you sure you want to change the base?
feat: Support program parameter in attach configurations (#14046) #14108
Conversation
|
@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'. |
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
|
@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. |
|
@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. |
sean-mcmanus
left a comment
There was a problem hiding this 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?
|
@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. |
|
@sean-mcmanus I have thoroughly reverted all unrelated Code Samples changes by syncing with upstream/main and removed the MIEngine_Debug subproject. |
|
@Subham-KRLX I've started reviewing this. I think I can finish tomorrow. |
Extension/package.nls.json
Outdated
| "{Locked=\"`program`\"} {Locked=\"`processId`\"}" | ||
| ] | ||
| }, | ||
| "c_cpp.debuggers.symbolSearchPath.description": "Semicolon separated list of directories to use to search for .so files. Example: \"c:\\dir1;c:\\dir2\".", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows with MSVC it uses .pdb files and not so files, so the description could be something like search for symbols (that is, pdb or .so files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4046187 - Updated to "search for symbol (that is, pdb or .so) files"
Extension/package.nls.json
Outdated
| }, | ||
| "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.", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
Extension/package.nls.json
Outdated
| }, | ||
| "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.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path to program executable should be path to the program executable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to "path to the program executable"
| const remoteAttachPicker: RemoteAttachPicker = new RemoteAttachPicker(); | ||
| processId = await remoteAttachPicker.ShowAttachEntries(config); | ||
|
|
||
| // If program is specified, try to find matching process by name |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 attachItemsProvider: AttachItemsProvider = NativeAttachItemsProviderFactory.Get(); | ||
| const attacher: AttachPicker = new AttachPicker(attachItemsProvider); | ||
| processId = await attacher.ShowAttachEntries(token); | ||
| // Show process picker if no program specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show process picker if no program specified->Show the process picker if no program is specified.
|
|
||
| // Find processes matching the program name | ||
| const matchingProcesses: AttachItem[] = processes.filter(p => { | ||
| const processName: string = p.label.toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The toLowerCase should only be used on Windows where the paths are case insensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case-insensitive matching is now restricted to Windows only using the isWindows check.
| // Find processes matching the program name | ||
| const matchingProcesses: AttachItem[] = processes.filter(p => { | ||
| const processName: string = p.label.toLowerCase(); | ||
| const targetName: string = programBaseName.toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved out of the lambda and into a local variable at the out scope to avoid unnecessarily calling it more than once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you could use something like
if (isWindows) {
targetName = targetName.endsWith(".exe") ? targetName : (targetName + ".exe");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targetName computation moved outside the filter lambda with .exe suffix logic for Windows included.
| 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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
| return undefined; | ||
| } else if (matchingProcesses.length === 1) { | ||
| void logger.getOutputChannelLogger().appendLine( | ||
| `Found process "${matchingProcesses[0].label}" with PID ${matchingProcesses[0].id}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to log here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sean-mcmanus I have addressed all review items in commit 4046187. This update restricts case-insensitivity to Windows, adds path validation, ensures exact process matching, and implements a silent fallback to the process picker. I have also removed all internal logging and corrected the documentation strings in
package.nls.json.
- 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
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.