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

Native Debug configuration is missing #146

Open
brownts opened this issue Sep 1, 2024 · 6 comments
Open

Native Debug configuration is missing #146

brownts opened this issue Sep 1, 2024 · 6 comments

Comments

@brownts
Copy link

brownts commented Sep 1, 2024

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
Copy link

vibrys commented Sep 2, 2024

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

@svaante
Copy link
Owner

svaante commented Sep 3, 2024

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
Copy link

vibrys commented Sep 6, 2024

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
Copy link
Author

brownts commented Sep 9, 2024

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
Copy link
Owner

svaante commented Sep 11, 2024

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

@brownts
Copy link
Author

brownts commented Sep 15, 2024

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

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

3 participants