816

GitHub - emacs-lsp/dap-mode: Debug Adapter Protocol for Emacs

 5 years ago
source link: https://github.com/emacs-lsp/dap-mode
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.org

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 is a wire protocol for communication between client and Debug Server. It’s similar to the LSP but provides integration with debug server.

Note: dap-mode works only against lsp.el interface.

Project status

The project is in it’s early stage but although it is not extensively tested it is considered stable enough to be used. The API considered unstable until 1.0 release is out. It is tested against Java, Python, Ruby, Elixir and LLDB (C/C++/Objective-C/Swift).

Usage

The main entry points are dap-debug and dap-debug-edit-template. The first one asks for a registered debug template and starts the configuration using the default values for that particular configuration. The later creates a debug template which could be customized before running.

Screenshot

Java

screenshots/MultiSession.png

Swift

screenshots/Swift.png

RUST

screenshots/rust.png

Go

screenshots/go.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

CommandDescriptiondap-breakpoint-toggleToggle breakpoint at linedap-breakpoint-deleteDelete breakpoint at linedap-breakpoint-addAdd java breakpoint at linedap-breakpoint-conditionSet/unset breakpoint conditiondap-breakpoint-hit-conditionSet/unset breakpoint hit conditiondap-breakpoint-log-messageSet/unset breakpoint log messagedap-evalEval stringdap-eval-regionEval region stringdap-eval-thing-at-pointEval symbol at pointdap-step-inDebug step indap-nextDebug nextdap-step-outDebug step outdap-stop-threadStop threaddap-restart-frameRestart framedap-continueDebug continuedap-disconnectCancel current debug sessiondap-switch-stack-frameSwitch active stack framedap-switch-threadSwitch active threaddap-switch-sessionSwitch active sessiondap-debug-edit-templateGenerate run commanddap-debugCreate and run new configuration using the available templatesdap-debug-lastDebug previous configurationdap-debug-recentSelect configuration to run from the previously started commanddap-go-to-output-bufferGo output buffer

Windows

CommandDescriptiondap-ui-sessionsShow active/terminated sessions viewdap-ui-localsShow locals viewdap-ui-breakpointsShow breakpoints viewdap-ui-inspectInspectdap-ui-replDAP UI REPLdap-ui-inspect-regionInspect regiondap-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

CommandDescriptionKeybindingsdap-ui-session-selectSelect object at point<return>dap-ui-session-remove WIPRemove terminated session from the list of running sessionstree-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

CommandDescriptionKeybindingsdap-ui-breakpoints-gotoGo to breakpoint under cursor<return>dap-ui-breakpoints-deleteDelete breakpoint under cursorddap-ui-breakpoints-delete-selectedDelete selected breakpointsDbui-list-markMark breakpoint under pointmbui-list-unmarkUnmark breakpoint under pointubui-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

CommandDescriptiondap-java-debugDebug javadap-java-run-test-methodRun test methoddap-java-debug-test-methodDebug test methoddap-java-run-test-classRun test classdap-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.2"
        
    • Then add the following line in your config:
    (require 'dap-python)
        

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

Ruby

  • Download and extract VSCode Ruby Extension . Make sure that dap-ruby-debug-program is: ("node" path-to-main-js) where node is either “node” if nodejs is on the path or path to nodejs and path-to-main-js is full path ./out/debugger/main.js which is part of the downloaded VScode package.
  • Follow the instructions on installing rdebug-ide from Ruby Debug Installation
  • Put in your emacs configuration.
    (require 'dap-ruby)
        

LLDB

Installation

LLDB is a debugger that supports, among others, C, C++, Objective-C and Swift.

Note: For proper Swift support, you need to compile LLDB from https://github.com/apple/swift-lldb and put the compiled LLDB library/framework in the “extensions” folder.

Elixir

Make sure that you have properly configured Elixir and that you have Elixir LS binaries on the path and put in your emacs configuration.

(require 'dap-elixir)

Then when you do dap-debug-edit-template and select Elixir which will generate runnable debug configuration. For more details on supported settings by the Elixir Debug Server refer to it’s documentation.

PHP

This is using felixbecker/vscode-php-debug (downloadable from the marketplace) as dap-server between emacs and the xdebug-extension on the http-server side. Make sure it is trans/compiled to javascript properly. Only tested under linux with node.

(require 'dap-php)

To begin debugging, select “PHP Run Configuration” from the dap-debug menu, issue the debug request in your browser, select the running thread (dap-switch-thread) and then dap-step-in.

Native Debug (GDB/LLDB)

Using https://github.com/WebFreak001/code-debug

Configuration

Download and extract VSCode extension (make sure that dap-gdb-lldb-path is pointing to the extract location).

(require 'dap-gdb-lldb)

Then do dap-debug or dap-debug-edit-template and selet GBD or LLDB configuration.

Go

Installation

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

Acknowledgments

What’s next

  • Watches

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK