Capture Java process pid and display debug toolbar when running Java in terminal #413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It does two things in this PR:
Capture the Java process pid when running Java in a terminal shell.
This is a follow-up of customRequest 'processId' to get the debugging Java process id #399. Both the SpringBoot Dashboard and Spring Tools extension have the requirement to get the running Java pid from Java debugger, so it makes sense to support it in Java debugger directly for reuse.
Since the DAP just returns the shell process pid when running Java in a terminal shell, the debugger have to find the running Java process based on the shell pid. In the standard shell environment such as PowerShell, cmd, Linux/macOS shells, the shell process is parent of Java process, it's easy to find Java subprocess from process tree. But this approach fails when using Git Bash as the default terminal, because the launched Java process is no longer a descendant process of the shell process.
Git bash is based on MSYS2 platform, which is a fork of Cygwin technology. When running Cygwin exe in Windows, it runs at an emulator layer. So its process tree is not same as Windows process tree. Each Cygwin process has a mapped Windows pid. Running ps command in bash can list the cygwin's pid, cygwin's ppid and its winpid. Based on ps command, it's possible to find the running Java process and its parent Git bash process.
Display the debug toolbar when using "Run Java" action to run Java in terminal without debugging.

Keep the debug session alive until the Java process exits. This fixes Provide "Stop Java" button when triggering "Run Java" action. vscode-java-debug#1166