shithub: sl

Download patch

ref: f88e3f0d32f64dee4cf62910427939f45b66e7e2
parent: b37a02aed79b77ed629f4eb57eade3ca724e0c25
author: spew <spew@cbza.org>
date: Mon Mar 24 16:40:27 EDT 2025

lsd: finish implementation of (stk) so it looks just like acid, add some more architectures

--- a/src/plan9/lsd.c
+++ b/src/plan9/lsd.c
@@ -422,7 +422,7 @@
 
 	addr = tosize(args[0]);
 	if(!fileline(buf, sizeof(buf), addr))
-		lerrorf(sl_errio, "could not get locate source code line at %ud", addr);
+		lerrorf(sl_errio, "could not locate source code line at %ud", addr);
 	return str_from_cstr(buf);
 }
 
@@ -444,4 +444,19 @@
 	if(addr == ~0)
 		lerrorf(sl_errio, "could not find address of %s:%d", file, line);
 	return size_wrap(addr);
+}
+
+BUILTIN("lsd-findsym", lsd_findsym)
+{
+	Symbol s;
+	uvlong addr;
+
+	argcount(nargs, 1);
+	if(sl_unlikely(!sl_isnum(args[0])))
+		type_error("num", args[0]);
+
+	addr = tosize(args[0]);
+	if(!findsym(addr, CTEXT, &s))
+		lerrorf(sl_errio, "could not locate sym near %ud", addr);
+	return mk_symbol(&s);
 }
--- a/src/plan9/lsd.sl
+++ b/src/plan9/lsd.sl
@@ -205,9 +205,14 @@
            (io-close sf))))
 
 (def tracers (table
-  "386"   (λ () (lsd-ctrace (curPC) (readreg SP) (u64 0)))
-  "amd64" (λ () (lsd-ctrace (curPC) (readreg SP) (u64 0)))
-  "arm64" (λ () (lsd-ctrace (curPC) (readreg SP) (readreg R30)))))
+  "386"     (λ () (lsd-ctrace (curPC) (readreg SP) (u64 0)))
+  "68020"   (λ () (lsd-ctrace (curPC) (readreg SP) (readreg A7)))
+  "amd64"   (λ () (lsd-ctrace (curPC) (readreg SP) (u64 0)))
+  "arm"     (λ () (lsd-ctrace (curPC) (readreg SP) (readreg R14)))
+  "arm64"   (λ () (lsd-ctrace (curPC) (readreg SP) (readreg R30)))
+  "mips"    (λ () (lsd-ctrace (curPC) (readreg SP) (readreg R31)))
+  "power"   (λ () (lsd-ctrace (curPC) (readreg SP) (readreg LR)))
+  "power64" (λ () (lsd-ctrace (curPC) (readreg SP) (readreg LR)))))
 
 (def ctrace (get tracers (os-getenv "objtype")))
 
@@ -245,7 +250,14 @@
           (princ ")+" (hex (- pc (symbol-addr floc))) " ")
           (princ (src pc) "\n")
           (go (frame-retpc f) (cdr fs))))))
-  (go (curPC) (_stk)))
+  (let* {[tos (go (curPC) (_stk))]
+         [topsym (lsd-findsym tos)]}
+    (princ (symbol-name topsym)
+           "+"
+           (hex (- tos (symbol-addr topsym)))
+           " "
+           (src tos)
+           "\n")))
 
 (def (curPC) (and (>= pid 0) (readreg PC)))
 
@@ -448,7 +460,7 @@
     (set! pid (aref v 0))
     (set! proc-stdin (aref v 1))
     (attach)
-    (bpset (car (follow (symbol-addr (get (global-text globals) 'main)))))
+    (map bpset (follow (sym-addr 'main)))
     (startstop)
     (set! pids (cons pid pids))
     pid))