this post was submitted on 30 Nov 2023
1 points (100.0% liked)

Emacs

310 readers
2 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

I have been trying to get dap-mode for c++ to work. Below is my config related to dap-mode

(use-package dap-mode
  :after lsp-mode
  :commands dap-debug
  :hook ((c++-mode python-mode . dap-ui-mode) (python-mode . dap-mode))
  :config
  (dap-auto-configure-mode t)

  (setq dap-python-debugger 'debugpy)
  (require 'dap-python)

  (require 'dap-gdb-lldb)
  (require 'dap-lldb)
  (setq dap-lldb-debug-program "/usr/bin/lldb-vscode")
;;; ask user for executable to debug if not specified explicitly (c++)
  (setq dap-lldb-debugged-program-function (lambda () (read-file-name "Select file to debug.")))

  ;;; default debug template for (c++)
  (dap-register-debug-template
   "C++ LLDB dap"
   (list :type "lldb-vscode"
         :cwd nil
         :args nil
         :request "launch"
         :program nil))
;; (defun dap-python--pyenv-executable-find (command)
;;   (with-venv (executable-find "python")))

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

(defun dap-debug-create-or-edit-json-template ()
    "Edit the C++ debugging configuration or create + edit if none exists yet."
    (interactive)
    (let ((filename (concat (lsp-workspace-root) "/launch.json"))
	  (default "~/.config/emacs/default-launch.json"))
      (unless (file-exists-p filename)
	(copy-file default filename))
      (find-file-existing filename))))

The problem I am facing currently is that every time i run

dap-debug

while the file is open i get prompted for executable and when i select the candidate, I get the error

Wrong type argument: stringp, nil

From what I learned we get the above error when a function get a nil value while expecting a string but I don't understand why the function will get a nil value when i selected the correct executable with appropriate compiler flags.

I would appreciate any help in the matter.

top 2 comments
sorted by: hot top controversial new old
[–] yyoncho@alien.top 1 points 11 months ago

M-x toggle-debug-on-error

[–] sammymammy2@alien.top 1 points 11 months ago

gdb also has DAP nowadays. I'd also try to get a full backtrace (enable elisp debugging).

If you grow tired of trying to use DAP then I'd suggest using gdb in conjunction with gf2: https://github.com/nakst/gf

gf2 is an extremely fast front-end for gdb.