emacs-lsp / dap-mode

Emacs :heart: Debug Adapter Protocol
https://emacs-lsp.github.io/dap-mode
GNU General Public License v3.0
1.3k stars 182 forks source link

Hang while debugging Java #674

Open goldfita opened 2 years ago

goldfita commented 2 years ago

I caught a hang in WinDbg while attempting to add expression in Java. I saved a few pages of disassembly from ntdll, which I can post, or I could just post the list of functions. Perhaps if there is some debug output I could enable or a pdb file, I could provide more useful debug materials. Please let me know how I can help.

ntdll!FirstEntrySList
ntdll!ExpInterlockedPopEntrySList
ntdll!ExpInterlockedPopEntrySListResume
ntdll!ExpInterlockedPopEntrySListFault
ntdll!ExpInterlockedPopEntrySListEnd
ntdll!ExpInterlockedPushEntrySList
ntdll!ExpInterlockedFlushSList
ntdll!InterlockedPushListSList
ntdll!KiUserApcHandler
ntdll!KiUserCallForwarder
ntdll!KiUserApcDispatch
ntdll!KiUserCallbackDispatcherHandler
goldfita commented 2 years ago

I caught another one while stepping into a function, again with some disassembly. This time I saw some messages in the echo area before it went down. Something about end of buffer, and then

Error running timer 'dap-ui-locals--refresh': (error "Variable binding depth exceeds max-specpdl-size")

I should mention that the file workspace/.cache/com.fasterxml.jackson.databind.ObjectMapper.java that I tried to step into shows windows line endings. Only some of the files in this directory show them. It's probably not relevant, but I'm mentioning it to be complete.

ntdll!KiUserCallbackDispatcherHandle
ntdll!KiUserCallbackDispatch
ntdll!KiUserCallbackDispatcherContinue
ntdll!KiUserExceptionDispatch
ntdll!KiRaiseUserExceptionDispatcher
goldfita commented 2 years ago

I've updated the previous comments with some of the surrounding assembly symbols at the point where it's hanging. Some of it may be debug interrupt code. I don't know what I'm looking at.

Now, I've caught another one while expanding a large array in sessions.

ntdll!FirstEntrySList
ntdll!ExpInterlockedPopEntrySList
ntdll!ExpInterlockedPopEntrySListResume
ntdll!ExpInterlockedPopEntrySListFault
ntdll!ExpInterlockedPopEntrySListEnd
ntdll!ExpInterlockedPushEntrySList
ntdll!KiUserApcHandler
ntdll!KiUserCallForwarder
ntdll!KiUserApcDispatch

This time I printed some information in dap--send-message. I thought this might be where it was hanging, but it looks like the operation completed; however, it may be possible that it hanged before the file was closed. The following is the last message that made it to file before Emacs locked-up. I also captured earlier messages, as well as the session. I can't provide the entire session due to there being proprietary information in it. But if you need something specific, I can dig around for it.

(:command variables :arguments (:variablesReference 1744) :type request :seq 433) End process-send-string

goldfita commented 2 years ago

I updated to the latest dap-mode, lsp, and lsp-ui on melpa. Then I also grabbed the latest treemacs, treemacs-lsp, and treemacs-projectile to try and get everything back in sync. But now breakpoints are not being hit at all. Also I'm getting a message when expanding the session tree

error in process filter: Wrong type argument: listp, lsp-treemacs-generic-root

I will probably need to set this aside until it matures further. I'm willing to help out by putting debug or message statements in the code if you want to see how it works on my system. I know windows is a low priority, though.

goldfita commented 1 year ago

I thought I might have a package incompatibility or incompatibility with the old workspace. So I blew everything away and started fresh with all packages from melpa. But now I am getting the following error.

lsp-workspace-command-execute: ‘workspace/executeCommand’ with ‘vscode.java.startDebugSession’ failed.
(error "No delegateCommandHandler for vscode.java.startDebugSession")

