1

I am new to emacs and I was following this tutorial to configure lsp-mode:

https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/

But dap-debug does not work. Everytime I try to debug, it doesn't stop at any breakpoint and it shows up this message:

1[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-96ov4rxz.d3n" 1>"/tmp/Microsoft-MIEngine-Out-dcuobbae.cqc"


Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
Stopped due to shared library event (no libraries added or removed)

Breakpoint 1, 0x0000555555555169 in main ()
[Inferior 1 (process 19914) exited normally]

I've tried changing the launch template many times but nothing worked.

my init file

(setq package-selected-packages '(lsp-mode yasnippet helm-lsp
                       projectile hydra flycheck company avy which-key helm-xref dap-mode))

(when (cl-find-if-not #'package-installed-p package-selected-packages)
  (package-refresh-contents)
  (mapc #'package-install package-selected-packages))

(which-key-mode)
(add-hook 'prog-mode-hook 'lsp)

(setq gc-cons-threshold (* 100 1024 1024)
      read-process-output-max (* 1024 1024)
      treemacs-space-between-root-nodes nil
      company-idle-delay 0.0
      company-minimum-prefix-length 1
      lsp-idle-delay 0.1)  ;; clangd is fast

(with-eval-after-load 'lsp-mode
  (add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration)
  (require 'dap-cpptools)
  (yas-global-mode))
(tooltip-mode 1)
(dap-ui-controls-mode 1)

(setq lsp-keymap-prefix "C-l")

my launch template:

(dap-register-debug-template
  "cpptools::Run Configuration"
  (list :type "cppdbg"
        :request "launch"
        :name "cpptools::Run Configuration"
        :MIMode "gdb"
        :program "${workspaceFolder}/main"
        :cwd "${workspaceFolder}"))

Things I've already added to launch template:

(dap-register-debug-template
  "MyCdebug"
  (list :type "cppdbg"
        :request "launch"
        :name "MyCdebug"
        :MIMode "gdb"
        :program "${workspaceFolder}/${fileBasenameNoExtension}"
        :dap-compilation "cd '${workspaceFolder}' && gcc ${fileBasename} -o ${fileBasenameNoExtension} -lm -lgmp && '${workspaceFolder}/${fileBasenameNoExtension}'"
        :dap-compilation-dir "${workspaceFolder}"
        :cwd "${workspaceFolder}"
        :args ["-fdiagnostics-color=always -g '${file}' -o '${fileDirname}/${fileBasenameNoExtension}'"]
        :stopOnEntry "false"
        :TargetArchitecture "x86_64"
        :additionalSOLibSearchPath "/lib/x86_64-linux-gnu/"
        :symbolSearchPath "/lib/x86_64-linux-gnu/"))
3
  • Suggest two things: modify the variable :stopOnEntry to true, and then set some breakpoints. Take care the compiler may optimise the code, so in some instances even if you set a breakpoint, it cannot be reached. Another thing is to use a launch.json file in the project root (is that launch.json used in vscode).
    – Ian
    Commented Aug 28, 2022 at 8:19
  • See this: code.visualstudio.com/docs/cpp/config-linux - look for the file launch.json - there are some small inaccuracy in your settings - e.g. you fail to pass the switch -g to compilation, to generate debug symbols; if your file is .cpp, then the compiler call should be g++; at debugger level the parameter "args": should be [], i.e. it refers to arguments passed to main at startup, not arguments for compiling.
    – Ian
    Commented Aug 29, 2022 at 13:14
  • There is an Emacs package compile which can be used for compilation, by default uses make utility, but can be configured for some other commands. I observed that debug templates shown uses a small number of parameters and they be in the specified order, so it is a good idea to use a .json launch file instead, but decision is yours.
    – Ian
    Commented Aug 29, 2022 at 13:15

1 Answer 1

0

As Ian said I needed to pass the -g switch to the compilation, now the breakpoints are working. Thank you.

:dap-compilation "cd '${workspaceFolder}' && gcc ${fileBasename} -o ${fileBasenameNoExtension} -g -lm -lgmp && '${workspaceFolder}/${fileBasenameNoExtension}'"

1
  • Could you expand on your answer to include the code snippet you updated for the benefit of future readers? Thanks!
    – Dan
    Commented Sep 10, 2022 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.