about summary refs log tree commit diff stats
path: root/039debug.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-03-11 16:52:37 -0700
committerKartik Agaram <vc@akkartik.com>2020-03-11 17:21:59 -0700
commit28746b36660093dcbf53667f4f67320d278359ea (patch)
treea3feabc3190234fcb9c2dd8802250c191c53bea2 /039debug.cc
parentbfb7c601354563498433d22f4dcf3ad4280a7314 (diff)
downloadmu-28746b36660093dcbf53667f4f67320d278359ea.tar.gz
6123 - runtime helper for initializing arrays
I built this in 3 phases:
a) create a helper in the bootstrap VM to render the state of the stack.
b) interactively arrive at the right function (tools/stack_array.subx)
c) pull the final solution into the standard library (093stack_allocate.subx)

As the final layer says, this may not be the fastest approach for most
(or indeed any) Mu programs. Perhaps it's better on balance for the compiler
to just emit n/4 `push` instructions.

(I'm sure this solution can be optimized further.)
Diffstat (limited to '039debug.cc')
-rw-r--r--039debug.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/039debug.cc b/039debug.cc
index 9f2dd4bd..411818ff 100644
--- a/039debug.cc
+++ b/039debug.cc
@@ -93,6 +93,32 @@ if (!Watch_this_effective_address.empty()) {
   put(Watch_points, Watch_this_effective_address, addr);
 }
 
+//: If a label starts with '$dump-stack', dump out to the trace n bytes on
+//: either side of ESP.
+
+:(after "Run One Instruction")
+if (contains_key(Symbol_name, EIP) && starts_with(get(Symbol_name, EIP), "$dump-stack")) {
+  dump_stack(64);
+}
+:(code)
+void dump_stack(int n) {
+  uint32_t stack_pointer = Reg[ESP].u;
+  uint32_t start = ((stack_pointer-n)&0xfffffff0);
+  dbg << "stack:" << end();
+  for (uint32_t addr = start;  addr < start+n*2;  addr+=16) {
+    if (addr >= AFTER_STACK) break;
+    ostringstream out;
+    out << HEXWORD << addr << ":";
+    for (int i = 0;  i < 16;  i+=4) {
+      out << ' ';
+      out << ((addr+i == stack_pointer) ? '[' : ' ');
+      out << HEXWORD << read_mem_u32(addr+i);
+      out << ((addr+i == stack_pointer) ? ']' : ' ');
+    }
+    dbg << out.str() << end();
+  }
+}
+
 //: Special label that dumps regions of memory.
 //: Not a general mechanism; by the time you get here you're willing to hack
 //: on the emulator.