Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to discover correct configs for debugging over TRAMP (specifically Rust) #136

Open
bertulli opened this issue Aug 9, 2024 · 8 comments

Comments

@bertulli
Copy link

bertulli commented Aug 9, 2024

Hi, first thank you for your work! I'm trying to set up dape to work with Rust programs, I remember doing it successfully a few months ago, but now I need to do the same connecting to a WSL machine. Specifically:

  • Host machine:
    Windows 11, running Emacs GNU Emacs 29.2 (build 2, x86_64-w64-mingw32) of 2024-02-01
  • Target machine:
    WSL Ubuntu-22.04, with installed codelldb as shown in the README, and exposing the ssh server on port 2020.

I usually can connect via TRAMP using the path /plink:[email protected]#2020:~/. After a bit of thinkering, I managed to customize the dape-config to

(codelldb-rust modes
		    (rust-mode rust-ts-mode)
		    ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb" command-cwd dape-command-cwd :type "lldb" :request "launch" command-args
		    ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}")
		    port :autoport :cwd "." :program
		    (lambda nil
		      (file-name-concat "target" "debug"
					(thread-first
					  (dape-cwd)
					  (directory-file-name)
					  (file-name-split)
					  (last)
					  (car))))
		    :args
		    []
		    :stopOnEntry nil)

(notice how I prefixed the command path with the TRAMP prefix). When launching dape, I insert the string codelldb-rust command-cwd "/plink:[email protected]#2020:~/exercism/rust/luhn/target/debug/" :program "luhn", and I obtain the error:

* Remote connection detected, setting prefix-local to "/plink:[email protected]:" *
* Unable to connect to dap server at localhost:0 *
* Connection is configurable by host and port keys *
env: ‘/plink:[email protected]#2020:/home/abertulli/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb’: No such file or directory

so I presume dape is not correctly detecting that the server is on a remote machine. Maybe it is similar to #109 or #105 , but I don't know which port I should specify. A couple of tries:

  • codelldb-rust command-cwd "/plink:[email protected]#2020:~/exercism/rust/luhn/target/debug/" port 2020 :program "luhn"
* Remote connection detected, setting prefix-local to "/plink:[email protected]:" *
* Adapter connection shutdown without successfully initializing *
Configuration:
  modes (rust-mode rust-ts-mode)
  ensure dape-ensure-command
  command "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb"
  command-cwd "/plink:[email protected]#2020:~/exercism/rust/luhn/target/debug/"
  :type "lldb"
  :request "launch"
  command-args ("--port" "2020" "--settings" "{\"sourceLanguages\":[\"rust\"]}")
  port 2020
  :cwd "."
  :program "luhn"
  :args []
  :stopOnEntry nil
  prefix-local "/plink:[email protected]:"
Invalid SSH identification string.

env: ‘/plink:[email protected]#2020:/home/abertulli/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb’: No such file or directory
  • codelldb-rust command-cwd "/plink:[email protected]#2020:~/exercism/rust/luhn/target/debug/" :port 2020 :program "luhn"
* Remote connection detected, setting prefix-local to "/plink:[email protected]:" *
* Unable to connect to dap server at localhost:0 *
* Connection is configurable by host and port keys *
env: ‘/plink:[email protected]#2020:/home/abertulli/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb’: No such file or directory

So, which configuration should I change to make dape launch via TRAMP a remote debug server? In this case, everything resides on the target machine, the only thing external is Emacs. Should I do an ssh forwarding? But on which poort? Thanks!

@svaante
Copy link
Owner

svaante commented Aug 18, 2024

Hey!

When debugging with an adapter that connects with TCP like codelldb
there are some less then optimal requirements when debugging with
tramp. If you are fine with the location of the default codelldb on
the remote machine I would not change/add any dape configurations.

  1. The adapter needs to be running on the remote machine
scp -r user@local:.emacs.d/debug-adapters/codelldb user@remote:.emacs.d/debug-adapters/codelldb

Make sure that codelldb is executable chmod +x

As long as the current buffer is on the remote machine the defualt
codelldb-rust will lunch codelldb on the remote machine(like we
want).

  1. There needs to be an open port on the remote machine so that Emacs
    can connect to it.

When calling codelldb-rust dape will try it's best to find an unused
port, but it has no idea what ports are open on the remote machine.

Use the keyword port to specify an port which is reachable for the
local machine, like:
M-x dape<Enter>codelldb-rust port 5678<Enter>

Another simpler approach to tramp debugging is to use a debugger which
does not use TCP to connect. No need for an open port, but still need
to install the adapter on the remote machine. I would suggest
lldap-dap which comes with an installation of lldb.

