svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
491 stars 32 forks source link

Native Debug configuration is missing #146

Open brownts opened 2 months ago

brownts commented 2 months ago

The Native Debug adapter has been around for quite a while and is an alternative to the Micrsoft cpptools debug adapter, supporting both GDB and LLDB.

The following are a set of installation instructions:

1. Download latest vsix [release](https://github.com/WebFreak001/code-debug/releases).
2. Unpack mkdir -p ~/.emacs.d/debug-adapters && unzip debug-<version>.vsix -d ~/.emacs.d/debug-adapters/native-debug

See [README](https://github.com/WebFreak001/code-debug) for more information.

The following is a good start at the configuration entry:

    (native-debug
     modes (c-mode c-ts-mode c++-mode c++-ts-mode)
     ensure (lambda (config)
              (dape-ensure-command config)
              (let* ((dap-debug-server-path (car (plist-get config 'command-args)))
                     (type (or (plist-get config :type) "gdb"))
                     (directory (file-name-directory dap-debug-server-path))
                     (file (format "%s.js" type)))
                ;; Determine path based on type
                (setq dap-debug-server-path (file-name-concat directory file))
                (unless (file-exists-p dap-debug-server-path)
                  (user-error "File %S does not exist" dap-debug-server-path))
                (setf (car (plist-get config 'command-args)) dap-debug-server-path)
                ))
     command-cwd dape-command-cwd
     command "node"
     command-args (,(expand-file-name
                     (file-name-concat dape-adapter-dir
                                       "native-debug"
                                       "extension"
                                       "out"
                                       "src"
                                       (string-join
                                        (list
                                         (seq-find 'executable-find '("lldb" "gdb"))
                                         ".js")))))
     fn (lambda (config)
          (when-let ((port (plist-get config 'port))
                     (command-args (plist-get config 'command-args)))
            (plist-put config 'command-args
                       (append command-args
                               (list (format "--server=%s" (prin1-to-string port))))))
          config)
     :type ,(seq-find 'executable-find '("lldb" "gdb"))
     :request "launch"
     :cwd dape-cwd
     :target "a.out"
     :args []
     :stopAtEntry nil)
vibrys commented 2 months ago

interesting with regards to #145 . I'll try it later this week to see how it goes

svaante commented 2 months ago

I am not against adding it but curious as what differentiates Native Debug from gdb, codelldb, lldbdap and cpptools.

Please open an PR and see Contribute, as this is an significant change FSF copy assignment is needed.

vibrys commented 2 months ago

native-debug tells to have command-cwd, which intuitively and according to other adapters (like cpptools) might be the directory where ":target" (binary being debugged?) resides, but IMO the adapter expects to have the target in :cwd, right?

then :cwd cannot be the CWD for application to debug.

also, can arguments passed to application be relative to :cwd?

how to choose between lldb and gdb? cpptools has :MIMode for that for example.

brownts commented 2 months ago

native-debug tells to have command-cwd, which intuitively and according to other adapters (like cpptools) might be the directory where ":target" (binary being debugged?) resides, but IMO the adapter expects to have the target in :cwd, right?

In dape, command-cwd is the CWD used for command (i.e., the Debug Adapter executable -- in this case it's "node", as it's a typescript/javascript application). To specify CWD for the application, use :cwd.

also, can arguments passed to application be relative to :cwd?

Yes. Note that :target is used to specify the application.

how to choose between lldb and gdb? cpptools has :MIMode for that for example.

Use :type. Similarly to how the :MIMode configuration was setup for cpptools, this will try to guess which debugger to use by searching your path. However, you can override that by specifying :type yourself. That is also used to choose the correct native-debug javascript file to run (lldb.js or gdb.js), depending on the value of :type.

svaante commented 2 months ago

@brownts how do you feel about opening up an pr with the addition of native-debug?

brownts commented 1 month ago

@brownts how do you feel about opening up an pr with the addition of native-debug?

Hi @svaante, I don't have FSF paperwork in place, so I don't plan on submitting a PR, at least not anytime soon. If someone else wants to take that on, I'm fine with it. I'm also fine to just leave it in this issue, or even close the issue if you want.