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
121 121
122nuke:V:122nuke:V:
123 mk clean123 mk clean
124
125lsd:V:
126 cp src/plan9/lsd.sl /rc/bin/lsd
src/plan9/lsd.sl+26−10
@@ -29,12 +29,12 @@ · 28 unmodified lines
29 :doc-see symbol29 :doc-see symbol
30 text data)30 text data)
31(defstruct frame31(defstruct frame
32 "A stack frame. Loc is the enclosing function symbol and instruction32 "A stack frame. Sym is the enclosing function symbol and instruction
33 address of the frame. Retpc is the return instruction address. Sp is33 address of the frame. Retpc is the return instruction address. Sp is
34 the stack pointer value. Locals are all the local symbols."34 the stack pointer value. Locals are all the local symbols."
35 :doc-group lsd35 :doc-group lsd
36 :doc-see symbol36 :doc-see symbol
37 loc retpc sp locals)37 sym retpc sp locals)
38 38
39(def coref NIL)39(def coref NIL)
40(def textf NIL)40(def textf NIL)
@@ -222,33 +222,41 @@ · 181 unmodified lines
222 :doc-see frame222 :doc-see frame
223 (reverse! (ctrace)))223 (reverse! (ctrace)))
224 224
225(def (stk)225(def (stk (:locals NIL))
226 "Print the stack trace without showing local auto values.226 "Print the stack trace optionally showing local auto values.
227 227
228 Bugs:228 Bugs:
229 229
230 Prints the values of parameters as unsigned 64 bit230 Prints the values of parameters and autos as unsigned
231 integers, not as their actual types."231 64 bit integers, not as their actual types."
232 :doc-group lsd232 :doc-group lsd
233 :doc-see _stk233 :doc-see _stk
234 :doc-see lstk
234 (def (go pc fs)235 (def (go pc fs)
235 (if (not fs) pc236 (if (not fs) pc
236 (let* {[f (car fs)]237 (let* {[f (car fs)]
237 [floc (frame-loc f)]}238 [fsym (frame-sym f)]}
238 (receive (params autos)239 (receive (params autos)
239 (partition (λ (x) (equal? #\p (symbol-type x)))240 (partition (λ (x) (equal? #\p (symbol-type x)))
240 (frame-locals f))241 (frame-locals f))
241 (set! params (sort params #.< :key symbol-addr))242 (set! params (sort params #.< :key symbol-addr))
242 (set! autos (sort autos #.> :key symbol-addr))243 (set! autos (sort autos #.> :key symbol-addr))
243 (princ (symbol-name floc) "(")244 (princ (symbol-name fsym) "(")
244 (princ245 (princ
245 (str-join246 (str-join
246 (map (λ (p)247 (map (λ (p)
247 (str (symbol-name p) "=" (hex (symbol-read p 'u64))))248 (str (symbol-name p) "=" (hex (symbol-read p 'u64))))
248 params)249 params)
249 ", "))250 ", "))
250 (princ ")+" (hex (- pc (symbol-addr floc))) " ")251 (princ ")+" (hex (- pc (symbol-addr fsym))) " ")
251 (princ (src pc) "\n")252 (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))
252 (go (frame-retpc f) (cdr fs))))))260 (go (frame-retpc f) (cdr fs))))))
253 (let* {[tos (go (curPC) (_stk))]261 (let* {[tos (go (curPC) (_stk))]
254 [topsym (lsd-findsym tos)]}262 [topsym (lsd-findsym tos)]}
@@ -259,6 +267,13 @@ · 4 unmodified lines
259 (src tos)267 (src tos)
260 "\n")))268 "\n")))
261 269
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
262(def (curPC) (and (>= pid 0) (readreg PC)))277(def (curPC) (and (>= pid 0) (readreg PC)))
263 278
264(def (step (n 1))279(def (step (n 1))
@@ -371,7 +386,8 @@ · 106 unmodified lines
371 (path-cwd)386 (path-cwd)
372 "\ntext\n\n"387 "\ntext\n\n"
373 (length s)388 (length s)
374 "\n" s))389 "\n"
390 s))
375 (io-close plumbf)))391 (io-close plumbf)))
376 392
377(def (B stepper)393(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