Skip to content
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

Capture Java process pid and display debug toolbar when running Java in terminal #413

Merged
merged 4 commits into from
May 24, 2022

Conversation

testforstephen
Copy link
Contributor

@testforstephen testforstephen commented May 22, 2022

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
    image

Copy link
Member

@Eskibear Eskibear left a comment

Choose a reason for hiding this comment

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

LGTM

@testforstephen testforstephen merged commit e3cf474 into microsoft:main May 24, 2022
@testforstephen testforstephen deleted the jinbo_run branch May 24, 2022 06:41
@testforstephen
Copy link
Contributor Author

With this PR, there are two ways to get the running Java process pid.

  • Custom DAP request processId.
  • processid notification.

And the response/event body will contain

{
 shellProcessId: number  /* The process ID of the terminal shell if the process is running in a terminal shell.  */
 processId: number /* The process ID. */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide "Stop Java" button when triggering "Run Java" action.
2 participants