Repository: vscode
Issue: DAP - Terminate Request is not sent for "Attach" Configurations
Labels: bug,debug

### Details

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
**Does this issue occur when all extensions are disabled?:** N/A

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- **VS Code Version:** 1.64.2
- **OS Version:** macOS 12.2.1

### Steps to Reproduce

1. Initialize a Debug Session with `supportsTerminateRequest`.
2. Create an "attach" configuration.
3. Start a debug session using the "attach" configuration.
4. Press Alt/Option to show the "Stop" button in the Debugger UI.
5. Click the "Stop" button.

### Expectation

If I implement a Debug Adapter that supports the Terminate Request so that I can handle the two-phase "Graceful Termination", then I expect that functionality to work in both "Launch" and "Attach" configurations. If the user presses the "Stop" button, then this internally indicates "terminate debuggee". This is indicated by the fact that the `terminateDebuggee` Disconnect Request argument is `true` (if support is enabled) when the user presses the "Stop" button. This applies to both "Attach" and "Launch" configurations.

### Reality

The Terminate Request is never called for Debug Sessions started with "Attach" configurations, even when the user clicks the "Stop" button to trigger termination.

The DAP specification does not suggest that the [Terminate Request](https://microsoft.github.io/debug-adapter-protocol/specification#leftwards_arrow_with_hook-terminate-request) is limited to work only with "Launch" configurations.

### History

The following appear to be related:

- #54384
- #54420
- #116731

It appears that this "rule" was implemented _before_ the Alt/Option feature that allows users to switch between Disconnect/Stop buttons in the UI. When this new feature was under discussion, @weinand [wrote the following](https://github.com/microsoft/vscode/issues/116731#issuecomment-815880492):

> The `terminate` request can be used to trigger a "soft" termination of a debuggee, which the debuggee can intercept to do some cleanup work. While doing this the debuggee can still be debugged and the debuggee can even decide to ignore the terminate and continue execution.

My expectation as a Debug Adapter implementer is that if I support the Terminate Request, then whenever the user initiates termination (e.g. via the Stop button, regardless of how the Debug Session was started) I should receive the Terminate Request. [The check for whether to call Terminate Request](https://github.com/microsoft/vscode/blob/188b1a51fe48a225c2a977e2b32c472b46845d36/src/vs/workbench/contrib/debug/browser/debugSession.ts#L338) should no longer check for "Launch" vs "Attach" but, rather, "Terminate" vs "Disconnect".

Perhaps this was simply an oversight during the initial implementation as @isidorn [wrote the following](https://github.com/microsoft/vscode/issues/116731#issuecomment-815751370):

> However if the debug adapter has a `supportsTerminateRequest` then all `stop` actions will actually call the `terminate` as they do today

Which is true, they do - at least the ones that _existed_ prior to this change. The newly added `stop` action (Alt/Option to enable Stop with "Attach" Debug Sessions) appears to have slipped through the cracks as it is **not** currently included in the "all `stop` actions".