GNU Debugger "GDB" Adds Support For Microsoft's Debug Adapter Protocol

Written by Michael Larabel in GNU on 2 January 2023 at 02:45 PM EST. 7 Comments
GNU
Merged today to the GNU Debugger (GDB) is initial support for the Debug Adapter Protocol (DAP) that is a JSON-RPC interface for use by integrated development environments (IDEs) to better communicate with debuggers.

The Debug Adapter Protocol (DAP) is defined by Microsoft as an abstract protocol between IDEs and debuggers. As explained on the protocol's GitHub page:
"The idea behind the Debug Adapter Protocol (DAP) is to abstract the way how the debugging support of development tools communicates with debuggers or runtimes into a protocol. Since it is unrealistic to assume that existing debuggers or runtimes adopt this protocol any time soon, we rather assume that an intermediary component - a so called Debug Adapter - adapts an existing debugger or runtime to the Debug Adapter Protocol.

The Debug Adapter Protocol makes it possible to implement a generic debugger for a development tool that can communicate with different debuggers via Debug Adapters. And Debug Adapters can be re-used across multiple development tools which significantly reduces the effort to support a new debugger in different tools.

The Debug Adapter Protocol is a win for both debugger providers and tooling vendors!"

The Debug Adapter Protocol is widely supported for Microsoft's VS Code, there is also a DAP Server, Eclipse has some DAP support, there is some DAP support integrated into GNU Emacs, and various other projects both for language support and development environments have centered around this JSON-RPC protocol. Now today, the latest GDB Git master code does DAP too.


This DAP implementation is via the debugger's Python API rather than a shim. With the latest GDB development code the support can be enabled with gdb -i=dap.
The DAP code will accept JSON-RPC messages on stdin and print responses to stdout. GDB redirects the inferior's stdout to a new pipe so that output can be encapsulated by the protocol.

The Python code uses multiple threads to do its work. Separate threads are used for reading JSON from the client and for writing JSON to the client. All GDB work is done in the main thread. (The first implementation used asyncio, but this had some limitations, and so I rewrote it to use threads instead.)

This is not a complete implementation of the protocol, but it does implement enough to demonstrate that the overall approach works.

The GDB implementation was worked on by developer Tom Tromey and will be found in the next GDB release.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week