arch-riscv: Don't crash when printing unknown CSRs
authorAlec Roelke <ar4jc@virginia.edu>
Fri, 15 Dec 2017 04:22:10 +0000 (23:22 -0500)
committerAlec Roelke <ar4jc@virginia.edu>
Thu, 11 Jan 2018 23:11:54 +0000 (23:11 +0000)
This patch fixes a potential crash if an unnamed CSR is accessed and
debug flags are enabled that print disassembly.  Unknown CSRs will be
identified as "??" followed by the address that was used.

Change-Id: If5ac57f1422bd59c72a1a06206fa9d9dc05d21ef
Reviewed-on: https://gem5-review.googlesource.com/7321
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Alec Roelke <ar4jc@virginia.edu>

src/arch/riscv/insts/standard.cc

index bcf0741f919a9e096f987fcb7b64c784b798494d..60cf4fc2b6c096ba11c5467d63805808206b56fe 100644 (file)
@@ -60,7 +60,11 @@ CSROp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
     ss << mnemonic << ' ' << registerName(_destRegIdx[0]) << ", ";
     if (_numSrcRegs > 0)
         ss << registerName(_srcRegIdx[0]) << ", ";
-    ss << MiscRegNames.at(csr);
+    auto name = MiscRegNames.find(csr);
+    if (name != MiscRegNames.end())
+        ss << name->second;
+    else
+        ss << "?? (" << hex << "0x" << csr << ")";
     return ss.str();
 }