about summary refs log tree commit diff stats
path: root/subx/039debug.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-10-10 19:51:20 -0700
committerKartik Agaram <vc@akkartik.com>2018-10-10 20:54:15 -0700
commit8950915a007f78c427f176609678c50ef9923e5b (patch)
treedbe10980201791f98d7ed02944c98d1defec38be /subx/039debug.cc
parent2a15acd51025c9a6e63865b6ba7b3fbbd4bdd802 (diff)
downloadmu-8950915a007f78c427f176609678c50ef9923e5b.tar.gz
4678
A debugging aid: 'subx --map translate' dumps a mapping from functions
to addresses to a file called "map", and 'subx --map run' loads the mapping
in "map", augmenting debug traces.

Let's see how much this helps. Debugging machine code has been pretty painful
lately.
Diffstat (limited to 'subx/039debug.cc')
-rw-r--r--subx/039debug.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/subx/039debug.cc b/subx/039debug.cc
new file mode 100644
index 00000000..4d041fa4
--- /dev/null
+++ b/subx/039debug.cc
@@ -0,0 +1,25 @@
+//: Some helpers for debugging.
+
+// Load the 'map' file generated during 'subx --map translate' when running 'subx --map --dump run'.
+// (It'll only affect the trace.)
+
+:(before "End Globals")
+map</*address*/uint32_t, string> Symbol_name;  // used only by 'subx run'
+:(before "End --map Settings")
+load_map("map");
+:(code)
+void load_map(const string& map_filename) {
+  ifstream fin(map_filename.c_str());
+  fin >> std::hex;
+  while (has_data(fin)) {
+    uint32_t addr = 0;
+    fin >> addr;
+    string name;
+    fin >> name;
+    put(Symbol_name, addr, name);
+  }
+}
+
+:(after "Run One Instruction")
+if (contains_key(Symbol_name, EIP))
+  trace(90, "run") << "== label " << get(Symbol_name, EIP) << end();