@bertulli
Copy link
Author

Thanks, I think I'm making progress! I am using WSL-2, so technically the ports are automatically forwarded. I also checked and the adapter is present only on the remote machine, and it is executable. I think I was using :port, now trying with port 5678 my Emacs actually froze, then upon C-g I landed on dape interface, and I got the error

Tramp: Opening connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Setup connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Opening connection dape adapter for [email protected]#2020 using plink...done
Tramp: Setup connection dape adapter for [email protected]#2020 using plink...done
QuitError during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations)
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations)
QuitError during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations)

Reading the Messages buffer I think this error may also be present before, when launching Eglot, that however works fine, so I don't know if it's a false positive. Trying with C-h o, I see that effectively I have nothing called jsonrpc--request-continuations. Am I missing a package?

@svaante
Copy link
Owner

svaante commented Sep 3, 2024

Hey sorry for the late response, this seams like your package manager is installing the correct version of jsonrpc. The package is built in but dape requires an newer version that what is package with emacs 29.

find-library<Enter>jsonrpc<Enter>

Should open an file containing

;;; jsonrpc.el --- JSON-RPC library                  -*- lexical-binding: t; -*-

;; Copyright (C) 2018-2024 Free Software Foundation, Inc.

;; Author: João Távora <[email protected]>
;; Keywords: processes, languages, extensions
;; Version: 1.0.25
;; Package-Requires: ((emacs "25.2"))

package-upgrade jsonrcp

If you are using straight.
You might need to install it explicitly, straight-pull-package<Enter>jsonrpc and restart Emacs.

  (use-package jsonrpc :straight t)

@bertulli
Copy link
Author

bertulli commented Sep 4, 2024 via email

@bertulli
Copy link
Author

bertulli commented Sep 13, 2024

Ok, I checked and apparently I already have version 1.0.25 of jsonrpc. It was a dependency of dape, but now I installed it manually.

I have a couple of reproducible examples, at least on my machine:

  • when I try M-x dape without changing any configuration, it prompts me for lldb-vscode command-cwd "/plink:[email protected]#2020:/" :program "luhn" port 5678, but it also errors telling me Unable to locate "lldb-vscode" (default directory /plink:[email protected]#2020:/). The *Messages* buffer shows
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [5 times]
dape--config-ensure: Unable to locate "lldb-vscode" (default-directory /plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/)Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations)
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [2 times]
  • Changing the adapter to codelldb-rust, it still can't find the adapter (complete string codelldb-rust command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/" :program "luhn" port 5678), with the messages
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [9 times]
dape--config-ensure: Unable to locate "~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb" (default-directory /plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/)Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations)
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [3 times]
  • If I instead add in front of dape-configs the value
(codelldb-rust modes
		    (rust-mode rust-ts-mode)
		    ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb" command-cwd dape-command-cwd :type "lldb" :request "launch" command-args
		    ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}")
		    port :autoport :cwd "." :program
		    (lambda nil
		      (file-name-concat "target" "debug"
					(thread-first
					  (dape-cwd)
					  (directory-file-name)
					  (file-name-split)
					  (last)
					  (car))))
		    :args
		    []
		    :stopOnEntry nil)

when I give M-x dape I am prompted for codelldb-rust command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/" port 5678 :program "luhn", and this time it doesn't complain about the missing adapter BUT the UI hangs with the echo area on Tramp: Setup connection dape adapter for [email protected]#2020 using plink...done. Closing with C-g, the date UI shows up, with the prompt

* Welcome to Dape REPL! *
Available Dape commands: debug, next, continue, pause, step, out, up, down, restart, kill, disconnect, quit
Empty input will rerun last command.

* Remote connection detected, setting prefix-local to "/plink:[email protected]:" *
> 

but the debug seems not to be running (d will prompt for the dape config string again). An example of the possible complete relevant *Messages* is:

Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [5 times]
Tramp: Opening connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Setup connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Opening connection dape adapter for [email protected]#2020 using plink...done
Tramp: Setup connection dape adapter for [email protected]#2020 using plink...done
QuitError during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations)
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [3 times]
  • Repeating with debug-on-quit to t (and the modified configs), I can see that the point on which Emacs hangs is
