about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--subx/010---vm.cc14
-rw-r--r--subx/012elf.cc11
2 files changed, 15 insertions, 10 deletions
diff --git a/subx/010---vm.cc b/subx/010---vm.cc
index 3af4a579..0d30f3cd 100644
--- a/subx/010---vm.cc
+++ b/subx/010---vm.cc
@@ -297,13 +297,12 @@ void run_one_instruction() {
   uint8_t op=0, op2=0, op3=0;
   // Run One Instruction
   if (Dump_trace) {
-    cerr << "registers: ";
     dump_registers();
-//?     dump_stack();  // for debugging; not defined until later layer
+    // End Dump Info for Instruction
   }
   trace(90, "run") << "inst: 0x" << HEXWORD << EIP << end();
   op = next();
-  if (Dump_trace) cerr << "opcode: " << HEXBYTE << NUM(op) << '\n';
+  trace(90, "run") << "opcode: " << HEXBYTE << NUM(op) << end();
   switch (op) {
   case 0xf4:  // hlt
     EIP = End_of_program;
@@ -366,11 +365,14 @@ inline uint8_t next() {
 }
 
 void dump_registers() {
+  ostringstream out;
+  out << "registers: ";
   for (int i = 0;  i < NUM_INT_REGISTERS;  ++i) {
-    if (i > 0) cerr << "; ";
-    cerr << "  " << i << ": " << std::hex << std::setw(8) << std::setfill('_') << Reg[i].u;
+    if (i > 0) out << "; ";
+    out << "  " << i << ": " << std::hex << std::setw(8) << std::setfill('_') << Reg[i].u;
   }
-  cerr << " -- SF: " << SF << "; ZF: " << ZF << "; OF: " << OF << '\n';
+  out << " -- SF: " << SF << "; ZF: " << ZF << "; OF: " << OF;
+  trace(90, "run") << out.str() << end();
 }
 
 //: start tracking supported opcodes
diff --git a/subx/012elf.cc b/subx/012elf.cc
index 47aba102..5220d18d 100644
--- a/subx/012elf.cc
+++ b/subx/012elf.cc
@@ -137,14 +137,17 @@ const int DATA_SEGMENT = 0x0a000000;  // keep sync'd with `Heap.limit` in alloca
 const int STACK_SEGMENT = 0x0b000000;
 const int AFTER_STACK = 0x0c000000;
 const int ARGV_DATA_SEGMENT = 0x0c000000;
+:(before "End Dump Info for Instruction")
+//? dump_stack();  // slow
 :(code)
 void dump_stack() {
-  cerr << "stack:\n";
+  ostringstream out;
+  trace(91, "run") << "stack:" << end();
   for (uint32_t a = AFTER_STACK-4;  a > Reg[ESP].u;  a -= 4)
-    cerr << "  0x" << HEXWORD << a << " => 0x" << HEXWORD << read_mem_u32(a) << '\n';
-  cerr << "  0x" << HEXWORD << Reg[ESP].u << " => 0x" << HEXWORD << read_mem_u32(Reg[ESP].u) << "  <=== ESP\n";
+    trace(91, "run") << "  0x" << HEXWORD << a << " => 0x" << HEXWORD << read_mem_u32(a) << end();
+  trace(91, "run") << "  0x" << HEXWORD << Reg[ESP].u << " => 0x" << HEXWORD << read_mem_u32(Reg[ESP].u) << "  <=== ESP" << end();
   for (uint32_t a = Reg[ESP].u-4;  a > Reg[ESP].u-40;  a -= 4)
-    cerr << "  0x" << HEXWORD << a << " => 0x" << HEXWORD << read_mem_u32(a) << '\n';
+    trace(91, "run") << "  0x" << HEXWORD << a << " => 0x" << HEXWORD << read_mem_u32(a) << end();
 }
 
 inline uint32_t u32_in(uint8_t* p) {