shithub: sl

Download patch

ref: ed6d23fde034ef52f179822318dd96ba6039a9e4
parent: daf109ca9fc190db105b7dc75e2bd84c13dba312
author: spew <spew@cbza.org>
date: Sun Apr 6 16:27:32 EDT 2025

lsd: fix symbol-addr mistakes, add more documentation

--- a/src/plan9/lsd.sl
+++ b/src/plan9/lsd.sl
@@ -147,22 +147,35 @@
   `(core-read (symbol-addr ,symbol) ,.rest))
 
 (def (str->symbol s)
+  "Return a symbol, searching first in the local stack frame then
+   in the global symbol table.
+
+   Input is a string."
+  :doc-see str->addr
+  :doc-group lsd
   (or (local-symbol s)
       (global-symbol s)))
 
 (def (str->addr s (:str->symbol str->symbol))
-  "Return the address corresponding to a source code line or symbol.
-  
+  «Return the address corresponding either to a source code line or
+   symbol.
+
    Input is a string.  By default str->symbol is used to lookup
    symbols in the local stack frame and then the global text and data
-   symbol tables."
+   symbol tables.
+
+   Examples:
+
+       (str->addr "strecpy") → 2276985; look up a symbol
+       (str->addr "/sys/src/cmd/ls.c:75") → 2097311; source code address»
   :doc-see loc->addr
   :doc-see str->symbol
+  :doc-see filepc
   :doc-group lsd
   (trycatch
     (filepc s)
     (λ (e) (when (eq? (car e) 'io-error) (raise e))
-           (let {[symb (symbol-addr (str->symbol s))]}
+           (let {[symb (str->symbol s)]}
              (if symb
                  (symbol-addr symb)
                  (error "could not find symbol " s))))))
@@ -181,6 +194,7 @@
    By default str->symbol is used to find the corresponding symbol
    which searches the local call stack then global text symbols then
    global data symbols.»
+  :doc-see str->addr
   (cond ((str? loc) (str->addr loc :str->symbol str->symbol))
         ((num? loc) (ptr loc))
         ((symbol? loc) (symbol-addr loc))
@@ -205,7 +219,7 @@
   :doc-see loc->addr
   :doc-see bpdel
   :doc-group lsd
-  (def (txtsymb s) (symbol-addr (global-symbol s :text T)))
+  (def (txtsymb s) (global-symbol s :text T))
   (waitstop)
   (let {[addr (loc->addr loc :str->symbol txtsymb)]}
     (when (has? bptbl addr)
@@ -220,7 +234,7 @@
   :doc-see loc->addr
   :doc-see bpdel
   :doc-group lsd
-  (def (txtsymb s) (symbol-addr (global-symbol s :text T)))
+  (def (txtsymb s) global-symbol s :text T))
   (waitstop)
   (let {[addr (loc->addr loc :str->symbol txtsymb)]}
     (unless (has? bptbl addr)