about summary refs log tree commit diff stats
path: root/315stack-debug.subx
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-20 23:25:19 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-20 23:27:13 -0700
commit7b2d39b8d418d29cc05dc0793c976761c302eadb (patch)
treea51af5ff35f5684ecba8c8fb693947ceac206478 /315stack-debug.subx
parentfb34909b4eb744811f6da2354667179c108870cb (diff)
downloadmu-7b2d39b8d418d29cc05dc0793c976761c302eadb.tar.gz
an interface approximating stack traces
Diffstat (limited to '315stack-debug.subx')
-rw-r--r--315stack-debug.subx23
1 files changed, 23 insertions, 0 deletions
diff --git a/315stack-debug.subx b/315stack-debug.subx
index 9734fd7a..a01c5687 100644
--- a/315stack-debug.subx
+++ b/315stack-debug.subx
@@ -49,3 +49,26 @@ $check-stack:end:
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
     c3/return
+
+# Helper for debugging deeply recursive calls without logs or traces.
+# Turn it on, insert calls in the right places, and you get a terse sense of
+# important parts of the call stack. A poor sophont's stack trace.
+debug-print:  # x: (addr array byte), fg: int, bg: int    # x is very short; usually a single character
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    {
+      81 7/subop/compare *Really-debug-print 0/imm32/false
+      74/jump-if-= break/disp8
+      (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+8) *(ebp+0xc) *(ebp+0x10))
+    }
+$debug-print:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+== data
+Really-debug-print:
+  0/imm32/false