;;; .doomrc --- doom runtime config -*- mode: emacs-lisp; lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'doom) ; be silent, byte-compiler

(after! dape
        (add-to-list
        'dape-configs
        `(gdb-dap-openocd
        ,@(alist-get 'gdb-dap dape-configs)
        fn (lambda (config)
                (let* ((default-directory (dape--guess-root config))
                (openocd
                        ;; Run openocd with config files from `openocd-files' property
                        (start-process-shell-command
                        "openocd" "*openocd*"
                        (concat "openocd"
                                (mapconcat (lambda (file)
                                        (concat " -f " (shell-quote-argument file)))
                                        (append (dape-config-get config 'openocd-files) nil)))))
                probe)
                ;; Wait until port is open
                (while (and (process-live-p openocd)
                        (not (setq probe (ignore-errors
                                                (make-network-process :name "openocd port probe"
                                                                :service 3333)))))
                (sleep-for 0.1))
                ;; Close probe connection
                (when probe
                (delete-process probe)))
                config)
        openocd-files ["openocd.cfg"]
        :initCommands ["target remote 10.128.5.10:3333"
                        "monitor reset halt"]
        :exitCommands ["monitor shutdown"]
        :terminateCommands ["monitor shutdown"]))
)

;;; .doomrc ends here
