ZigBrains icon indicating copy to clipboard operation
ZigBrains copied to clipboard

[WIP] Consider migrating to lsp4ij DAP

Open FalsePattern opened this issue 11 months ago • 24 comments

Once https://github.com/redhat-developer/lsp4ij/pull/735 is merged, investigate whether the current DAP debugger in zigbrains can be rewired to use the LSP4IJ one with feature parity.

Notes:

  • LSP4IJ DAP works outside of clion/rustrover/ideaultimate because it uses XDebugger instead of CIDR. This would allow debugging zig code with lldb-dap on ideacommunity and bypass the proprietary IDE restriction the current debugger impl has.
  • Memory disassembly view is only available in CIDR debugger API. Can it be hacked onto an XDebugger via reflection magic?
  • If the difference is too large, can we have best of both worlds and use lldb-dap on ic and the CIDR debugger on cl/rr/iu?

FalsePattern avatar Jan 16 '25 16:01 FalsePattern

Point 2 tl;dr: Can we make something like this work in the open source IDEs?

FalsePattern avatar Jan 16 '25 16:01 FalsePattern

Memory disassembly view is only available in CIDR debugger API. Can it be hacked onto an XDebugger via reflection magic?

I think we should copy/paste code from Memory view and adapt the code to console Memory DAP request / response.

https://github.com/JetBrains/intellij-community/blob/51454bce1c44da85d94e9cb092fbff974280232a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java#L315

angelozerr avatar Jan 20 '25 13:01 angelozerr

I meant the disassembler that clion exposes through the CIDR api for native debuggers, and coupling it with the disassemble DAP request. In zigbrains I just hardwired the DAP integration on top of the cidr debugger api so it just works, but lsp4ij compiles against the open source intellij apis so it's not available there. Image

FalsePattern avatar Jan 20 '25 19:01 FalsePattern

See: https://github.com/FalsePattern/ZigBrains/blob/3a5daab063bed81c0897378482a3fec9cbb14d41/cidr/src/main/kotlin/com/falsepattern/zigbrains/debugger/dap/DAPDriver.kt#L798-L839

FalsePattern avatar Jan 20 '25 19:01 FalsePattern

@FalsePattern I have discovered your issue and I am glad that you could be interested with dap support from LSP4IJ.

Even if it is not perfect and it requires a lot of work again, I merged the PR. You can install nigthy to play with it and you can read the doc at https://github.com/redhat-developer/lsp4ij/blob/main/docs%2Fdap%2FDAP.md

Dont hesitate to create any issues with your idea.

angelozerr avatar Jan 20 '25 19:01 angelozerr

At the moment zigbrains only has the builtin DAP support for debugging zig on windows (lldb cannot parse windows pdb files generated by zig so as a workaround i wrote a DAP adapter for using the msvc debugger), but i'm planning to use the lsp4ij DAP for debugging on idea community. The disassembler is not really required, i'm mostly just curious about how complex would it be to implement

FalsePattern avatar Jan 20 '25 19:01 FalsePattern

At the moment zigbrains only has the builtin DAP support for debugging zig on windows (lldb cannot parse windows pdb files generated by zig so as a workaround i wrote a DAP adapter for using the msvc debugger), but i'm planning to use the lsp4ij DAP for debugging on idea community. The disassembler is not really required, i'm mostly just curious about how complex would it be to implement

I dont know and I have never seen use it and dont know if the UI is complex.

First I suggest that you play with the LSP4IJ dap support because I am not sure that it works with stdio instead of socket.

I have tried to start lldp dap from swift in stdio but it fails. Only socket is working.

The runInTerminal is not implemented and I have seen that you have implemented it. I dont know if it can work without this runInTerminal.

Dont hesitate to create any issue.

For the moment dap server is not configurable with extension point so perhaps we need to provide it.

In short please dont be disappointed, it is just a basic dap support that it requires to improve it.

angelozerr avatar Jan 20 '25 19:01 angelozerr

@FalsePattern have you time to play with DAP support from LSP4IJ? Please try it with nighty build.

angelozerr avatar Feb 20 '25 10:02 angelozerr

I'm busy with university at the moment, I won't have a lot of free time until about June, so this issue is on hold for now.

FalsePattern avatar Feb 20 '25 14:02 FalsePattern

No problem, good luck with your university!

