-
Notifications
You must be signed in to change notification settings - Fork 159
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
customRequest 'processId' to get the debugging Java process id #399
customRequest 'processId' to get the debugging Java process id #399
Conversation
@@ -125,6 +126,7 @@ private void initialize() { | |||
registerHandlerForDebug(new SetDataBreakpointsRequestHandler()); | |||
registerHandlerForDebug(new InlineValuesRequestHandler()); | |||
registerHandlerForDebug(new RefreshVariablesHandler()); | |||
registerHandlerForDebug(new ProcessIdHandler()); | |||
|
|||
// NO_DEBUG mode only | |||
registerHandlerForNoDebug(new DisconnectRequestWithoutDebuggingHandler()); |
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.
When I debug Boot App via "Debug" action i get this back:
{"processId":0,"shellProcessId":78134}
which is great.
However, when i run the app via the "Run" action i get an error back:
Error: {"name":"Error","message":"custom request failed"}
Is it possible to make it work with "Run" action?
I thought the change for this would be instead of registerHandlerForDebug(...)
call registerHandler(...)
but this didn't work for me and i hope also because i messed up the build...
What do you think?
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.
yes, we can support it in "Run" as well.
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.
I have added 'processId' request in Run action as well.
If the Run action is running with internalConsole, it works fine.
However, if the Run action is triggered on terminal shell, it may not work. In this case, Java debugger will terminate the DAP debug session early once the RunInTerminal request is responded. You may not have opportunity to call custom request to get processId.
We have a TODO task to not terminate DAP session when triggering a Run with integratedTerminal, which requires more work and may not be done right away.
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.
LGTM.
@testforstephen Sorry for getting back to you only now... Was away from work and then had other projects to take care of.
Now, when i debug the app i get this printed:
However, when i run the app I get this:
Looks to me that this request is never even sent to DAP... Any idea what is going on here? |
Like I mentioned before, for Run action, the debug session only exists for a very short moment. Once the terminal is started, Java debugger will send a terminate event back to VS Code to exit debug session. That's why custom request is rejected for your case. |
Another idea is to make the debugger to send a custom event with the processId/shellProcessId as payload. This approach works both for Run/Debug. And the client can use the code like |
@testforstephen Just tried custom notifications. Think this would be ideal solution for me :-) |
4606552
to
05ba417
Compare
@BoykoAlex The latest commit will send a custom notification when processId/shellProcessId is ready. |
I have tried the latest version of this PR that includes the custom |
I don't know how do you test this, it's supposed to report the process info after the debug connection is setup. |
We're going to have a release this week. I plan to merge this PR first. If there is any further improvement needed, we can send another PR. |
@testforstephen Here is how i test it:
|
I can also repro the issue mentioned in #399 (comment) , with another lib But I think java-debug has no knowledge about when the real java process will be alive. |
Recently I'm also working on improving the processId mechanism in debugger side, so that it returns the correct Java process pid directly instead of the shellProcessId. On Windows, I found in some terminal environment, the started Java process is not a child process of the returned shell process.
On macOS, the started process is always a child of the target shell terminal. |
After some investigation, I found this is related with Cygwin emulator, which is a technology to run Linux GNU apps in Windows. When running Cygwin exe in Git Bash, it runs at an emulator layer and its process tree is not same as Windows process tree. However, each Cygwin process has a mapped Windows pid. Running ps command in Git 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. The new PR #413 includes the improvement to return the Java processId directly when running Java in terminal. |
request: 'processId'
response:
{
processId?: long; // The process id
shellProcessId?: long; // The process id of the terminal if the Java process is running in a terminal
}
Also the server sends a custom notification when processId/shellProcessId is ready.