When I run lsp-describe-session, I don't see 'workspace/executeCommand' or any commands that start with 'vscode'.

       |-[-] workspace:
       |  `-[-] workspaceFolders:
       |     |-[X] changeNotifications: t
       |     `-[X] supported: t
       |-[-] executeCommandProvider:
       |  `-[X] commands: [java.edit.organizeImports java.project.refreshDiagnostics java.project.import java.navigate.openTypeHierarchy java.project.removeFromSourcePath java.project.listSourcePaths java.project.resolveStackTraceLocation java.project.getAll java.project.isTestFile java.project.getClasspaths java.navigate.resolveTypeHierarchy java.edit.stringFormatting java.project.getSettings java.project.updateSourceAttachment java.project.resolveWorkspaceSymbol java.project.upgradeGradle java.project.resolveSourceAttachment java.project.addToSourcePath]

I tried this initially with Eclipse JDT LS 1.16. Then I noticed that lsp-java-jdt-download-url is set to 1.12, so I tried with 1.12 but had the same issue.

goldfita commented 1 year ago

I finally realized that the snapshot version from the eclipse site and the version lsp-java downloads are not the same even though the version number is the same and they have the same jar in the features directory. So the last comment has been resolved. But I am back to break points not working. It appears at least one issue is related to treemacs. I see the following when I attempt to expand the session.

Error processing message (wrong-type-argument integer-or-marker-p nil). error in process filter: Invalid function: lsp-treemacs-wcb-unless-killed [2 times] error in process filter: treemacs-find-node: Wrong type argument: listp, lsp-treemacs-generic-root error in process filter: Wrong type argument: listp, lsp-treemacs-generic-root

And the stack trace is:

Debugger entered--Lisp error: (wrong-type-argument listp lsp-treemacs-generic-root)
  treemacs--find-custom-node((lsp-treemacs-generic-root "remote"))
  treemacs-find-node((lsp-treemacs-generic-root "remote"))
  treemacs--async-update-part-complete((lsp-treemacs-generic-root "remote") (lsp-treemacs-generic-root "remote") (... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  #f(compiled-function (items) #<bytecode 0x36e5308163c9d2d>)((... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  #f(compiled-function (result) #<bytecode 0x153e3805978429fa>)((... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  #f(compiled-function (input0) #<bytecode 0x9d6c8696be2334d>)(#<hash-table equal 6/65 0x900334232d>)
  #f(compiled-function (m) #<bytecode 0x716d60e5e7d944d>)("{\"success\":true,\"request_seq\":62,\"command\":\"thread...")
  mapc(#f(compiled-function (m) #<bytecode 0x716d60e5e7d944d>) ("{\"success\":true,\"request_seq\":62,\"command\":\"thread..."))
  #f(compiled-function (_ msg) #<bytecode -0xfa50e355ec8e79>)(#<process remote> "Content-Length: 8083\15\n\15\n{\"success\":true,\"request_s...")

Now when I attempt to open the breakpoint window, it goes into an infinite loop between connecting to LSP and disconnecting from LSP, at which point I have to close emacs or kill it.

Versions:

dap-mode-20221118.1707 lsp-java-20220825.450 lsp-mode-20221118.815 treemacs-20221107.2105

yyoncho commented 1 year ago

delete packages/restart emacs/install packages.

goldfita commented 1 year ago

I've done that twice now. I've also gotten into the habit into wiping out workspace and lspsession files. I will try again when the packages update and report back in a few weeks. Thanks.

yyoncho commented 1 year ago

That issue was reported multiple times and it goes away after restart. It is caused by package.el inefficiency when updating.

goldfita commented 1 year ago

OK good to know. I will try again soon.

goldfita commented 1 year ago

I blew everything away and tried once more. Still the same problem. Is there a workaround for package.el?

yyoncho commented 1 year ago

@goldfita does it happen when you do M-x lsp-start-plain?

goldfita commented 1 year ago

Yes, same thing. Also, it opens another frame with the error:

Debugger entered--Lisp error: (file-error "https://elpa.gnu.org/packages/spinner-1.7.4.tar" "No Data")
  signal(file-error ("https://elpa.gnu.org/packages/spinner-1.7.4.tar" "No Data"))

Spinner appears to be installed. Also, I should mention, I'm on Emacs 28.2 now, Win11.

goldfita commented 1 year ago

I saw there was a new lsp-java on melpa, so I took another stab at this. Still the same issue. I also seem to have a new issue now. When I open the "Errors List" window, it gets stuck in a loop connecting/disconnecting to the LSP server.

goldfita commented 1 year ago

@yyoncho I finally found a workaround for the missing lsp-treemacs-wcb-unless-killed symbol. I searched for every occurrence and manually recompiled each file where it appeared. There were two in lsp-treemacs and one in lsp-ui. Is it possible that lsp-ui needs to install after lsp-treemacs? This behavior is stable. No matter how many times I re-install, it's the same error.

The problem with it connecting and disconnecting from the server in an infinite loop was caused by the .project file. I had been creating an empty one to make things work. In one of the recent releases, this file started getting generated. This was causing the server to complain, I guess because there was already one there. Once the server raises an exception, lsp disconnects. Then somehow this is causing one of my hooks to run, which again starts lsp and then immediately disconnects.

I briefly tried to run a unit test and hit a breakpoint. The unit test had been working, but now I get some lsp-treemacs error. I was able to hit a breakpoint using dap, but it's raising an exception on the server. When I have more time to look at it, I will comment here with details.

yyoncho commented 1 year ago

That error is caused by elpa being down. M-x lsp-start-plain will start clean emacs and it will install packages. The issue you have is that you install the packages in-memory. You should do that by deleting the package, restaring emacs and isntalling them. This is package.el limitation.

trev-dev commented 1 year ago

@yyoncho which package manager would you recommend if package.el is the problem? I'd rather not have to diddle my .emacs.d, I do too much of that already.