From 77b8a92e034a5cc574a549cd5e7f5453f64461e535e503d8b75a71d534e962f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Bj=C3=B6rnstam?= Date: Fri, 16 Oct 2026 09:35:25 +0200 Subject: [PATCH] Debugging with dape and netcoredbg, and the compiler's new options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit emacs/bjolang-dape.el adds a dape configuration that builds the current file with -d and runs it under netcoredbg, launching dotnet with the program, which is a managed assembly rather than a native host. The README says what a debugger shows today. The check builds its options from Build.dependencyOptions, now that the compiler's options have grown the dump flags. 🤖 Generated with [ECA](https://eca.dev) Co-Authored-By: eca-agent --- Check.fs | 7 +---- README.md | 13 +++++++++ emacs/bjolang-dape.el | 63 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 emacs/bjolang-dape.el diff --git a/Check.fs b/Check.fs index c5ec18a..33f1226 100644 --- a/Check.fs +++ b/Check.fs @@ -98,12 +98,7 @@ let private found (file: string) (d: Diagnostics.Diagnostic) : Found = IsError = isError Message = d.Message + where } -let private options: Build.Options = - { IsLibrary = false - Debug = false - Runtime = [] - EmitCs = None - Check = true } +let private options: Build.Options = { Build.dependencyOptions with IsLibrary = false; Check = true } /// Checks `file` as `bjolang --check` does, reading every file in `buffers`, /// by full path, from there rather than from disk: the editor's unsaved text, diff --git a/README.md b/README.md index 878e7fc..130bd84 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,19 @@ stdout, and logs to stderr. (add-hook 'bjo-mode-hook #'lsp) ``` +`emacs/bjolang-dape.el` debugs a program with `dape` and +[netcoredbg](https://github.com/Samsung/netcoredbg/releases): + +```elisp +(load "/home/linis/Programmering/BjolangLsp/emacs/bjolang-dape.el") +``` + +`M-x dape RET bjolang RET` in a file with a `main` builds it with `-d` and +runs it under the debugger. Breakpoints in the `.bjo` file bind, stepping +goes by its lines, and the call stack names them. The locals are the +generated C#'s, compiler temporaries included, and values show as their C# +types, which expand into their fields. + With eglot instead: ```elisp diff --git a/emacs/bjolang-dape.el b/emacs/bjolang-dape.el new file mode 100644 index 0000000..40c8c1b --- /dev/null +++ b/emacs/bjolang-dape.el @@ -0,0 +1,63 @@ +;;; 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