[sim] added "str" debug command
authorAndrew Waterman <waterman@s144.Millennium.Berkeley.EDU>
Sun, 17 Apr 2011 02:44:16 +0000 (19:44 -0700)
committerAndrew Waterman <waterman@s144.Millennium.Berkeley.EDU>
Sun, 17 Apr 2011 02:44:16 +0000 (19:44 -0700)
it prints the c string starting at the specified memory address.

riscv/sim.cc
riscv/sim.h

index 50264ed3db87c61acedf14f21c1fa3c1c1842266..7ac60c11b398b963d8b6eca186e263b4e793f052 100644 (file)
@@ -75,6 +75,7 @@ void sim_t::run(bool debug)
       funcs["fregs"] = &sim_t::interactive_fregs;
       funcs["fregd"] = &sim_t::interactive_fregd;
       funcs["mem"] = &sim_t::interactive_mem;
+      funcs["str"] = &sim_t::interactive_str;
       funcs["until"] = &sim_t::interactive_until;
       funcs["while"] = &sim_t::interactive_until;
       funcs["q"] = &sim_t::interactive_quit;
@@ -254,6 +255,22 @@ void sim_t::interactive_mem(const std::string& cmd, const std::vector<std::strin
   printf("0x%016llx\n",(unsigned long long)get_mem(args));
 }
 
+void sim_t::interactive_str(const std::string& cmd, const std::vector<std::string>& args)
+{
+  if(args.size() != 1)
+    throw trap_illegal_instruction;
+
+  reg_t addr = strtol(args[0].c_str(),NULL,16);
+
+  mmu_t mmu(mem,memsz);
+  char ch;
+
+  while((ch = mmu.load_uint8(addr++)))
+    putchar(ch);
+
+  putchar('\n');
+}
+
 void sim_t::interactive_until(const std::string& cmd, const std::vector<std::string>& args)
 {
   if(args.size() < 3)
index 722fe64268d7a27c812dd80f8dd037dcaa4ccb2b..a471500973ee6e67eee17f125ae916c45920b7fb 100644 (file)
@@ -46,6 +46,7 @@ private:
   void interactive_fregs(const std::string& cmd, const std::vector<std::string>& args);
   void interactive_fregd(const std::string& cmd, const std::vector<std::string>& args);
   void interactive_mem(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_str(const std::string& cmd, const std::vector<std::string>& args);
   void interactive_until(const std::string& cmd, const std::vector<std::string>& args);
 
   reg_t get_reg(const std::vector<std::string>& args);