|
| 1 | +;;; dap-gdb.el --- Debug Adapter Protocol mode for LLDB/GDB -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2019 Ivan Yonchovski |
| 4 | +;; Copyright (C) 2024 Danny Milosavljevic |
| 5 | + |
| 6 | +;; Author: Danny Milosavljevic <[email protected]> |
| 7 | +;; Keywords: languages |
| 8 | + |
| 9 | +;; This program is free software; you can redistribute it and/or modify |
| 10 | +;; it under the terms of the GNU General Public License as published by |
| 11 | +;; the Free Software Foundation, either version 3 of the License, or |
| 12 | +;; (at your option) any later version. |
| 13 | + |
| 14 | +;; This program is distributed in the hope that it will be useful, |
| 15 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +;; GNU General Public License for more details. |
| 18 | + |
| 19 | +;; You should have received a copy of the GNU General Public License |
| 20 | +;; along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 21 | + |
| 22 | +;;; Commentary: |
| 23 | +;; Adapter for GDB version >= 14 |
| 24 | + |
| 25 | +;;; Code: |
| 26 | + |
| 27 | +(require 'dap-mode) |
| 28 | +(require 'dap-utils) |
| 29 | + |
| 30 | +(defcustom dap-gdb-debug-program `("gdb" "-i" "dap") |
| 31 | + "The path to the GDB debugger." |
| 32 | + :group 'dap-gdb |
| 33 | + :type '(repeat string)) |
| 34 | + |
| 35 | +(defun dap-gdb--populate-gdb (conf) |
| 36 | + "Populate CONF with the required arguments." |
| 37 | + (-> conf |
| 38 | + (dap--put-if-absent :dap-server-path dap-gdb-debug-program) |
| 39 | + (dap--put-if-absent :type "gdb") |
| 40 | + (dap--put-if-absent :cwd default-directory) |
| 41 | + ;(dap--put-if-absent :target (expand-file-name (read-file-name "Select file to debug."))) |
| 42 | + (dap--put-if-absent :name "GDB Debug") |
| 43 | + |
| 44 | + (dap--put-if-absent :valuesFormatting "prettyPrinters"))) |
| 45 | + |
| 46 | +(dap-register-debug-provider "gdb" 'dap-gdb--populate-gdb) |
| 47 | +(dap-register-debug-template "GDB Run Configuration" |
| 48 | + (list :type "gdb" |
| 49 | + :request "launch" |
| 50 | + :name "GDB::Run" |
| 51 | + :target nil |
| 52 | + :cwd nil)) |
| 53 | + |
| 54 | +(defun dap-gdb--populate-gdbserver (conf) |
| 55 | + "Populate CONF with the required arguments." |
| 56 | + (-> conf |
| 57 | + (dap--put-if-absent :dap-server-path dap-gdb-debug-program) |
| 58 | + (dap--put-if-absent :type "gdbserver") |
| 59 | + (dap--put-if-absent :name "GDB Server") |
| 60 | + (dap--put-if-absent :request "attach") |
| 61 | + (dap--put-if-absent :gdbpath "gdb") |
| 62 | + (dap--put-if-absent :cwd default-directory) |
| 63 | + (dap--put-if-absent :target (read-string "target?(host:port) ")) |
| 64 | + (dap--put-if-absent :remote :json-true) |
| 65 | + |
| 66 | + (dap--put-if-absent :valuesFormatting "prettyPrinters"))) |
| 67 | + |
| 68 | + |
| 69 | +(dap-register-debug-provider "gdbserver" 'dap-gdb--populate-gdbserver) |
| 70 | +(dap-register-debug-template "GDBServer Connect Configuration" |
| 71 | + (list :type "gdbserver" |
| 72 | + :name "GDBServer::Connect" |
| 73 | + :target nil ;;host:port |
| 74 | + :cwd nil |
| 75 | + :executable nil ;;usually not needed as symbols can be downloaded from gdbserver |
| 76 | + :autorun nil |
| 77 | + :debugger_args nil |
| 78 | + :env nil |
| 79 | + :showDevDebugOutput :json-false |
| 80 | + :printCalls :json-false)) |
| 81 | + |
| 82 | + |
| 83 | +(provide 'dap-gdb) |
| 84 | +;;; dap-gdb.el ends here |
0 commit comments