DEV Community

Cover image for Debug Adapter Protocol
Aisuko
Aisuko

Posted on

Debug Adapter Protocol

I'd like to add the official document link first

https://microsoft.github.io/debug-adapter-protocol/

What's the debug adapter protocol?

DAP defines the abstract protocol used between a development tool(e.g IDE or editor) and a debugger.

DAP is to abstract the way how the debugging support of developing tools communicates with debuggers or runtimes into a protocol.

Because is unrealistic to assume that existing debuggers or runtimes adopt the protocol any time soon, so there may import
a component - Debug Adapter to adapts an existing debugger or runtime to the Debug Adapter Protocol.

Why there need DAP?

Because of VScode(and other IDE or editor) needs to support multiple languages and every one of them needs to develop the union functions, this makes a significant effort and can not be easily amortized over multiple development tools.

image

So, If we add DAP:

image

The diagram shows that the Debug Adapter Protocol makes it possible to implement a single generic debugger UI per development tool and that Debug Adapters can be re-used across these tools. This reduces the effort to support a new debugger considerably.

How can we use the adapter in Golang development:

  • We need to create the new launch configurations like below:
{
    "name": "Launch file",
    "type": "go",
    "request": "launch",
    "mode": "auto",
    "program": "${fileDirname}",
    "debugAdapter": "dlv-dap"
}
Enter fullscreen mode Exit fullscreen mode

To switch back to the legacy adapter, set "debugAdapter" to "legacy".

And use the function I mentioned in another blog https://dev.to/aisuko/debug-adapter-protocol-4ncg to run the test functions.

And you need to confirm from the console that your program already used the dlv-dap adapter like below:

image

The images of DAP architecture above all from https://microsoft.github.io/debug-adapter-protocol/overview

Top comments (2)

Collapse
 
altiano profile image
Altiano Gerung

question is, why use dlv-dap?

Collapse
 
aisuko profile image
Aisuko