;;; bjolang-dape.el --- Debugging Bjolang programs with dape and netcoredbg -*- lexical-binding: t; -*- ;;; Commentary: ;; `M-x dape RET bjolang RET' in a Bjolang buffer builds the file with `-d' ;; and runs it under netcoredbg. A breakpoint set in the `.bjo' file binds, ;; stepping goes by its lines, and the call stack names them: the compiler ;; maps the generated C# back to the source with `#line', and a debug build ;; writes that mapping into the program's PDB. ;; ;; The file has to be a program, one with a `main'. The program is a ;; managed assembly that `dotnet' runs, so that is what netcoredbg is told ;; to start, with the program as its argument. ;; ;; netcoredbg: https://github.com/Samsung/netcoredbg/releases, unpacked so ;; that `bjo-netcoredbg' names the executable. ;;; Code: (defgroup bjolang-dape nil "Debugging Bjolang programs." :group 'tools) (defcustom bjo-compiler "~/Programmering/Bjolang/bin/compiler/Bjolang.dll" "The Bjolang compiler, as `build_compiler.sh --path' prints it." :type 'file) (defcustom bjo-netcoredbg "~/.local/share/netcoredbg/netcoredbg" "The netcoredbg executable." :type 'file) (defun bjo--dape-source () "The Bjolang file a debug session is started from." (or (buffer-file-name) (user-error "Not visiting a Bjolang file"))) (defun bjo--dape-program () "The program a debug build of the current file produces." (concat (file-name-sans-extension (bjo--dape-source)) ".exe")) (defun bjo--dape-compile-command () "The debug build of the current file." (format "dotnet %s -d %s" (shell-quote-argument (expand-file-name bjo-compiler)) (shell-quote-argument (bjo--dape-source)))) (with-eval-after-load 'dape (add-to-list 'dape-configs `(bjolang modes (bjo-mode) command ,(expand-file-name bjo-netcoredbg) command-args ["--interpreter=vscode"] compile bjo--dape-compile-command :request "launch" :type "coreclr" :cwd (lambda () (file-name-directory (bjo--dape-source))) :program "dotnet" :args [bjo--dape-program] :justMyCode t :stopAtEntry nil))) (provide 'bjolang-dape) ;;; bjolang-dape.el ends here