ref: b8265c8f266a5cfb54402aa6e52be74c4eff27ce
parent: ad400bef13cb9703064590465eca4413b253b2c9
author: spew <spew@cbza.org>
date: Wed Mar 19 11:32:18 EDT 2025
lsd: cleanup, add documentation
--- a/src/plan9/lsd.lsp
+++ b/src/plan9/lsd.lsp
@@ -87,7 +87,8 @@
(unless (eq? (status) 'Stopped)
(begin (princ "Waiting... " status "\n")
(stop)))
- (cond ((sym? loc) (symbol-addr (get (global-text globals) loc)))
+ (cond ((sym? loc) (symbol-addr
+ (get (global-text globals) loc)))
((num? loc) (u64 loc))
((symbol? loc) (symbol-addr loc))
((str? loc) (filepc loc))
@@ -242,7 +243,7 @@
`(asm)` ; print out 5 from current program instruction.
`(asm 10)` ; print out 10 from current program instruction.
- `(asm 5 (step))` ; step and then print out 5."
+ `(asm 3 (sym-addr 'strecpy))` ; 3 instructions from strecpy"
(for-each (λ (i) (princ (car i) "\t" (cdr i) "\n"))
(asmlist n addr)))
@@ -252,11 +253,9 @@
(lsd-fileline addr))
(def (Bsrc (addr (readreg PC)))
- "Send a plumb message of the filename and line number so
- the source code corresponding to the instruction address
- can be viewed in your text editor.
-
- See the examples for `(src)`, this works the same."
+ "Send a plumb message of the filename and line number
+ corresponding to the instruction address so that the
+ source code can be viewed in your text editor."
(let ((s (src addr))
(plumbf (file "/mnt/plumb/send" :write)))
(io-write plumbf
@@ -268,6 +267,17 @@
(io-close plumbf)))
(def (filepc f (line NIL))
+ "Return the instruction address corresponding to a filename
+ and line number. It is the inverse of (src addr).
+
+ Examples:
+
+ #;> (filepc \"/sys/src/cmd/cat.c:5\")
+ 2097192
+ #;> (filepc \"/sys/src/cmd/cat.c\" 5)
+ 2097192
+ #;> (src 2097192)
+ \"/sys/src/cmd/cat.c:5\""
(if line
(lsd-file2pc f line)
(let ((s (str-split f ":")))
@@ -276,20 +286,30 @@
(unless line (error "bad line number"))
(lsd-file2pc (car s) line)))))
-(def (at-exit s)
- (when proc-stdin (io-close proc-stdin))
- (detach)
- (lsd-cleanup)
- (for-each (λ (p) (princ "echo kill > /proc/" p "/ctl\n")) pids))
-
(def (sym-find s)
+ "Return a symbol from the attached proc's symbol table or NIL.
+ Input is a sym.
+
+ Examples:
+
+ #;> (sym-find 'strecpy)
+ #(symbol \"strecpy\" #\\T 2276784)"
(let* ((find (λ (tbl k) (and (has? tbl k) (get tbl k)))))
(or (find (global-text globals) s)
(find (global-data globals) s))))
-(def (sym-addr s) (symbol-addr (find-sym s)))
+(def (sym-addr s)
+ "Return the address of a symbol from the attached proc's
+ symbol table or NIL. Input is a sym."
+ (symbol-addr (sym-find s)))
-(add-exit-hook at-exit)
+(add-exit-hook
+ (λ (s)
+ (when proc-stdin (io-close proc-stdin))
+ (detach)
+ (lsd-cleanup)
+ (for-each (λ (p) (princ "echo kill > /proc/" p "/ctl\n"))
+ pids)))
(let* ((proc (cadr *argv*))
(pid (str->num proc)))