ref: 4f0538a0ae8bc62d076cfd5c60885fe66179e178
parent: 00026fb68973917c1263fb945182fde95381338f
author: spew <spew@cbza.org>
date: Sun Mar 23 20:14:56 EDT 2025
lsd: start implementation of (stk), add documentation
--- a/src/plan9/lsd.sl
+++ b/src/plan9/lsd.sl
@@ -1,16 +1,30 @@
#!/bin/sl -i
-(defstruct reg name type addr size)
-(defstruct symbol name type addr)
+(defstruct reg
+ "A register of the process. The fields are internal. To read the
+ value of a register use `readreg`"
+ :doc-group lsd
+ :doc-see readreg
+ name type addr size)
+(defstruct symbol
+ "A symbol of the process. Name is a string denoting the symbol,
+ type is a character as described in a.out(6), and address is the
+ location of the symbol in the process address space"
+ :doc-group lsd
+ name type addr)
(defstruct global
"All the global symbols, separated into text and data symbols.
The text and data fields are both tables from syms to symbols."
+ :doc-group lsd
+ :doc-see symbol
text data)
(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."
+ :doc-group lsd
+ :doc-see symbol
loc retpc sp locals)
(def coref NIL)
@@ -188,7 +202,25 @@
(def ctrace (get tracers (os-getenv "objtype")))
-(def (_stk) (reverse! (ctrace)))
+(def (_stk)
+ "Return the call stack in the form of a list of stack frames."
+ :doc-group lsd
+ :doc-see frame
+ (reverse! (ctrace)))
+
+(def (stk)
+ "Pretty print the stack trace without showing locals. Still WIP."
+ :doc-group lsd
+ :doc-see _stk
+ (def (go f)
+ (receive (params autos)
+ (partition (λ (x) (equal? #\p (symbol-type x)))
+ (frame-locals f))
+ (set! params (sort params #.< :key symbol-addr))
+ (set! autos (sort autos #.> :key symbol-addr))
+ (princ (symbol-name (frame-loc f))
+ "(" params ")\n")))
+ (for-each go (_stk)))
(def (curPC) (and (>= pid 0) (readreg PC)))