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

Dape compatibility #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

iNecas
Copy link

@iNecas iNecas commented Nov 8, 2024

When trying to get DebugAdapter running with https://github.com/svaante/dape, I came across some issues and capabilities I needed to support it fully, both with launch and attach requests.

With https://github.com/svaante/dape, I run into issues in termination
phase when connected via `attach` request. When I looked at
implementations of DAP in other languages (llvm), they report
`supportsTerminateRequest` as false, so that the DAP client doesn't try
to send the termination request, that currently seems to have an
undefined behavior when attached.

After this change, I'm able to run the following code to start
the server I can attach to from dape:

```
session = DebugAdapter.DebugSession(conn)
session.capabilities.supportsTerminateRequest = false
DebugAdapter.run(session)
```
In DAP protocol, the arguments key is optional. With dape, I run
into issues when in this case, the DebugAdapter has failed with:

```
ERROR: KeyError: key "arguments" not found
Stacktrace:
 [1] getindex
   @ ./dict.jl:498 [inlined]
 [2] dispatch_msg(x::DebugAdapter.DAPRPC.DAPEndpoint{Sockets.TCPSocket, Sockets.TCPSocket}, dispatcher::DebugAdapter.DAPRPC.MsgDispatcher, msg::Dict{String, Any})
   @ DebugAdapter.DAPRPC ~/active/projects/julia/DebugAdapter.jl/src/DAPRPC/typed.jl:86
 [3] (::DebugAdapter.var"#132#161"{Dict{String, Any}, Nothing, DebugAdapter.DAPRPC.MsgDispatcher, DebugAdapter.DAPRPC.DAPEndpoint{Sockets.TCPSocket, Sockets.TCPSocket}})()
   @ DebugAdapter ~/active/projects/julia/DebugAdapter.jl/src/packagedef.jl:134
```

Also, for optional fields, the dape client sometimes sends null values instead of omitting the key.

Making the code a big more defensive sounds like good idea and if fixes
the issue for me.
iNecas added a commit to iNecas/julia-snail that referenced this pull request Nov 8, 2024
Use DebugAdapter.jl + dape to provide debugging capabilities from repl.

Requires julia-vscode/DebugAdapter.jl#95 to
be merged first.
@davidanthoff
Copy link
Member

I tried to understand what this would fix, but I'm not succeeding :) I think the idea here is that we don't handle some message correctly that could contain a null value? Which one? My sense is that the DAP only allows null in very few cases that we actually don't support in the first place? I think I just need to get a bit more context to understand this PR.

@iNecas
Copy link
Author

iNecas commented Nov 18, 2024

A sepecific case that I've hit was originated here https://github.com/svaante/dape/blob/master/dape.el#L2418 (but there are other similar cases). I first meant to send a PR to dape to use boolean instead, but then, when looking at the specification https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disconnect, there is a difference between false value and null/missing key (letting the implementation to make a choice). Given dape works fine with other DAP implementations, making the code here a bit more resilient looked like a better approach.

@davidanthoff
Copy link
Member

I don't think sending null as the value is spec conformant, though? The spec conformant way is to just not include the terminateDebuggee element in the JSON, and I think that is already supported on our end?

@iNecas
Copy link
Author

iNecas commented Nov 19, 2024

You are right. Not TypeScripter myself, but given the DAP protocol is defined via TS, it seems it doesn't like null values (based on some short experiement).

image

I will need to send a PR to dape to fix that.

Note the issue with null values is just one change needed. The other two were:

  1. allow to customize the Capabilities when initiating the server
  2. handle missing arguments (this is different than the null values issues above, as in this case, the arguments are really omitted and there are quite a couple of arguments? places in the DAP spec

Would the other changes be acceptable, any changes suggested there?

@davidanthoff
Copy link
Member

allow to customize the Capabilities when initiating the server

Can you explain a bit more why that would be useful? In my mind the list of supported features is kind of hard coded simply by the choice of what features we implement?

handle missing arguments (this is different than the null values issues above, as in this case, the arguments are really omitted and there are quite a couple of arguments? places in the DAP spec

So, I think technically that is already supported, albeit in a bit of an inconsistent way.

const configuration_done_request_type = DAPRPC.RequestType("configurationDone", Union{ConfigurationDoneArguments,Nothing}, ConfigurationDoneResponseArguments)
is an example, i.e. the way to do that is to use a Union{T,Nothing}. Having said that, I guess it would actually be more consistent to use Missing instead there, as we have used that throughout for the ? TypeScript case.

@iNecas
Copy link
Author

iNecas commented Nov 20, 2024

Can you explain a bit more why that would be useful? In my mind the list of supported features is kind of hard coded simply by the choice of what features we implement?

The particular case I've hit was at the end of attach request session. Dape looks at the capabilities to determine, whether to send the terminateRequest https://github.com/svaante/dape/blob/master/dape.el#L2390. It however doesn't seem to make sense in the attach case and that's what I observed in lldb dap implementation was they report supportsTerminateRequest to be false in this case.

Thanks for the pointers about the alternative way of handling the missing arguments, I will try looking at leveraging that approach.

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.

2 participants