emacs-lsp / dap-mode

Emacs :heart: Debug Adapter Protocol
https://emacs-lsp.github.io/dap-mode
GNU General Public License v3.0
1.28k stars 181 forks source link
cpp debug debugger emacs emacs-lsp go java javascript lsp lua php powershell ruby rust swift typescript

[[https://melpa.org/#/dap-mode][file:https://melpa.org/packages/dap-mode-badge.svg]] [[https://stable.melpa.org/#/dap-mode][file:https://stable.melpa.org/packages/dap-mode-badge.svg]] [[http://spacemacs.org][file:https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg]] [[https://github.com/emacs-lsp/dap-mode/actions][file:https://github.com/emacs-lsp/dap-mode/workflows/CI/badge.svg]] [[https://discord.gg/swuxy5AAgT][file:https://discordapp.com/api/guilds/789885435026604033/widget.png?style=shield]]

** Summary Emacs client/library for [[https://microsoft.github.io/debug-adapter-protocol/][Debug Adapter Protocol]] is a wire protocol for communication between client and Debug Server. It's similar to the [[https://github.com/Microsoft/language-server-protocol][LSP]] but provides integration with debug server. * Project status 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 latter creates a debug template which could be customized before running. ~dap-debug-edit-template~ will prepare a template declaration inside a temporary buffer. You should execute this code using ~C-M-x~ for the changes to apply. You should also copy this code into your Emacs configuration if you wish to make it persistent.

dap-mode also provides a [[https://github.com/abo-abo/hydra][hydra]] with ~dap-hydra~. You can automatically trigger the hydra when the program hits a breakpoint by using the following code.

+BEGIN_SRC elisp

(add-hook 'dap-stopped-hook (lambda (arg) (call-interactively #'dap-hydra)))

+END_SRC

*** Docker usage You can also use this tool with dockerized debug servers: configure it either with a ~.dir-locals~ file or drop an ~.lsp-docker.yml~ configuration file (use [[https://github.com/emacs-lsp/lsp-docker][lsp-docker]] for general reference). Basically you have one function ~dap-docker-register~ that performs all the heavy lifting (finding the original debug template, patching it, registering a debug provider e.t.c). This function examines a configuration file or falls back to the default configuration (which can be patched using the ~.dir-locals~ approach, take a note that the default configuration doesn't provide any sane defaults for debugging) and then operates on the combination of the two. This mechanism is the same as in ~lsp-docker~.

Note: currently you cannot use this mode when using a network connection to connect to debuggers (this part is yet to be implemented).
Still want to talk to debuggers over network? In order to do so you have to look at the ~launch-args~ patching
done by ~dap-docker--dockerize-start-file-args~, you have to somehow assign ~nil~ to ~dap-server-path~ before it is passed further into session creation.

If you want to stick to a configuration file, take a look at the example below:

#+begin_src yaml
lsp:
  server:
    # 'lsp-docker' fields
  mappings:
    - source: "/your/host/source/path" # used both by 'lsp-docker' and 'dap-docker'
      destination: "/your/local/path/inside/a/container" # used both by 'lsp-docker' and 'dap-docker'
  debug:
    type: docker # only docker is supported
    subtype: image # or 'container'
    name: <docker image or container that has the debugger in> # you can omit this field
    # in this case the 'lsp-docker' ('server' section) image name is used
    enabled: true # you can explicitly disable 'dap-docker' by using 'false'
    provider: <your default language debug provider, double quoted string>
    template: <your default language debug template, double quoted string>
    launch_command: <an explicit command if you want to override a default one provided by the debug provider>
    # e.g. if you have installed a debug server in a different directory, not used with 'container' subtype debuggers
#+end_src

[[https://emacs-lsp.github.io/dap-mode/page/features/][Features]] [[https://emacs-lsp.github.io/dap-mode/page/configuration/][Configuration]] [[https://emacs-lsp.github.io/dap-mode/page/gallery][Gallery]] [[https://emacs-lsp.github.io/dap-mode/page/adding-debug-server][Extending DAP with new Debug servers]] ** Links