@@ -242,43 +242,9 @@ you are good to debug dart.
242242 [Flutter debug](https://github.com/emacs-lsp/lsp-dart#flutter) with
243243 options to debug a device or emulator.
244244
245- ## LLDB
245+ ## C and C++
246246
247- 1. Installation
248-
249- LLDB is a debugger that supports, among others, C, C++, Objective-C
250- and Swift.
251-
252- - Clone and follow the instructions to compile lldb-vscode from
253- <https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-vscode>
254-
255- - Put in your emacs configuration.
256-
257- ``` elisp
258- (require ' dap-lldb)
259- ` ` `
260-
261- ** Note** : For proper Swift support, you need to compile LLDB from
262- < https://github.com/apple/swift-lldb> and put the compiled LLDB
263- library/framework in the " extensions" folder.
264-
265- # # vscode-cpptools
266-
267- 1. Installation
268-
269- You only need to run ` dap-cpptools-setup` to setup automatically and then
270- you are good start debugging.
271-
272- - Clone and follow the instructions to compile lldb-vscode from
273- < https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-vscode>
274-
275- - Put in your emacs configuration.
276-
277- ` ` ` elisp
278- (require ' dap-cpptools)
279- ```
280- 2. Usage `dap-debug-edit-template` and select template "cpptools" prefixed
281- configuration.
247+ Please see the [Native Debugging](#native_debugging) section.
282248
283249## Elixir
284250
@@ -341,38 +307,240 @@ the running thread (`dap-switch-thread`) and then `dap-step-in`.
341307 ```
3423083. Run `dap-debug` in a Prolog buffer and start debugging.
343309
344- ## Native Debug (GDB/LLDB )
310+ ## <a name="native_debugging"></a> Native Debuging (C, C++, Rust etc )
345311
346- Using <https://github.com/WebFreak001/code-debug>
312+ There are a number of options for using `dap-mode` with languages which compile
313+ to native code. All of these use the [GDB](https://sourceware.org/gdb/) or
314+ [LLDB](https://lldb.llvm.org/) debuggers in one way or another.
347315
348- 1. Configuration
316+ ### `dap-gdb`
349317
350- For easier of setting up vscode extension, you only need call
351- `dap-gdb-lldb-setup` after requiring `dap-gdb-lldb`.
318+ This package requires GDB version 14 or later. It communicates directly with the
319+ debugger using DAP JSON (without the need for an adapter layer), and there is no
320+ directly equivalent VSCode extension.
352321
353- Or download and extract [VSCode
354- extension](https://marketplace.visualstudio.com/items?itemName=webfreak.debug)
355- (make sure that `dap-gdb-lldb-path` is pointing to the extract
356- location).
322+ This package registers two types of debugger:
323+
324+ * `:type "gdb"`
325+ * `:type "gdbserver"`
326+
327+ The latter allows debugging of programs which are running (usually remotely)
328+ under the
329+ [`gdbserver`](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Server.html)
330+ program.
331+
332+ 1. Installation
333+
334+ Please ensure that you have GDB version 14 or later installed on your
335+ system, and add the following line to your Emacs setup:
336+ ``` elisp
337+ (require ' dap-gdb)
338+ ` ` `
339+ If ` gdb` is not on your ` PATH` , set or customize ` dap-gdb-debug-program` with
340+ the flags requried to start it in DAP mode, e.g.:
341+ ` ` ` elisp
342+ (setq dap-gdb-debug-program ' ("/path/to/gdb" "-i" "dap"))
343+ ```
344+
345+ 2. Usage
346+
347+ Create a configuration with <kbd>M-x</kbd> `dap-debug-edit-template`, using
348+ either "GDB Run Configuration" or "GDBServer Connect Configuration" as the
349+ base settings. See the [GDB
350+ documentation](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Debugger-Adapter-Protocol.html)
351+ for full descriptions of launch configuration options.
352+
353+ **Note** you must set the `:program` property in your debug template,
354+ otherwise you will get an error when the debugger attempts to execute your
355+ source file.
356+
357+ ### `dap-lldb`
358+
359+ LLDB is a debugger that supports, among others, C, C++, Objective-C and
360+ Swift. LLDB supports direct communication with the debugger using DAP JSON,
361+ without an adapter layer, similar to newer versions of GDB. Unlike GDB, the DAP
362+ server is provided by a separate binary which ships with the main LLDB command
363+ tool. The binary is called `lldb-vscode` on older versions, and is called
364+ `lldb-dap` since version 18.
365+
366+ This package registers a single debugger type:
367+
368+ * `:type lldb-vscode`
369+
370+ The official VSCode extension is [LLDB
371+ DAP](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap),
372+ although it is not necessary to install this to use `dap-lldb` in Emacs.
373+
374+ 1. Installation
375+
376+ Ensure that you have the command-line program `lldb-dap` (or `lldb-vscode`)
377+ installed on your system. If you want to build the tool from scratch, clone
378+ and follow the instructions to compile lldb-dap from:
379+
380+ <https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-dap>
381+
382+ **Note**: For proper Swift support, you need to compile LLDB from
383+ <https://github.com/apple/swift-lldb>.
384+
385+ Then put the following in your emacs configuration:
386+ ``` elisp
387+ (require ' dap-lldb)
388+ ` ` `
389+
390+ This package expects to find the ` lldb-vscode` program in the extensions
391+ folder used by VSCode. If you have this installed elsewhere, or are using
392+ the more modern ` lldb-dap` version, you will need to set or customize
393+ ` dap-lldb-debug-program` appropriately:
357394
395+ ` ` ` elisp
396+ (setq dap-lldb-debug-program ' ("/path/to/lldb-dap"))
397+ ```
398+
399+ 2. Usage
400+
401+ Create a configuration with <kbd>M-x</kbd> `dap-debug-edit-template`,
402+ selecting the template prefixed "LLDB (VS Code)" for the base
403+ settings. Detailed descriptions of the launch configuration options are
404+ provided in the [LLDB DAP
405+ README](https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-dap). Remember
406+ to set the `:program` property to the path to the binary you wish to debug.
407+
408+
409+ ### `dap-cpptools`
410+
411+ This package utilizes the official Microsoft extension [VSCode
412+ CPPTools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools),
413+ which ships with a debug adapter which translates DAP JSON into GDB' s [Machine
414+ Interface (MI)
415+ protocol](https://sourceware.org/gdb/current/onlinedocs/gdb.html/GDB_002fMI.html),
416+ (used by many debugger GUIs, including Emacs' built-in gud debugger). It
417+ therefore works with older versions of GDB which do not support the DAP protocol
418+ directly. The adapter is written in C# and is called
419+ [OpenDebugAD7](https://github.com/microsoft/MIEngine/wiki/Architecture-of-OpenDebugAD7). The
420+ installation steps below will install this program as an executable binary on
421+ your system, so it can be used by this package.
422+
423+ This package registers a single debugger type:
424+
425+ * `:type cpptools`
426+
427+ which uses the OpenDebugAD7 adapter to run GDB debugging sessions.
428+
429+ 1. Installation
430+
431+ Add the following to your Emacs configuration:
432+ ``` elisp
433+ (require ' dap-cpptools)
434+ ` ` `
435+
436+ A one-time step is required to download the extension and set it up
437+ automatically - < kbd> M-x< /kbd> ` dap-cpptools-setup` - then you are good
438+ start debugging. Note that this will download the extension from the address
439+ specified in ` dap-cpptools-download-url` , which is by default set to a
440+ specific release under
441+ < https://github.com/microsoft/vscode-cpptools/releases> .
442+
443+ The location of the OpenDebugAD7 binary is specified by
444+ ` dap-cpptools-debug-program` , which can be customized if needed.
445+
446+ 2. Usage
447+
448+ Run < kbd> M-x< /kbd> ` dap-debug-edit-template` and select the " cpptools"
449+ prefixed template as a base. Additional configuration options are documented
450+ on the extension' s [official
451+ page](https://code.visualstudio.com/docs/cpp/launch-json-reference).
452+
453+
454+ ### `dap-gdb-lldb`
455+
456+ This package uses the VSCode extension [WebFreak Native
457+ Debug](https://marketplace.visualstudio.com/items?itemName=webfreak.debug). This
458+ extension is written in Typescript and implements a DAP JSON to MI
459+ translation layer, similar to the CPPTools extension. The extension advertizes
460+ support for both GDB and LLDB - LLDB support requires the additional binary
461+ `lldb-mi`; to install this follow the instructions in the link above.
462+
463+ This package registers several debugger types:
464+
465+ * `:type gdb`
466+ * `:type gdbserver`
467+ * `:type lldb-mi`
468+
469+ Note that the first two conflict with the types registered by the `dap-gdb`
470+ package, so you must avoid adding both `dap-gdb` and `dap-gdb-lldb` to your
471+ Emacs configuration.
472+
473+ The source code for the extension may be found at
474+ <https://github.com/WebFreak001/code-debug>.
475+
476+ 1. Installation
477+
478+ Add the following to your Emacs configuration:
358479 ``` elisp
359480 (require ' dap-gdb-lldb)
360481 ` ` `
361482
362- Then do ` dap-debug` or ` dap-debug-edit-template` and selet GBD or
363- LLDB configuration.
364-
365- # ## Rust
366- To fully support rust and pretty printing of strings when debugging, remember to add set ` gdbpath` to ` rust-gdb` in your debug template. An example template would be
483+ If you do not have the VSCode extension installed already, you can install it with
484+ < kbd> M-x< /kbd> ` dap-gdb-lldb-setup` . Or download and extract [VSCode
485+ extension](https://marketplace.visualstudio.com/items? itemName=webfreak.debug)
486+ (make sure that ` dap-gdb-lldb-path` is pointing to the extract
487+ location).
488+
489+ You will also need to have [NodeJS](https://nodejs.org/) installed on your
490+ system, to run the adapter.
491+
492+ 2. Usage
493+
494+ Run < kbd> M-x< /kbd> ` dap-debug-edit-template` and select one of the following
495+ base templates, depending on your needs:
496+
497+ * " GDB Run Configuration"
498+ * " GDBServer Connect Configuration"
499+ * " LLDB Run Configuration"
500+
501+ See the project' s [README](https://github.com/WebFreak001/code-debug) for
502+ additional documentation on the launch configurations. **Note** - be sure to
503+ set the working directory (`:cwd` property) to an absolute path - the
504+ default may insert a tilde (~) shortcut for your home directory (which the
505+ adapter does not understand) and this will cause a launch failure with a
506+ misleading error message questioning the existence of the target binary.
507+
508+ ## Rust
509+
510+ First, please see the [Native Debugging](#native_debugging) section.
511+
512+ The rustup tool (at least for the x86_64 toolchain) provides additional
513+ configuration for both GDB and LLDB to provide pretty-printers for standard Rust
514+ types. The most straightforward way to use this functionality is to configure
515+ the debug adapters to pick up these scripts rather than the debugger
516+ directly. For `dap-gdb`, you can configure the GDB debug program as follows
517+ (assuming `~/.cargo/bin` is in your `$PATH`):
367518
368519```elisp
369- (dap-register-debug-template " Rust::GDB Run Configuration"
370- (list :type " gdb"
371- :request " launch"
372- :name " GDB::Run"
373- :gdbpath " rust-gdb"
374- :target nil
375- :cwd nil))
520+ (setq dap-gdb-debug-program ' (" rust-gdb" " -i" " dap" ))
521+ ` ` `
522+
523+ For the MI debug adapters, you can supply the debugger program as part of the
524+ launch configuration - for ` dap-cpptools` the relevant property is
525+ ` :miDebuggerPath` , and for ` dap-gdb-lldb` it is ` :gdbpath` .
526+
527+ Another way to enable pretty-printing is to specify the relevant configuration
528+ steps as part of the launch intialization (and this is the only option for
529+ ` dap-lldb` ). Looking at the ` rust-lldb` script in
530+ ` ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin` , we see that it
531+ sources a python file to define the pretty printers, and then a command file to
532+ register them. The same things can be done as an initialization step when
533+ launching the DAP debugger, for example:
534+
535+ ` ` ` elisp
536+ (dap-register-debug-template
537+ " MyProgram"
538+ (list :type " lldb-vscode"
539+ :initCommands ' ("command script import ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/etc/lldb_lookup.py"
540+ "command source ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/etc/lldb_commands")
541+ :request "launch"
542+ ...
543+ ))
376544```
377545
378546## Go
0 commit comments