From dafa39853a6fc43f6a803ff6436b0f6d25373368 Mon Sep 17 00:00:00 2001
From: Ben Bridle <ben@derelict.engineering>
Date: Thu, 31 Oct 2024 18:08:19 +1300
Subject: Only print stack debug information in debug mode

The stack state when halting was previously being printed even outside
of debug mode.
---
 src/debug.rs | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/debug.rs b/src/debug.rs
index d7e7f67..8be5bb9 100644
--- a/src/debug.rs
+++ b/src/debug.rs
@@ -34,20 +34,26 @@ impl DebugState {
     }
 
     pub fn debug_summary(&mut self, core: &BedrockCore) {
-        eprintln!("\n PC: 0x{:04x}   Cycles: {} (+{} in {:.2?})",
-            core.mem.pc, core.cycle,
-            core.cycle.saturating_sub(self.last_cycle),
-            self.last_mark.elapsed(),
-        );
-        eprint!("WST: ");
-        debug_stack(&core.wst, 0x10);
-        eprint!("RST: ");
-        debug_stack(&core.rst, 0x10);
-        // Print information about the current symbol.
-        if let Some(symbol) = self.symbols.for_address(core.mem.pc) {
-            eprint!("SYM: {BLUE}@{}{NORMAL} 0x{:04x}", symbol.name, symbol.address);
-            if let Some(location) = &symbol.location { eprint!(" {DIM}{location}{NORMAL}"); }
-            eprintln!();
+        if self.enabled {
+            eprintln!("\n PC: 0x{:04x}   Cycles: {} (+{} in {:.2?})",
+                core.mem.pc, core.cycle,
+                core.cycle.saturating_sub(self.last_cycle),
+                self.last_mark.elapsed(),
+            );
+            eprint!("WST: ");
+            debug_stack(&core.wst, 0x10);
+            eprint!("RST: ");
+            debug_stack(&core.rst, 0x10);
+            // Print information about the closest symbol.
+            if let Some(symbol) = self.symbols.for_address(core.mem.pc) {
+                let name = &symbol.name;
+                let address = &symbol.address;
+                eprint!("SYM: {BLUE}@{name}{NORMAL} 0x{address:04x}");
+                if let Some(location) = &symbol.location {
+                    eprint!(" {DIM}{location}{NORMAL}");
+                }
+                eprintln!();
+            }
         }
         self.last_cycle = core.cycle;
         self.last_mark = Instant::now();
-- 
cgit v1.2.3-70-g09d2