Debugger entered--Lisp error: (quit)
  dape--create-connection((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil prefix-local "/plink:[email protected]:"))
  #f(compiled-function (nil nil)
  dape--request-return(#f(compiled-function 
  dape-kill(nil #f(compiled-function 
  dape((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  funcall-interactively(dape (modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  command-execute(dape record)
  execute-extended-command(nil "dape" nil)
  funcall-interactively(execute-extended-command nil "dape" nil)
  command-execute(execute-extended-command)

and the messages are

Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [5 times]
Tramp: Opening connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Setup connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Opening connection dape adapter for [email protected]#2020 using plink...done
Tramp: Setup connection dape adapter for [email protected]#2020 using plink...done
Entering debugger...
cl-prin1: (args-out-of-range "" 0) [3 times]
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [6 times]
  • I thought this may be due to the dape config not actually pointing to the real Rust program, so I changed that to (note the additions):
codelldb-rust command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/" port 5678 :program "target/debug/luhn" :cwd "/plink:[email protected]#2020:~/exercism/rust/luhn/"
                                                                                                                                      ^^^^^^^^^^^^       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

but it still hangs. In this case, the backtrace is

Debugger entered--Lisp error: (quit)
  dape--create-connection((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "/plink:[email protected]#2020:~/exercism/rust/lu..." :program "target/debug/luhn" :args [] :stopOnEntry nil prefix-local "/plink:[email protected]:"))
  #f(compiled-function (nil nil)
  dape--request-return(#f(compiled-function 
  dape-kill(nil #f(compiled-function 
  dape((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "/plink:[email protected]#2020:~/exercism/rust/lu..." :program "target/debug/luhn" :args [] :stopOnEntry nil))
  funcall-interactively(dape (modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "/plink:[email protected]#2020:~/exercism/rust/lu..." :program "target/debug/luhn" :args [] :stopOnEntry nil))
  command-execute(dape record)
  execute-extended-command(nil "dape" nil)
  funcall-interactively(execute-extended-command nil "dape" nil)
  command-execute(execute-extended-command)

while the messages are

Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [17 times]
Tramp: Opening connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Setup connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Opening connection dape adapter for [email protected]#2020 using plink...done
Tramp: Setup connection dape adapter for [email protected]#2020 using plink...done
Entering debugger...
cl-prin1: (args-out-of-range "" 0) [3 times]
Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [6 times]

PS the actual code I run to change the config is from helpful-describe-variable > set (which suggests a setq), I placed the new config at the front. Now dape-configs is

((codelldb-rust modes
		(rust-mode rust-ts-mode)
		ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb" command-cwd dape-command-cwd :type "lldb" :request "launch" command-args
		("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}")
		port :autoport :cwd "." :program
		(lambda nil
		  (file-name-concat "target" "debug"
				    (thread-first
				      (dape-cwd)
				      (directory-file-name)
				      (file-name-split)
				      (last)
				      (car))))
		:args
		[]
		:stopOnEntry nil)
 (attach modes nil ensure
	 (lambda
	   (config)
	   (unless
	       (plist-get config 'port)
	     (user-error "Missing `port' property")))
	 host "localhost" :request "attach")
 (launch modes nil command-cwd dape-command-cwd ensure
	 (lambda
	   (config)
	   (unless
	       (plist-get config 'command)
	     (user-error "Missing `command' property")))
	 :request "launch")
 (codelldb-cc modes
	      (c-mode c-ts-mode c++-mode c++-ts-mode)
	      command-args
	      ("--port" :autoport)
	      ensure dape-ensure-command command-cwd dape-command-cwd command "~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb" port :autoport :type "lldb" :request "launch" :cwd "." :program "a.out" :args
	      []
	      :stopOnEntry nil)
 (codelldb-rust modes
		(rust-mode rust-ts-mode)
		command-args
		("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}")
		ensure dape-ensure-command command-cwd dape-command-cwd command "~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb" port :autoport :type "lldb" :request "launch" :cwd "." :program
		(lambda nil
		  (file-name-concat "target" "debug"
				    (thread-first
				      (dape-cwd)
				      (directory-file-name)
				      (file-name-split)
				      (last)
				      (car))))
		:args
		[]
		:stopOnEntry nil)
 (cpptools modes
	   (c-mode c-ts-mode c++-mode c++-ts-mode)
	   ensure dape-ensure-command command-cwd dape-command-cwd command "~/.emacs.d/debug-adapters/cpptools/extension/debugAdapters/bin/OpenDebugAD7" fn
	   (lambda
	     (config)
	     (let
		 ((program
		   (plist-get config :program)))
	       (if
		   (file-name-absolute-p program)
		   config
		 (thread-last
		   (tramp-file-local-name
		    (dape--guess-root config))
		   (expand-file-name program)
		   (plist-put config :program)))))
	   :type "cppdbg" :request "launch" :cwd "." :program "a.out" :MIMode "lldb")
 (debugpy modes
	  (python-mode python-ts-mode)
	  ensure
	  (lambda
	    (config)
	    (dape-ensure-command config)
	    (let
		((python
		  (dape-config-get config 'command)))
	      (unless
		  (zerop
		   (call-process-shell-command
		    (format "%s -c \"import debugpy.adapter\"" python)))
		(user-error "%s module debugpy is not installed" python))))
	  command "python" command-args
	  ("-m" "debugpy.adapter" "--host" "0.0.0.0" "--port" :autoport)
	  port :autoport :request "launch" :type "python" :cwd dape-cwd :program dape-buffer-default :args
	  []
	  :justMyCode nil :console "integratedTerminal" :showReturnValue t :stopOnEntry nil)
 (debugpy-module modes
		 (python-mode python-ts-mode)
		 ensure
		 (lambda
		   (config)
		   (dape-ensure-command config)
		   (let
		       ((python
			 (dape-config-get config 'command)))
		     (unless
			 (zerop
			  (call-process-shell-command
			   (format "%s -c \"import debugpy.adapter\"" python)))
		       (user-error "%s module debugpy is not installed" python))))
		 command "python" command-args
		 ("-m" "debugpy.adapter" "--host" "0.0.0.0" "--port" :autoport)
		 port :autoport :request "launch" :type "python" :cwd dape-cwd :module
		 (lambda nil
		   (thread-first default-directory
				 (directory-file-name)
				 (file-name-split)
				 (last)
				 (car)))
		 :args
		 []
		 :justMyCode nil :console "integratedTerminal" :showReturnValue t :stopOnEntry nil)
 (dlv modes
      (go-mode go-ts-mode)
      ensure dape-ensure-command command "dlv" command-args
      ("dap" "--listen" "127.0.0.1::autoport")
      command-cwd dape-command-cwd port :autoport :request "launch" :type "debug" :cwd "." :program ".")
 (flutter ensure dape-ensure-command modes
	  (dart-mode)
	  command "flutter" command-args
	  ("debug_adapter")
	  command-cwd dape-command-cwd :type "dart" :cwd "." :program "lib/main.dart" :toolArgs
	  ["-d" "all"])
 (gdb ensure
      (lambda
	(config)
	(dape-ensure-command config)
	(let*
	    ((default-directory
	      (or
	       (dape-config-get config 'command-cwd)
	       default-directory))
	     (output
	      (shell-command-to-string "gdb --version"))
	     (version
	      (save-match-data
		(when
		    (string-match "GNU gdb \\(?:(.*) \\)?\\([0-9.]+\\)" output)
		  (string-to-number
		   (match-string 1 output))))))
	  (unless
	      (>= version 14.1)
	    (user-error "Requires gdb version >= 14.1"))))
      modes
      (c-mode c-ts-mode c++-mode c++-ts-mode)
      command-cwd dape-command-cwd command "gdb" command-args
      ("--interpreter=dap")
      defer-launch-attach t :request "launch" :program "a.out" :args
      []
      :stopAtBeginningOfMainSubprogram nil)
 (godot modes
	(gdscript-mode)
	port 6006 :request "launch" :type "server" :cwd dape-cwd)
 (js-debug-node modes
		(js-mode js-ts-mode)
		ensure
		#[257 "\300�!\210\301�\302\"\211\203�\0\303�!\210\210\304�\305\"@\306�!?\205!\0\307\310�\"\207"
		      [dape-ensure-command dape-config-get :runtimeExecutable dape--ensure-executable plist-get command-args file-exists-p user-error "File %S does not exist"]
		      5 "\n\n(fn CONFIG)"]
		command "node" command-args
		("c:/Users/a.bertulli/AppData/Roaming/.emacs.d/debug-adapters/js-debug/src/dapDebugServer.js" :autoport)
		port :autoport :type "pwa-node" :cwd dape-cwd :program dape-buffer-default :console "internalConsole")
 (js-debug-ts-node modes
		   (typescript-mode typescript-ts-mode)
		   ensure
		   #[257 "\300�!\210\301�\302\"\211\203�\0\303�!\210\210\304�\305\"@\306�!?\205!\0\307\310�\"\207"
			 [dape-ensure-command dape-config-get :runtimeExecutable dape--ensure-executable plist-get command-args file-exists-p user-error "File %S does not exist"]
			 5 "\n\n(fn CONFIG)"]
		   command "node" command-args
		   ("c:/Users/a.bertulli/AppData/Roaming/.emacs.d/debug-adapters/js-debug/src/dapDebugServer.js" :autoport)
		   port :autoport :type "pwa-node" :runtimeExecutable "ts-node" :cwd dape-cwd :program dape-buffer-default :console "internalConsole")
 (js-debug-node-attach modes
		       (js-mode js-ts-mode typescript-mode typescript-ts-mode)
		       ensure
		       #[257 "\300�!\210\301�\302\"\211\203�\0\303�!\210\210\304�\305\"@\306�!?\205!\0\307\310�\"\207"
			     [dape-ensure-command dape-config-get :runtimeExecutable dape--ensure-executable plist-get command-args file-exists-p user-error "File %S does not exist"]
			     5 "\n\n(fn CONFIG)"]
		       command "node" command-args
		       ("c:/Users/a.bertulli/AppData/Roaming/.emacs.d/debug-adapters/js-debug/src/dapDebugServer.js" :autoport)
		       port :autoport :type "pwa-node" :request "attach" :port 9229)
 (js-debug-chrome modes
		  (js-mode js-ts-mode typescript-mode typescript-ts-mode)
		  ensure
		  #[257 "\300�!\210\301�\302\"\211\203�\0\303�!\210\210\304�\305\"@\306�!?\205!\0\307\310�\"\207"
			[dape-ensure-command dape-config-get :runtimeExecutable dape--ensure-executable plist-get command-args file-exists-p user-error "File %S does not exist"]
			5 "\n\n(fn CONFIG)"]
		  command "node" command-args
		  ("c:/Users/a.bertulli/AppData/Roaming/.emacs.d/debug-adapters/js-debug/src/dapDebugServer.js" :autoport)
		  port :autoport :type "pwa-chrome" :url "http://localhost:3000" :webRoot dape-cwd)
 (lldb-vscode command "lldb-vscode" :type "lldb-vscode" modes
	      (c-mode c-ts-mode c++-mode c++-ts-mode rust-mode rust-ts-mode rustic-mode)
	      ensure dape-ensure-command command-cwd dape-command-cwd :cwd "." :program "a.out")
 (lldb-dap command "lldb-dap" :type "lldb-dap" modes
	   (c-mode c-ts-mode c++-mode c++-ts-mode rust-mode rust-ts-mode rustic-mode)
	   ensure dape-ensure-command command-cwd dape-command-cwd :cwd "." :program "a.out")
 (netcoredbg modes
	     (csharp-mode csharp-ts-mode)
	     ensure dape-ensure-command command "netcoredbg" command-args
	     ["--interpreter=vscode"]
	     :request "launch" :cwd dape-cwd :program
	     (lambda nil
	       (let
		   ((dlls
		     (file-expand-wildcards
		      (file-name-concat "bin" "Debug" "*" "*.dll"))))
		 (if dlls
		     (file-relative-name
		      (file-relative-name
		       (car dlls)))
		   ".dll"
		   (dape-cwd))))
	     :stopAtEntry nil)
 (ocamlearlybird ensure dape-ensure-command modes
		 (tuareg-mode caml-mode)
		 command "ocamlearlybird" command-args
		 ("debug")
		 :type "ocaml" :program
		 (lambda nil
		   (file-name-concat
		    (dape-cwd)
		    "_build" "default" "bin"
		    (concat
		     (file-name-base
		      (dape-buffer-default))
		     ".bc")))
		 :console "internalConsole" :stopOnEntry nil :arguments
		 [])
 (rdbg modes
       (ruby-mode ruby-ts-mode)
       ensure dape-ensure-command command "rdbg" command-args
       ("-O" "--host" "0.0.0.0" "--port" :autoport "-c" "--" :-c)
       fn
       (lambda
	 (config)
	 (plist-put config 'command-args
		    (mapcar
		     (lambda
		       (arg)
		       (if
			   (eq arg :-c)
			   (plist-get config '-c)
			 arg))
		     (plist-get config 'command-args))))
       port :autoport command-cwd dape-command-cwd :type "Ruby" -c
       (lambda nil
	 (format "ruby %s"
		 (or
		  (dape-buffer-default)
		  ""))))
 (jdtls modes
	(java-mode java-ts-mode)
	ensure
	(lambda
	  (config)
	  (let
	      ((file
		(dape-config-get config :filePath)))
	    (unless
		(and
		 (stringp file)
		 (file-exists-p file))
	      (user-error "Unable to find locate :filePath `%s'" file))
	    (with-current-buffer
		(find-file-noselect file)
	      (unless
		  (eglot-current-server)
		(user-error "No eglot instance active in buffer %s"
			    (current-buffer)))
	      (unless
		  (seq-contains-p
		   (eglot--server-capable :executeCommandProvider :commands)
		   "vscode.java.resolveClasspath")
		(user-error "Jdtls instance does not bundle java-debug-server, please install")))))
	fn
	(lambda
	  (config)
	  (with-current-buffer
	      (find-file-noselect
	       (dape-config-get config :filePath))
	    (if-let
		((server
		  (eglot-current-server)))
		(pcase-let
		    ((`[,module-paths ,class-paths]
		      (eglot-execute-command server "vscode.java.resolveClasspath"
					     (vector
					      (plist-get config :mainClass)
					      (plist-get config :projectName))))
		     (port
		      (eglot-execute-command server "vscode.java.startDebugSession" nil)))
		  (thread-first config
				(plist-put 'port port)
				(plist-put :modulePaths module-paths)
				(plist-put :classPaths class-paths)))
	      server)))
	:filePath
	#[0 "\300\301!\206\f\0\302\303 \304 \"\207"
	    [#[257 "\3001!\0\301\302 \303\304\305\306 !!#\307\310�\"\206�\0\211\311H\312��\"\266\2020\207\210\313\207"
		   [(error)
		    eglot-execute-command eglot-current-server "vscode.java.resolveMainClass" file-name-nondirectory directory-file-name dape-cwd seq-find
		    #[257 "\300�\301\"\302 \232\207"
			  [plist-get :filePath buffer-file-name]
			  4 "\n\n(fn VAL)"]
		    0 plist-get nil]
		   7 "\n\n(fn KEY)"]
	     :filePath expand-file-name dape-buffer-default dape-cwd]
	    3]
	:mainClass
	#[0 "\300\301!\206�\0\302\207"
	    [#[257 "\3001!\0\301\302 \303\304\305\306 !!#\307\310�\"\206�\0\211\311H\312��\"\266\2020\207\210\313\207"
		   [(error)
		    eglot-execute-command eglot-current-server "vscode.java.resolveMainClass" file-name-nondirectory directory-file-name dape-cwd seq-find
		    #[257 "\300�\301\"\302 \232\207"
			  [plist-get :filePath buffer-file-name]
			  4 "\n\n(fn VAL)"]
		    0 plist-get nil]
		   7 "\n\n(fn KEY)"]
	     :mainClass ""]
	    2]
	:projectName
	#[0 "\300\301!\206�\0\302\207"
	    [#[257 "\3001!\0\301\302 \303\304\305\306 !!#\307\310�\"\206�\0\211\311H\312��\"\266\2020\207\210\313\207"
		   [(error)
		    eglot-execute-command eglot-current-server "vscode.java.resolveMainClass" file-name-nondirectory directory-file-name dape-cwd seq-find
		    #[257 "\300�\301\"\302 \232\207"
			  [plist-get :filePath buffer-file-name]
			  4 "\n\n(fn VAL)"]
		    0 plist-get nil]
		   7 "\n\n(fn KEY)"]
	     :projectName ""]
	    2]
	:args "" :stopOnEntry nil :type "java" :request "launch" :vmArgs " -XX:+ShowCodeDetailsInExceptionMessages" :console "integratedConsole" :internalConsoleOptions "neverOpen")
 (xdebug modes
	 (php-mode php-ts-mode)
	 ensure
	 (lambda
	   (config)
	   (dape-ensure-command config)
	   (let
	       ((dap-debug-server-path
		 (car
		  (plist-get config 'command-args))))
	     (unless
		 (file-exists-p dap-debug-server-path)
	       (user-error "File %S does not exist" dap-debug-server-path))))
	 command "node" command-args
	 ("c:/Users/a.bertulli/AppData/Roaming/.emacs.d/debug-adapters/php-debug/extension/out/phpDebug.js")
	 :type "php" :port 9003))

@bertulli
Copy link
Author

Another thing: checking the buffer *dape-server stderr*, I see

env: ‘/plink:[email protected]#2020:/home/abertulli/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb’: No such file or directory

but I am sure the program is here and executable

$ ll /home/abertulli/.emacs.d/debug-adapters/codelldb/extension/adapter
total 6004
drwxr-xr-x 3 abertulli abertulli    4096 Aug  9 13:30 ./
drwxr-xr-x 7 abertulli abertulli    4096 Aug  9 13:30 ../
-rwxr-xr-x 1 abertulli abertulli 6134864 Sep 15  2023 codelldb*
drwxr-xr-x 3 abertulli abertulli    4096 Aug  9 13:30 scripts/

@svaante
Copy link
Owner

svaante commented Sep 14, 2024

First of thank you for supplying all the debug information for me to go on.

Another dape user had similar issues see #142 with eglot after jsonrpc update.

This error Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [17 times] is due to eglot needing to be updated to work with the latest jsonrpc (a bit of a mess).

The hanging is unrelated to the eglot error thou.

  dape--create-connection((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "/plink:[email protected]#2020:~/exercism/rust/lu..." :program "target/debug/luhn" :args [] :stopOnEntry nil prefix-local "/plink:[email protected]:"))

It seams like dape has started codelldb on [email protected] but cant seam to connect to the port 5678 on the machine, still.

I would suggest you try out gdb or lldb-dap instead of codelldb-rust both adapters use stdout to communicate which can be done over tramp.

  • gdb command-cwd "/plink:[email protected]#2020:/working/directory/of/program" :program "./target/debug/my-rust-binary"
  • lldb-dap command-cwd "/plink:[email protected]#2020:/working/directory/of/program" :program "./target/debug/my-rust-binary"

@bertulli
Copy link
Author

thank you for supplying all the debug information for me to go on.

You're very welcome!

This error Error during redisplay: (eval (eglot--mode-line-format)) signaled (void-function jsonrpc--request-continuations) [17 times] is due to eglot needing to be updated to work with the latest jsonrpc (a bit of a mess).

Thanks, I manually installed the MELPA version of Eglot (1.17 over 1.12 shipped with Emacs 29.2) and the error about jsonrpc is gone.

More tests!

  • Now, with a similar process (modified config and dape string codelldb-rust command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/" port 5678 :program "luhn"), I hang at
Debugger entered--Lisp error: (quit)
  make-network-process(:name "dape adapter connection" :host "localhost" :coding utf-8-emacs-unix :service 5678 :noquery t)
  dape--create-connection((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil prefix-local "/plink:[email protected]:"))
  #f(compiled-function (nil nil)
  dape--request-return(#f(compiled-function 
  dape-kill(nil #f(compiled-function 
  dape((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  funcall-interactively(dape (modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  command-execute(dape record)
  execute-extended-command(nil "dape" nil)
  funcall-interactively(execute-extended-command nil "dape" nil)
  command-execute(execute-extended-command)
  • About the port

It seams like dape has started codelldb on [email protected] but cant seam to connect to the port 5678 on the machine, still.

Would it help if I activated the server manually? For instance, I tried running $ ~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb --port 5678 before M-x dape, but it still hung at

Debugger entered--Lisp error: (quit)
  sleep-for(0.1)
  dape--create-connection((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil prefix-local "/plink:[email protected]:"))
  #f(compiled-function (nil nil)
  dape--request-return(#f(compiled-function 
  dape-kill(nil #f(compiled-function 
  dape((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  funcall-interactively(dape (modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-a..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  command-execute(dape record)
  execute-extended-command(nil "dape" nil)
  funcall-interactively(execute-extended-command nil "dape" nil)
  command-execute(execute-extended-command)
  • I also tried to get the local IP of my WSL distro (172.23.243.157, before I was using 127.0.0.1 and relying on WSL's port forwarding). I think it's correct because I can connect over dired's TRAMP. However, Emcas hangs still on
Debugger entered--Lisp error: (quit)
  dape--create-connection((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/de..." :type "lldb" :request "launch" command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil prefix-local "/plink:[email protected]:"))
  #f(compiled-function (nil nil)
  dape--request-return(#f(compiled-function 
  dape-kill(nil #f(compiled-function 
  dape((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/de..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  funcall-interactively(dape (modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/de..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  command-execute(dape record)
  execute-extended-command(nil "dape" nil)
  funcall-interactively(execute-extended-command nil "dape" nil)
  command-execute(execute-extended-command)
  • I tried manually opening a port using and admin Powershell:
netsh interface portproxy set v4tov4 listenport=5678 listenaddress=0.0.0.0 connectport=5678 conn
ectaddress=$(wsl hostname -I)

and that got me

Debugger entered--Lisp error: (quit)
  make-network-process(:name "dape adapter connection" :host "localhost" :coding utf-8-emacs-unix :service 5678 :noquery t)
  dape--create-connection((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/de..." :type "lldb" :request "launch" command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil prefix-local "/plink:[email protected]:"))
  #f(compiled-function (nil nil)
  dape--request-return(#f(compiled-function 
  dape-kill(nil #f(compiled-function 
  dape((modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/de..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  funcall-interactively(dape (modes (rust-mode rust-ts-mode) ensure dape-ensure-command command "/plink:[email protected]#2020:~/.emacs.d/debug-a..." command-cwd "/plink:[email protected]#2020:~/.emacs.d/de..." :type "lldb" :request "launch" command-args ("--port" :autoport "--settings" "{\"sourceLanguages\":[\"rust\"]}") port 5678 :cwd "." :program "luhn" :args [] :stopOnEntry nil))
  command-execute(dape record)
  execute-extended-command(nil "dape" nil)
  funcall-interactively(execute-extended-command nil "dape" nil)
  command-execute(execute-extended-command)
  • Now, with both port forwarding and the server started by CLI (if I did that right), the dape REPL presents me a hopeful
* Welcome to Dape REPL! *
Available Dape commands: debug, next, continue, pause, step, out, up, down, restart, kill, disconnect, quit
Empty input will rerun last command.

* Remote connection detected, setting prefix-local to "/plink:[email protected]:" *
Console is in 'commands' mode, prefix expressions with '?'.
unable to find executable for 'luhn'
* Adapter connection shutdown without successfully initializing *
Configuration:
  modes (rust-mode rust-ts-mode)
  ensure dape-ensure-command
  command "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb"
  command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/"
  :type "lldb"
  :request "launch"
  command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}")
  port 5678
  :cwd "."
  :program "luhn"
  :args []
  :stopOnEntry nil
  prefix-local "/plink:[email protected]:"
env: ‘/plink:[email protected]#2020:/home/abertulli/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb’: No such file or directory
> 

my Linux terminal shows

$ ~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb --port 5678
[ERROR codelldb::debug_session] unable to find executable for 'luhn'

and the messages buffer

Tramp: Opening connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Setup connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Opening connection dape adapter for [email protected]#2020 using plink...done
Tramp: Setup connection dape adapter for [email protected]#2020 using plink...done
[jsonrpc] Server exited with status 0
  • I thought it was not pointing to the right Rust executable, so I changed the dape string to codelldb-rust command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/" port 5678 :cwd "/plink:[email protected]#2020:~/exercism/rust/luhn/" :program "target/debug/luhn", for which my terminal still showed
$ ~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb --port 5678
[ERROR codelldb::debug_session] unable to find executable for 'target/debug/luhn'

the dape REPL

* Welcome to Dape REPL! *
Available Dape commands: debug, next, continue, pause, step, out, up, down, restart, kill, disconnect, quit
Empty input will rerun last command.

* Remote connection detected, setting prefix-local to "/plink:[email protected]:" *
Console is in 'commands' mode, prefix expressions with '?'.
unable to find executable for 'target/debug/luhn'
* Adapter connection shutdown without successfully initializing *
Configuration:
  modes (rust-mode rust-ts-mode)
  ensure dape-ensure-command
  command "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb"
  command-cwd "/plink:[email protected]#2020:~/.emacs.d/debug-adapters/codelldb/extension/adapter/"
  :type "lldb"
  :request "launch"
  command-args ("--port" "5678" "--settings" "{\"sourceLanguages\":[\"rust\"]}")
  port 5678
  :cwd "/plink:[email protected]#2020:~/exercism/rust/luhn/"
  :program "target/debug/luhn"
  :args []
  :stopOnEntry nil
  prefix-local "/plink:[email protected]:"
env: ‘/plink:[email protected]#2020:/home/abertulli/.emacs.d/debug-adapters/codelldb/extension/adapter/codelldb’: No such file or directory
> 

and the Messages buffer


Tramp: Opening connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Setup connection *dape-server stderr* for [email protected]#2020 using plink...done
Tramp: Opening connection dape adapter for [email protected]#2020 using plink...done
Tramp: Setup connection dape adapter for [email protected]#2020 using plink...done
[jsonrpc] Server exited with status 0
You can run the command ‘dape’ with C-x C-a d
[jsonrpc] Server exited with status 0

I don't know if it's an improvement 😆

I would suggest you try out gdb or lldb-dap instead of codelldb-rust both adapters use stdout to communicate which can be done over tramp.

  • gdb command-cwd "/plink:[email protected]#2020:/working/directory/of/program" :program "./target/debug/my-rust-binary"
  • lldb-dap command-cwd "/plink:[email protected]#2020:/working/directory/of/program" :program "./target/debug/my-rust-binary"

Sorry, I didn't understand here, shouldn't command-cwd be pointing to the directory containing the adapter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants