about summary refs log tree commit diff stats
path: root/subx/039debug.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-01-08 15:39:53 -0800
committerKartik Agaram <vc@akkartik.com>2019-01-08 15:46:55 -0800
commitf7f0d6318231ff081ed6ff2ef30d8e1823e11c70 (patch)
treeb85f03addb53d757bf3eac59e7c9cc93648d1709 /subx/039debug.cc
parent96a6bac52d6f4a67932e54d25166bf7961718e9d (diff)
downloadmu-f7f0d6318231ff081ed6ff2ef30d8e1823e11c70.tar.gz
4915
In the process of building next-token I finally added some support for a
debugging situation I've found myself in a couple of times: wondering "what
changed this memory location"?
Diffstat (limited to 'subx/039debug.cc')
-rw-r--r--subx/039debug.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/subx/039debug.cc b/subx/039debug.cc
index 4d041fa4..816947a2 100644
--- a/subx/039debug.cc
+++ b/subx/039debug.cc
@@ -23,3 +23,33 @@ void load_map(const string& map_filename) {
 :(after "Run One Instruction")
 if (contains_key(Symbol_name, EIP))
   trace(90, "run") << "== label " << get(Symbol_name, EIP) << end();
+
+// If a label starts with '$watch-', make a note of the effective address
+// computed by the next instruction. Start dumping out its contents after
+// every subsequent instruction.
+
+:(after "Run One Instruction")
+dump_watch_points();
+:(before "End Globals")
+map<string, uint32_t> Watch_points;
+:(before "End Reset")
+Watch_points.clear();
+:(code)
+void dump_watch_points() {
+  if (Watch_points.empty()) return;
+  dbg << "watch points:" << end();
+  for (map<string, uint32_t>::iterator p = Watch_points.begin();  p != Watch_points.end();  ++p)
+    dbg << "  " << p->first << ": " << HEXWORD << p->second << " -> " << HEXWORD << read_mem_u32(p->second) << end();
+}
+
+:(before "End Globals")
+string Watch_this_effective_address;
+:(after "Run One Instruction")
+Watch_this_effective_address = "";
+if (contains_key(Symbol_name, EIP) && starts_with(get(Symbol_name, EIP), "$watch-"))
+  Watch_this_effective_address = get(Symbol_name, EIP);
+:(after "Found effective_address(addr)")
+if (!Watch_this_effective_address.empty()) {
+  dbg << "now watching " << HEXWORD << addr << " for " << Watch_this_effective_address << end();
+  Watch_points[Watch_this_effective_address] = addr;
+}