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

Feat: add cortex-debug #647

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions dap-cortex.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
;;; dap-cortex.el --- Debug Adapter Protocol mode for cortex -*- lexical-binding: t; -*-

;; Copyright (C) 2022 Mario Schlegel

;; Author: Mario Schlegel [email protected]
;; Keywords: languages

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;; URL: https://github.com/mrsch/dap-mode
;; Version: 0.1

;;; Commentary:
;; Adapter for https://github.com/Marus/cortex-debug

;;; Code:

(require 'dap-mode)
(require 'dap-utils)

(defcustom dap-cortex-path (expand-file-name "marus25.cortex-debug" dap-utils-extension-path)
"The path to the place at which the webfreak.debug extension."
:group 'dap-cortex
:type 'string)

(defcustom dap-cortex-debug-program `("node" ,(f-join dap-cortex-path "dist/debugadapter.js"))
"The path to the cortex debugger."
:group 'dap-cortex
:type '(repeat string))

(defun dap-cortex--populate-jlink (conf)
"Populate CONF with the required arguments."
(-> conf
(dap--put-if-absent :dap-server-path dap-cortex-debug-program)
(dap--put-if-absent :type "cortex-debug")
(dap--put-if-absent :name "Debug JLink")
(dap--put-if-absent :request "launch")
(dap--put-if-absent :gdbPath "arm-none-eabi-gdb")
(dap--put-if-absent :rttConfig '(:enabled :json-true :address "auto" :decoders [(:label "" :port 0 :type "console")]))
(dap--put-if-absent :gdbServerConsolePort 55878)
(dap--put-if-absent :cwd default-directory)
(dap--put-if-absent :extensionPath (concat dap-cortex-path "/"))
(dap--put-if-absent :preLaunchCommands [])
(dap--put-if-absent :postLaunchCommands [])
(dap--put-if-absent :interface "swd")
(dap--put-if-absent :swoConfig '(:enabled :json-false))
))


(dap-register-debug-provider "cortex-debug" 'dap-cortex--populate-jlink)

(provide 'dap-cortex)
;;; dap-cortex.el ends here
5 changes: 3 additions & 2 deletions dap-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,11 @@ thread exection but the server will log message."
(while (not (string-empty-p chunk))
(if (not (dap--parser-reading-body p))
;; Read headers
(let* ((body-sep-pos (string-match-p "\r\n\r\n" chunk)))
(let* ((body-sep-pos (string-match-p "\r\n\r\n" chunk))
(header-pos (string-match-p "Content-Length" chunk)))
(if body-sep-pos
;; We've got all the headers, handle them all at once:
(let* ((header-raw (substring chunk 0 body-sep-pos))
(let* ((header-raw (substring chunk header-pos body-sep-pos))
(content (substring chunk (+ body-sep-pos 4)))
(headers
(mapcar 'dap--parse-header
Expand Down