shithub: sl

Download patch

ref: cd06d114f5b0c2ec8f99e0f9481347ca1ae25fad
parent: e6f027b15cd680bee3447bbb96256fa8d9909030
author: spew <spew@cbza.org>
date: Fri Mar 21 15:07:27 EDT 2025

lsd: implement line and over

--- a/src/plan9/lsd.lsp
+++ b/src/plan9/lsd.lsp
@@ -94,7 +94,7 @@
 
 (def (oct n) (str "0" (num->str n 8)))
 
-(def (readbp a) (readcore a 'byte (length bpinst)))
+(def (bpsave a) (readcore a 'byte (length bpinst)))
 
 (let ((bp_init (λ (loc)
                  (when (< pid 0) (error "no running process"))
@@ -111,7 +111,7 @@
                 (let ((addr (bp_init loc)))
                   (when (has? bptbl addr)
                         (error "breakpoint already set at " loc))
-                  (put! bptbl addr (readbp addr))
+                  (put! bptbl addr (bpsave addr))
                   (writecore addr bpinst))))
   (set! bpdel (λ (loc)
                 (let ((addr (bp_init loc)))
@@ -223,7 +223,7 @@
              (on-bp (has? bptbl addr)))
         (when on-bp (writecore addr (get bptbl addr)))
         (let* ((f (follow addr))
-               (o (map readbp f)))
+               (o (map bpsave f)))
           (for-each (λ (a) (writecore a bpinst)) f)
           (startstop)
           (map writecore f o)
@@ -241,12 +241,33 @@
 (def (func)
   "Continue program execution until the current function returns."
   (let* ((bp (frame-retpc (car (_stk))))
-         (o (readbp bp)))
+         (o (bpsave bp)))
     (writecore bp bpinst)
     (cont)
     (writecore bp o))
   (curPC))
 
+(def (line)
+  "Step one line of the source code.
+
+   This fuction will step into functions not over."
+  (let ((orig (src)))
+    (def (go)
+      (step)
+      (if (not (equal? orig (src)))
+          (curPC)
+          (go)))
+    (go)))
+
+(def (over)
+  "Step one line of source code, going over a function call, not in"
+  (let ((f (car (_stk))))
+    (line)
+    (if (equal? f (car (_stk)))
+        (curPC)
+        (begin (func)
+               (line)))))
+
 (def (asmlist (n 5) (addr (curPC)))
   "Return a list of the next `n` disassembled instructions starting at `addr`.
 
@@ -292,6 +313,17 @@
                    (length s)
                    "\n" s))
     (io-close plumbf)))
+
+(def (Bline)
+  "Step forward one line of source code and then plumb the
+   new line (make a bee line) to your editor."
+  (line)
+  (Bsrc))
+
+(def (Bover)
+  "Same as Bline but with `over`"
+  (over)
+  (Bsrc))
 
 (def (filepc f (line NIL))
   "Return the instruction address corresponding to a filename