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

[WIP] Consider migrating to lsp4ij DAP #93

Open
FalsePattern opened this issue Jan 16, 2025 · 10 comments
Open

[WIP] Consider migrating to lsp4ij DAP #93

FalsePattern opened this issue Jan 16, 2025 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@FalsePattern
Copy link
Owner

FalsePattern commented Jan 16, 2025

Once redhat-developer/lsp4ij#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 FalsePattern added the enhancement New feature or request label Jan 16, 2025
@FalsePattern FalsePattern self-assigned this Jan 16, 2025
@FalsePattern
Copy link
Owner Author

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

@angelozerr
Copy link

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

@FalsePattern
Copy link
Owner Author

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
Copy link
Owner Author

FalsePattern commented Jan 20, 2025

See:

private suspend fun disassembleSuspend(range: AddressRange): List<LLInstruction> {
if (!capabilities.supportsDisassembleRequest)
throw DebuggerCommandException("disassemble is not supported by debugger!")
val args = DisassembleArguments()
args.memoryReference = java.lang.Long.toHexString(range.start.unsignedLongValue)
args.instructionCount = Math.toIntExact(range.size)
args.resolveSymbols = true
val disassembly = server.disassemble(args).getSuspend()
val dapInstructions = disassembly.instructions
val jbInstructions = ArrayList<LLInstruction>(dapInstructions.size)
var loc: Source? = null
var startLine: Int? = null
var endLine: Int? = null
var symbol: String? = null
var baseOffset = 0L
for (dapInstruction in dapInstructions) {
val dapLoc = dapInstruction.location
val dapStartLine = dapInstruction.line
val dapEndLine = dapInstruction.endLine
val dapSymbol = dapInstruction.symbol
val dapAddr = Util.parseAddress(dapInstruction.address)
var uniq = true
if (dapLoc != null) {
loc = dapLoc
} else if (startLine != null && dapStartLine == startLine && endLine != null && dapEndLine == endLine) {
uniq = false
} else {
startLine = dapStartLine
endLine = dapEndLine
}
if (dapSymbol != null && dapSymbol != symbol) {
symbol = dapSymbol
baseOffset = dapAddr
}
val llSymbol = symbol?.let {LLSymbolOffset(symbol, dapAddr - baseOffset)}
jbInstructions.add(Util.instructionJBFromDAP(dapInstruction, loc, startLine, endLine, uniq, llSymbol))
}
return jbInstructions
}

@angelozerr
Copy link

@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.

@FalsePattern
Copy link
Owner Author

FalsePattern commented Jan 20, 2025

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

@angelozerr
Copy link

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
Copy link

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

@FalsePattern
Copy link
Owner Author

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.

@angelozerr
Copy link

No problem, good luck with your university!

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

No branches or pull requests

2 participants