Setting Up Dape in Emacs
Updated: April 12, 2025 · 2 min
Dape allows you to run DAP compatible debuggers in emacs. It’s essentially a replacement for dap-mode. I use Doom Emacs, so you’ll see some Doom-isms.
Once you install and load the package, you’re basically done. Dape has a fair amount of debuggers configured out of the box, and it maps its keybindings to C-x C-a
.
1;; packages.el
2(package! dape)
3
4;; config.el
5(use-package! dape)
Now when you run dape via M-x dape
or C-X C-a d
, you can type in the name of the debugger you want. You can find the names for all the debuggers using describe-variables
and looking for dape-configs
. I recommend searching for the mode you want to debug (ie. go-mode
).
1;; Excerpt from dape-configs
2 (dlv modes
3 (go-mode go-ts-mode)
4 ensure dape-ensure-command command "dlv" command-args
5 ("dap" "--listen" "127.0.0.1::autoport")
6 command-cwd dape-command-cwd port :autoport :request "launch" :type "debug" :cwd "." :program ".")
As we can see here, the name of the debugger is dlv
. When we type that in, we can see the total set of options given to us by dape.
Run adapter: dlv
command-cwd "/var/home/digyx/Code/ric/"
:cwd "."
:program "."
We can change these args by setting them in the Run adapter:
line.
Run adapter: dlv command-cwd "/var/uwu" :cwd "/var/home"
command-cwd "/var/uwu"
:cwd "/var/home"
:program "."
Installing codelldb
Codelldb needs to be manually installing due to it actually being a VSCode plugin. Instructions are here.
https://github.com/svaante/dape?tab=readme-ov-file#c-c-and-rust—codelldb
If you use Doom Emacs, you’ll need to extract the file under ~/.emacs.d/.local/cache/debug-adapters/codelldb/
instead of ~/.emacs.d/debug-adapters/codelldb/
.
Keybindings
If you want map the keybindings to your leader key, this is my current configuration.
1(map! :map dap-mode-map
2 :leader
3 :prefix ("d" . "dap")
4 :desc "dap hydra" "h" #'hydra-dap/body
5
6 :desc "dap debug" "s" #'dape
7 :desc "dap quit" "q" #'dape-quit
8 :desc "dap restart" "r" #'dape-restart
9
10 :desc "dap breakpoint toggle" "b" #'dape-breakpoint-toggle
11 :desc "dap breakpoint remove all" "B" #'dape-breakpoint-remove-all
12 :desc "dap breakpoint log" "l" #'dape-breakpoint-log
13
14 :desc "dap continue" "c" #'dape-continue
15 :desc "dap next" "n" #'dape-next
16 :desc "dap step in" "i" #'dape-step-in
17 :desc "dap step out" "o" #'dape-step-out
18
19 :desc "dap eval" "e" #'dape-evaluate-expression)
And then the hydra:
1(require 'hydra)
2(defhydra hydra-dap (:color pink :hint nil)
3 "
4^Dape Hydra^
5------------------------------------------------
6_n_: Next _e_: Eval _Q_: Disconnect
7_i_: Step In
8_o_: Step Out
9_c_: Continue
10_r_: Restart
11
12"
13 ("n" #'dape-next)
14 ("i" #'dape-step-in)
15 ("o" #'dape-step-out)
16 ("c" #'dape-continue)
17 ("e" #'dape-evaluate-expression)
18 ("r" #'dape-restart)
19 ("q" nil "Quit" :color blue)
20 ("Q" #'dape-quit :color blue))