angelozerr avatar Feb 20 '25 19:02 angelozerr

@FalsePattern please note that 1.5.0 will improve dap support with runInTerminal which uses the intellij integrated terminal, api is also improved to use your own breakoint, configuration type.

angelozerr avatar Aug 09 '25 12:08 angelozerr

@FalsePattern again for your information I have implemented hover to show dap value with hover. I dont know if your current dap implementation does that.

angelozerr avatar Aug 14 '25 17:08 angelozerr

@FalsePattern again for your information I have implemented hover to show dap value with hover. I dont know if your current dap implementation does that.

My primary blockers for migrating to the lsp4ij dap is support for Disassemble/Memory operations, as my DAP implementation builds on top of com.jetbrains.cidr.execution.debugger.backend.DebuggerDriver

See: https://www.jetbrains.com/help/clion/disassembly-view.html

FalsePattern avatar Aug 22 '25 16:08 FalsePattern

Example: https://github.com/FalsePattern/ZigBrains/blob/3fb6077b4fe6b64656f12ccfff4b1fe0307b4c0a/cidr/src/main/kotlin/com/falsepattern/zigbrains/debugger/dap/DAPDriver.kt#L854

FalsePattern avatar Aug 22 '25 16:08 FalsePattern

Example: https://github.com/FalsePattern/ZigBrains/blob/3fb6077b4fe6b64656f12ccfff4b1fe0307b4c0a/cidr/src/main/kotlin/com/falsepattern/zigbrains/debugger/dap/DAPDriver.kt#L854

I understand but my main problem is that I dont know how it is working. Could you please explain me with several screnshot.

I dont know zig, could you explain me how to consume zig debugger and have a basic zig app to debug in order to I have a usecase

angelozerr avatar Aug 22 '25 16:08 angelozerr

This DAP communicates with the MSVC debugger adapter (used for debugging zig on Windows due to an LLDB/GDB compatibility issue in the generated .pdb files), it's not zig-specific

FalsePattern avatar Aug 22 '25 17:08 FalsePattern

See: https://github.com/microsoft/vscode-cpptools

FalsePattern avatar Aug 22 '25 17:08 FalsePattern

As a cross-platform reference, LLDB-DAP uses the same requests/responses

https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/README.md

FalsePattern avatar Aug 22 '25 17:08 FalsePattern

As a cross-platform reference, LLDB-DAP uses the same requests/responses

https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/README.md

Thanks for your info. I need to understand what is disassembly.

If you have some tutorial which uses vscode cpptools with disassembly in order too I see the ui to implement it would be very nice.

Same thing for IJ. I have no idea which UI must be implemented and how dap disassembly works.

angelozerr avatar Aug 22 '25 17:08 angelozerr

The disassembly UI in clion is implemented in proprietary jetbrains code, so unfortunately i cannot provide a example code of the UI for that. The best reference i can give is this documentation page: https://www.jetbrains.com/help/clion/disassembly-view.html and this demo https://www.youtube.com/watch?v=cjJDpRArf_w

FalsePattern avatar Aug 22 '25 17:08 FalsePattern

Thanks @FalsePattern for your relevant information.

I have started to try to implement this DAP Disassembly support. It was not trivial but I can add an Open Disassembly view with contextual menu on a stack trace and open an editor with a disassembly content:

Image

And as Disassembly is a text editor (readonly), I can add Disassembly breakpoint type

Image

For now, that's it, I need to send disassembly breakpoint to DAP server. I don't know if it will be easy. We will see..

angelozerr avatar Aug 29 '25 15:08 angelozerr

Current status

Image

angelozerr avatar Sep 02 '25 19:09 angelozerr

@FalsePattern I have merged my PR with DAP Disassembly support, see doc at https://github.com/redhat-developer/lsp4ij/blob/main/docs/dap/UserGuide.md#disassemble

You will have to install https://github.com/redhat-developer/lsp4ij?tab=readme-ov-file#testing-nightly-builds

It is not perfect and I think it will require some improvement, but it starts working.

Don't hesitate to contribute to LSP4IJ if you need some improvement. Thanks!

angelozerr avatar Sep 05 '25 13:09 angelozerr

@FalsePattern just for your info, I am improving syntax coloration for Disassembly https://github.com/redhat-developer/lsp4ij/pull/1328

image image

angelozerr avatar Oct 12 '25 16:10 angelozerr