-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Add debugging attach support to VS Code #6569
Comments
What we plan to do: We will extend the concept of system variables with a mechanism to trigger commands. {
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processName": "${action.PickProcess}"
} Starting a debug session with this launch config will run the 'PickProcess' command where the user can select a process. The result is a string that becomes the value of the variable. Cancelling the command will cancel the launch of the debug session. The implementation of the PickProcess command will live in the debugger extension and most likely is based on the QuickPick UI. But an extension is free to use whatever UI is available for an extension. The package.json of the debugger extension will contribute a mapping between the system variable (‘PickProcess’) and the command implemented by the extension, e.g. something like: "variables": {
"PickProcess": "extension.pickProcess"
} At a later point we can decide to provide a default picker action in VS Core and the debugger extensions are free to remove their implementations. /cc @isidorn @chrisdias |
Thanks Andre for the details on the proposal. I have a few questions: I don't think this is possible, but is there a way of passing arguments to the action being launched by VSCode? Something that would be useful might be to pass the
Do you have any other suggestions? I think option 2 is more user friendly. Some questions about the behavior of this feature:
|
@edumunoz here are my answers to the questions from above:
|
Thanks for the responses @weinand.
Yes, sorry for mixing both.
I assume this can be a |
@edumunoz, @Andrew-MSFT, @isidorn, @egamma Please note: I'm launching a simple express application from the command line without running node.js in debug mode. With the picker I select the node process by filtering on the arguments "bin/www". The variable ${action.pickProcess} in the launch config is then replaced by the process id of the node process. |
@weinand very cool, thanks for showing us. |
@edumunoz the picker code (from mock-debug) is here: https://github.com/Microsoft/vscode-mock-debug/blob/master/src/extension.ts |
I integrated what I was working on with your prototype and it works great. Let us know once the implementation makes it to master. |
The implementation is on master now. |
@edumunoz since node.js supports 'Attach to Process' too, I've added the full process picker flow to node-debug. This includes:
I've already modified the process picker in @gregg-miskelly, @roblourens, @daviwil, @rkeithhill, @felixfbecker, @rebornix, @MSLaguana, @lukehoban: this feature is useful if you want to add process, url, or port pickers to your launch configs. Here is a video. Please be aware that this is just a first cut and things might change until the end of this sprint. But we'd appreciate any feedback. |
@weinand does the extension that implements the process picker need to be the same extension that has the debug adapter, or can the two extensions be different? In one of our attach scenarios, we would need them to be different. |
@gregg-miskelly I did not yet verify it, but it is an explicit design goal that a process picker can live in a different extension than a debug adapter. So if it does not work, it would be a bug. |
@weinand Excellent. One other question: looking at the node implementation at least, it looks like this facility is pretty generic, and not necessarily specific to picking processes. For example, if we wanted, could we set the launch configuration program to be '${action.getCurrentCSharpOutputProgram}' which would run code in the C# extension to get the output path to the current project? Is or this mechanism really specific to attach to process. (NOTE: I am not sure if we would really want to do this. But I am curious if we could). |
@gregg-miskelly yes, your use-case is perfectly valid. The action-variable concept is basically a mechanism to call a function implemented in an extension (aka 'command') with the launch config as a parameter and return a string. So it does not have to involve any UI at all (and of course it is in no way specific for attaching to a process). (And because we are really running a 'command' and not necessarily a UI 'action' we are already discussing to rename the variables to '${command.xxxxx}'). |
This is great, I've wanted something like this. FYI @auchenberg. We could use this to pick tabs/targets to attach to. Can the debug adapter call those actions from its own code? It doesn't require a launch.json variable, right? |
@weinand I don't get why this requires a launch.json variable. Why can't the debug adapter simply ask VS Code to display a quick pick UI with some values and VS Code returns the user pick? |
The debug adapter is a separate black-box process and has no access to VS Code APIs. |
The debug protocol could easily introduce a request/event for this. |
This looks awesome so far! One question:
Does this mean the action syntax can be used in other variables aside from processId? Also, is |
@felixfbecker Assuming there is a way to do this from debug adapter code, this is better because the debug adapter can call arbitrary code using any of the normal Extension APIs. It's not just for quick pickers. Assuming I'm reading this right, if so, I think @weinand is underselling it :) |
@roblourens As I understand it the debug adapter is not calling anything, instead the user sets an action in launch.json and then VS Code asks the adapter to act on that. I would prefer if the adapter could trigger UI actions at own will. |
In a web context we would like the ability to populate the "target selector UI" with targets that isn't coming from a specific process. Think web apps running on a phone or HoloLens. Looking at the current format for a target, it's very specific to local processes such as Node:
I could easily imagine us wanting to add a icon next to the debug target for the favicons and another icon to show the device type. Can we expand the format, or is that what the Could we remove For the web we currently have two defacto formats: One to describe devices, and another for debug tagets. |
@felixfbecker I was thinking that the debug adapter was calling that action from its process, but actually that doesn't make sense, I guess I misunderstood. So yeah it would be nice to have support in the debug protocol for calling code that uses the vscode extension APIs. |
Some answers/clarification: As @MSLaguana correctly stated: a debug adapter is a separate black-box process that has no access to VS Code APIs (and has no UI on its own). Any debugger UI that uses the VS Code debugger protocol can use debug adapters. Opening up the debug adapter to all VS Code APIs would blur this clear separation of concerns and would make it hard to use debug adapters in a different context than VS Code. In addition if the debug adapter would be able to create its own UI, that would most likely clash with the generic VS Code debugger UI. @daviwil the "variables": {
"PickProcess": "extension.pickNodeProcess"
} @auchenberg every debug extension is free to implement whatever picker or other UI they need (as long as it uses the VS Code API). The ProcessPicker implemented for node.js is just an example or a starting point; it is not a shared component that should be used in other debug extensions. @auchenberg as mentioned earlier it will not be possible to directly call UI from the debug adapter. But it is possible to call UI from the debug extension. So if you want to present your pick UI independent from a launch config and its action variables, you can do so in the VS Code May release: |
@weinand When the quick pick UI appears and the user presses Esc to cancel the attach, our debug adapter is still getting passed the attach request. How can I prevent that in the code that returns the result of the quick pick UI? FWIW I also notice that the NET Core debugger doesn't handle this situation very well. The debug adapter gets called in this scenario and then errors with: |
@rkeithhill this sounds like a new issue and potentially a regression. Please try reproducing it with vscode insiders and if you still see it please file a new issue and ping me on that issue. Thanks! |
@weinand Thanks. |
VS Code should add platform level support that provides a structured way for debug adapters to implement and provide attach to process functionality that doesn't rely on updating the launch.json file every time the developer needs to attach to the process.
Key requirements are:
The text was updated successfully, but these errors were encountered: