about summary refs log tree commit diff stats
path: root/315stack-debug.subx
diff options
context:
space:
mode:
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