shithub: sl

Download patch

ref: f8093f8e32ba6ef75cbdcefb40834a1a3b85a1da
parent: b3618d54e387bd8600dfa432f0007a9b97111edc
author: spew <spew@cbza.org>
date: Mon Mar 17 23:39:46 EDT 2025

lsd: add lsd-fileline and document bpset, bpdel

--- a/src/plan9/lsd.c
+++ b/src/plan9/lsd.c
@@ -379,6 +379,21 @@
 	return r;
 }
 
+BUILTIN("lsd-fileline", lsd_fileline)
+{
+	static char buf[1024];
+	uvlong addr;
+
+	argcount(nargs, 1);
+	if(sl_unlikely(!sl_isnum(args[0])))
+		type_error("num", args[0]);
+
+	addr = tosize(args[0]);
+	if(!fileline(buf, sizeof(buf), addr))
+		lerrorf(sl_errio, "could not get locate source code line at %ud", addr);
+	return str_from_cstr(buf);
+}
+
 BUILTIN("lsd-ctrace", lsd_ctrace)
 {
 	sl_v *a;
--- a/src/plan9/lsd.lsp
+++ b/src/plan9/lsd.lsp
@@ -102,6 +102,36 @@
                   (writecore addr (get bptbl addr))
                   (del! bptbl addr)))))
 
+(doc-for bpset
+  "Set a breakpoint.
+
+   The location can either be a symbol, in which case
+   the address will be retrieved from the global text symbols
+   of the process, or an integer which is the address at which
+   to place the break.
+
+   Examples:
+     (bpset 'strcpy) ; breakpoint on strcpy function.
+     (bpset (readreg PC)) ; breakpoint on current instruction.
+
+   Signature:
+     (bpset loc)")
+
+(doc-for bpdel
+  "Delete a breakpoint.
+
+   The location can either be a symbol, in which case
+   the address will be retrieved from the global text symbols
+   of the process, or an integer which is the address at which
+   to remove the break.
+
+   Examples:
+     (bpdel 'strcpy) ; remove breakpoint on strcpy function.
+     (bpdel (readreg PC)) ; remove breakpoint on current instruction.
+
+   Signature:
+     (bpdel loc)")
+
 (def (detach)
   (if regsf (io-close regsf))
   (if fpregsf (io-close fpregsf))
@@ -147,6 +177,7 @@
     (caddr stats)))
 
 (def tracers (table
+  "386"   (λ () (lsd-ctrace (readreg PC) (readreg SP) (u64 0)))
   "amd64" (λ () (lsd-ctrace (readreg PC) (readreg SP) (u64 0)))
   "arm64" (λ () (lsd-ctrace (readreg PC) (readreg SP) (readreg R30)))))
 
@@ -155,6 +186,8 @@
 (def (curPC) (if (>= pid 0) (readreg PC)))
 
 (def (step)
+  "Step one assembly instruction. Returns the next instruction
+   address to be executed or void if the program has exited."
   (let* ((addr (readreg PC))
          (on-bp (has? bptbl addr)))
     (if on-bp (writecore addr (get bptbl addr)))
@@ -167,6 +200,8 @@
       (or (curPC) (void)))))
 
 (def (cont)
+  "Continue program execution. Returns the next instruction
+   address to be executed or void if the program has exited."
   (let ((addr (readreg PC)))
     (if (has? bptbl addr) (step))
     (startstop)
@@ -176,7 +211,7 @@
   "Print the next n disassembled instructions at addr.
 
    By default n is 5 and it returns the following instruction
-   so it can be called again.
+   address so it can be called again.
 
    Examples:
      (asm (readreg PC)) ; print out 5 from current program instruction.