History

lsd: add (lstk), add a target to install lsd

spew committed 1 year ago

Commit 415ef9f1 parent 3d331f32 files · +29 −10Browse files

Unified · Split

2 files
  1. mkfile +3 −0
  2. src/plan9/lsd.sl +26 −10
mkfile+3−0
@@ -121,3 +121,6 @@ clean:V: · 120 unmodified lines
121121
122122 nuke:V:
123123 mk clean
124+
125+lsd:V:
126+ cp src/plan9/lsd.sl /rc/bin/lsd
src/plan9/lsd.sl+26−10
@@ -29,12 +29,12 @@ · 28 unmodified lines
2929 :doc-see symbol
3030 text data)
3131 (defstruct frame
32− "A stack frame. Loc is the enclosing function symbol and instruction
32+ "A stack frame. Sym is the enclosing function symbol and instruction
3333 address of the frame. Retpc is the return instruction address. Sp is
3434 the stack pointer value. Locals are all the local symbols."
3535 :doc-group lsd
3636 :doc-see symbol
37− loc retpc sp locals)
37+ sym retpc sp locals)
3838
3939 (def coref NIL)
4040 (def textf NIL)
@@ -222,33 +222,41 @@ · 181 unmodified lines
222222 :doc-see frame
223223 (reverse! (ctrace)))
224224
225−(def (stk)
226− "Print the stack trace without showing local auto values.
225+(def (stk (:locals NIL))
226+ "Print the stack trace optionally showing local auto values.
227227
228228 Bugs:
229229
230− Prints the values of parameters as unsigned 64 bit
231− integers, not as their actual types."
230+ Prints the values of parameters and autos as unsigned
231+ 64 bit integers, not as their actual types."
232232 :doc-group lsd
233233 :doc-see _stk
234+ :doc-see lstk
234235 (def (go pc fs)
235236 (if (not fs) pc
236237 (let* {[f (car fs)]
237− [floc (frame-loc f)]}
238+ [fsym (frame-sym f)]}
238239 (receive (params autos)
239240 (partition (λ (x) (equal? #\p (symbol-type x)))
240241 (frame-locals f))
241242 (set! params (sort params #.< :key symbol-addr))
242243 (set! autos (sort autos #.> :key symbol-addr))
243− (princ (symbol-name floc) "(")
244+ (princ (symbol-name fsym) "(")
244245 (princ
245246 (str-join
246247 (map (λ (p)
247248 (str (symbol-name p) "=" (hex (symbol-read p 'u64))))
248249 params)
249250 ", "))
250− (princ ")+" (hex (- pc (symbol-addr floc))) " ")
251+ (princ ")+" (hex (- pc (symbol-addr fsym))) " ")
251252 (princ (src pc) "\n")
253+ (when locals
254+ (for-each (λ (l) (princ " "
255+ (symbol-name l)
256+ "="
257+ (hex (symbol-read l 'u64))
258+ "\n"))
259+ autos))
252260 (go (frame-retpc f) (cdr fs))))))
253261 (let* {[tos (go (curPC) (_stk))]
254262 [topsym (lsd-findsym tos)]}
@@ -259,6 +267,13 @@ · 4 unmodified lines
259267 (src tos)
260268 "\n")))
261269
270+(def (lstk)
271+ "Print the stack trace showing local auto values."
272+ :doc-group lsd
273+ :doc-see _stk
274+ :doc-see stk
275+ (stk :locals T))
276+
262277 (def (curPC) (and (>= pid 0) (readreg PC)))
263278
264279 (def (step (n 1))
@@ -371,7 +386,8 @@ · 106 unmodified lines
371386 (path-cwd)
372387 "\ntext\n\n"
373388 (length s)
374− "\n" s))
389+ "\n"
390+ s))
375391 (io-close plumbf)))
376392
377393 (def (B stepper)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t