diff options
author | Elmar Melcher <elmar@dsc.ufcg.edu.br> | 2021-07-02 11:31:30 -0300 |
---|---|---|
committer | emelcher <elmar@dsc.ufcg.edu.br> | 2021-08-03 10:19:27 -0300 |
commit | 08ed2fab4f627dad4c77ee41d93deddde68817fe (patch) | |
tree | b3aceb13d8f2d8b135e6946f033eb72fb0a15275 | |
parent | 810ec3fb130bcc5e06d7fe5060a02a15a9f17cd6 (diff) | |
download | spike-08ed2fab4f627dad4c77ee41d93deddde68817fe.zip spike-08ed2fab4f627dad4c77ee41d93deddde68817fe.tar.gz spike-08ed2fab4f627dad4c77ee41d93deddde68817fe.tar.bz2 |
use socket output stream for processor debug output
-rw-r--r-- | riscv/processor.cc | 33 | ||||
-rw-r--r-- | spike_main/spike.cc | 2 |
2 files changed, 27 insertions, 8 deletions
diff --git a/riscv/processor.cc b/riscv/processor.cc index 2ea04b1..aa3df35 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -13,12 +13,20 @@ #include <cmath> #include <cstdlib> #include <iostream> +#include <iomanip> #include <assert.h> #include <limits.h> #include <stdexcept> #include <string> #include <algorithm> +using std::stringstream; +using std::hex; +using std::dec; +using std::setfill; +using std::setw; +using std::endl; + #undef STATE #define STATE state @@ -52,6 +60,8 @@ processor_t::processor_t(const char* isa, const char* priv, const char* varch, else if (max_xlen == 64) set_mmu_capability(IMPL_MMU_SV48); + sout_ptr = sout_ptr_ctor; // needed for command line option -s + reset(); } @@ -684,11 +694,16 @@ void processor_t::enter_debug_mode(uint8_t cause) void processor_t::take_trap(trap_t& t, reg_t epc) { if (debug) { - fprintf(log_file, "core %3d: exception %s, epc 0x%0*" PRIx64 "\n", - id, t.name(), max_xlen/4, zext(epc, max_xlen)); + stringstream s; // first put everything in a string, later send it to output + s << "core " << dec << setfill(' ') << setw(3) << id + << ": exception " << t.name() << ", epc 0x" + << hex << setfill('0') << setw(max_xlen/4) << zext(epc, max_xlen) << endl; if (t.has_tval()) - fprintf(log_file, "core %3d: tval 0x%0*" PRIx64 "\n", - id, max_xlen/4, zext(t.get_tval(), max_xlen)); + s << "core " << dec << setfill(' ') << setw(3) << id + << ": tval 0x" << hex << setfill('0') << setw(max_xlen/4) + << zext(t.get_tval(), max_xlen) << endl; + if (log_file==stderr) *sout_ptr << s.str(); // handles command line options -d -s -l + else fputs(s.str().c_str(),log_file); // handles command line option --log } if (state.debug_mode) { @@ -797,9 +812,13 @@ void processor_t::disasm(insn_t insn) fprintf(log_file, "core %3d: Executed %" PRIx64 " times\n", id, executions); } - fprintf(log_file, "core %3d: 0x%0*" PRIx64 " (0x%08" PRIx64 ") %s\n", - id, max_xlen/4, zext(state.pc, max_xlen), bits, - disassembler->disassemble(insn).c_str()); + stringstream s; // first put everything in a string, later send it to output + s << "core " << dec << setfill(' ') << setw(3) << id + << hex << ": 0x" << setfill('0') << setw(max_xlen/4) + << zext(state.pc, max_xlen) << " (0x" << setw(8) << bits << ") " + << disassembler->disassemble(insn) << endl; + if (log_file==stderr) *sout_ptr << s.str(); // handles command line options -d -s -l + else fputs(s.str().c_str(),log_file); // handles command line option --log last_pc = state.pc; last_bits = bits; executions = 1; diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 43431a6..13bead5 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -415,7 +415,7 @@ int main(int argc, char** argv) // aceptor is created passing argument port=0, so O.S. will choose a free port string name = boost::asio::ip::host_name(); std::cout << "Listening for debug commands on " << name.substr(0,name.find('.')) - << " port " << acceptor_ptr->local_endpoint().port() << " ." << std::endl; + << " port " << acceptor_ptr->local_endpoint().port() << " ." << std::endl; // at the end, add space and some other character for convenience of javascript .split(" ") } catch (std::exception& e) |