ref: 13bcf7653e5ab5578b39662b4fb6b1e8a5c54b6b
parent: 96fa385727991e81a3c0d97b80720836551c8572
author: spew <spew@cbza.org>
date: Fri Mar 21 12:47:16 EDT 2025
lsd: add func, add documentation
--- a/src/plan9/lsd.lsp
+++ b/src/plan9/lsd.lsp
@@ -3,9 +3,15 @@
(defstruct reg name type addr size)
(defstruct symbol name type addr)
(defstruct global
- "All the global symbols, separated into text and data symbols."
+ "All the global symbols, separated into text and data symbols.
+
+ The text and data fields are both tables from syms to symbols."
text data)
-(defstruct frame loc retpc sp locals)
+(defstruct frame
+ "A stack frame. Loc is the enclosing function symbol and instruction
+ address of the frame. Retpc is the return instruction address.
+ Sp is the stack pointer value. Locals are all the local symbols."
+ loc retpc sp locals)
(def coref NIL)
(def textf NIL)
@@ -12,7 +18,7 @@
(def regsf NIL)
(def fpregsf NIL)
(def proc-stdin NIL)
-(def pids ())
+(def pids NIL)
(def bptbl (table))
(def (procfile s . flags)
@@ -88,6 +94,8 @@
(def (oct n) (str "0" (num->str n 8)))
+(def (readbp a) (readcore a 'byte (length bpinst)))
+
(let ((bp_init (λ (loc)
(when (< pid 0) (error "no running process"))
(unless (eq? (status) 'Stopped)
@@ -103,7 +111,7 @@
(let ((addr (bp_init loc)))
(when (has? bptbl addr)
(error "breakpoint already set at " loc))
- (put! bptbl addr (readcore addr 'byte (length bpinst)))
+ (put! bptbl addr (readbp addr))
(writecore addr bpinst))))
(set! bpdel (λ (loc)
(let ((addr (bp_init loc)))
@@ -199,7 +207,10 @@
(def ctrace (get tracers (os-getenv "objtype")))
-(def (_stk) (reverse (ctrace)))
+(def (_stk)
+ (reverse!
+ (map (λ (f) (frame-locals f (reverse! (frame-locals f))) f)
+ (ctrace))))
(def (curPC) (and (>= pid 0) (readreg PC)))
@@ -212,7 +223,7 @@
(on-bp (has? bptbl addr)))
(when on-bp (writecore addr (get bptbl addr)))
(let* ((f (follow addr))
- (o (map (λ (a) (readcore a 'byte (length bpinst))) f)))
+ (o (map readbp f)))
(for-each (λ (a) (writecore a bpinst)) f)
(startstop)
(map writecore f o)
@@ -226,6 +237,15 @@
(when (has? bptbl addr) (step))
(startstop)
(curPC)))
+
+(def (func)
+ "Continue program execution until the current function returns."
+ (let* ((bp (frame-retpc (car (_stk))))
+ (o (readbp bp)))
+ (writecore bp bpinst)
+ (cont)
+ (writecore bp o))
+ (curPC))
(def (asmlist (n 5) (addr (curPC)))
"Return a list of the next `n` disassembled instructions starting at `addr`.