/dap-mode

Debug Adapter Protocol for Emacs

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

https://melpa.org/packages/dap-mode-badge.svg https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg https://travis-ci.org/yyoncho/dap-mode.svg?branch=master

Table of Contents

Summary

Emacs client/library for Debug Adapter Protocol Debug Adapter Protocol is a wire protocol for communication between client and Debug Server. It similar to the LSP but providers integration with debug server.

Project status

The project is in it’s early stage and is still not extensively tested. The API considered unstable until 1.0 release is out. It is tested only against Java and Python.

Screenshot

screenshots/MultiSession.png

Features

  • Launch/Attach
  • Breakpoints
  • Exceptions
  • Pause & Continue
  • Step In/Out/Over
  • Callstacks
  • Threads
  • Multiple simultaneous debug sessions
  • Evaluating statements
  • Debug/Run configurations

Debugger commands

CommandDescription
dap-breakpoint-toggleToggle java breakpoint at line
dap-breakpoint-deleteDelete java breakpoint at line
dap-breakpoint-addAdd java breakpoint at line
dap-breakpoint-conditionSet/unset breakpoint condition
dap-breakpoint-hit-conditionSet/unset breakpoint hit condition
dap-breakpoint-log-messageSet/unset breakpoint log message
dap-evalEval string
dap-eval-regionEval region string
dap-eval-thing-at-pointEval symbol at point
dap-step-inDebug step in
dap-nextDebug next
dap-step-outDebug step out
dap-stop-threadStop thread
dap-restart-frameRestart frame
dap-continueDebug continue
dap-disconnectCancel current debug session
dap-switch-stack-frameSwitch active stack frame
dap-switch-threadSwitch active thread
dap-switch-sessionSwitch active session
dap-debugCreate and run new configuration using the available templates
dap-debug-lastDebug previous configuration
dap-debug-recentSelect configuration to run from the previously started command
dap-go-to-output-bufferGo output buffer

Windows

CommandDescription
dap-ui-sessionsShow active/terminated sessions view
dap-ui-localsShow locals view
dap-ui-breakpointsShow breakpoints view
dap-ui-inspectInspect
dap-ui-replDAP UI REPL
dap-ui-inspect-regionInspect region
dap-ui-inspect-thing-at-pointInspect symbol at point

Sessions

The sessions view is showed after invoking dap-ui-sessions . It represents the list of the active sessions.

Keybindings

CommandDescriptionKeybindings
dap-ui-session-selectSelect object at point<return>
dap-ui-session-remove WIPRemove terminated session from the list of running sessions
tree-mode-toggle-expandToggle node expand state<tab>

Locals

Locals can be viewed after invoking dap-ui-locals.

Breakpoints

Breakpoints can be viewed after invoking dap-ui-breakpoints.

Keybindings

CommandDescriptionKeybindings
dap-ui-breakpoints-gotoGo to breakpoint under cursor<return>
dap-ui-breakpoints-deleteDelete breakpoint under cursord
dap-ui-breakpoints-delete-selectedDelete selected breakpointsD
bui-list-markMark breakpoint under pointm
bui-list-unmarkUnmark breakpoint under pointu
bui-list-unmark-allUnmark breakpoint under pointU

DAP debug REPL

DAP provides a debug shell to execute command when the program has hit breakpoints. The REPL has the same features as standart emacs shell (e. g. command history, C-p/n navigation through history, etc.) in addition to optional company-mode autocompletion. screenshots/dap-ui-repl.png

Configuration

DAP mode configuration

Enable both dap-mode and dap-ui-mode.

(dap-mode 1)
(dap-ui-mode 1)

After enabling DAP mode on emacs side follow the language specific settings.

Java

Installation

Latest version of LSP Java will automatically discover if dap-mode is present and it will download and install the required server side components. If you have already downloaded a Eclispe JDT Server you will have to force server update via lsp-java-update-server. In order to enable lsp java you will have to require dap-java.el

(require 'dap-java)

Commands

CommandDescription
dap-java-debugDebug java
dap-java-run-test-methodRun test method
dap-java-debug-test-methodDebug test method
dap-java-run-test-classRun test class
dap-java-debug-test-classDebug test class

Python

Installation

  • Make sure you have installed and configured lsp-python.
  • install latest version of ptvsd.
    pip install "ptvsd>=4.1.1a11"
        
    • Then add the following line in your config:
    (require 'dap-python)
        

    This will add the python related configuration to dap-debug.

Extending DAP with new Debug servers

There are two methods that are used for registering remote extensions:

  • dap-register-debug-provider - register a method to call for populating startup parameters. It should either populate :debugPort and :host in case of TCP Debug Adapter Server or :dap-server-path when STD out must be used for Debug Adapter Server communication.
  • dap-register-debug-template register a debug teplate which will be available when dap-debug is called. The debug template must specify :type key which will be used to determine the provider to be called to populate missing fields.

Example

For full example you may check dap-java.el.

(dap-register-debug-provider
 "programming-language-name"
 (lambda (conf)
   (plist-put conf :debugPort 1234)
   (plist-put conf :host "localhost")
   conf))

(dap-register-debug-template "Example Configuration"
                             (list :type "java"
                                   :request "launch"
                                   :args ""
                                   :name "Run Configuration"))

Links

Troubleshooting

If you notice a bug, open an issue on Github Issues.

What’s next

  • Watches