diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-03-24 22:21:01 +0100 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-03-24 22:21:01 +0100 |
commit | 742d48d1462523c89087551e683e824f922bb629 (patch) | |
tree | f08d132f2e87e6810fd960cb1d8d3f4e4aeba8ab /qtmips_cli | |
parent | f7d222b7399e1d3b93541a278f55022fcbf8eaec (diff) | |
download | qtmips-742d48d1462523c89087551e683e824f922bb629.tar.gz qtmips-742d48d1462523c89087551e683e824f922bb629.tar.bz2 qtmips-742d48d1462523c89087551e683e824f922bb629.zip |
Extend qtmips_cli to recognize break and report final state.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_cli')
-rw-r--r-- | qtmips_cli/reporter.cpp | 79 | ||||
-rw-r--r-- | qtmips_cli/reporter.h | 1 |
2 files changed, 79 insertions, 1 deletions
diff --git a/qtmips_cli/reporter.cpp b/qtmips_cli/reporter.cpp index d095449..a7db4a8 100644 --- a/qtmips_cli/reporter.cpp +++ b/qtmips_cli/reporter.cpp @@ -35,6 +35,7 @@ #include "reporter.h" #include <iostream> +#include <iomanip> #include <typeinfo> #include <qtmipsexception.h> @@ -47,6 +48,7 @@ Reporter::Reporter(QCoreApplication *app, QtMipsMachine *machine) : QObject() { connect(machine, SIGNAL(program_exit()), this, SLOT(machine_exit())); connect(machine, SIGNAL(program_trap(machine::QtMipsException&)), this, SLOT(machine_trap(machine::QtMipsException&))); + connect(machine->core(), SIGNAL(stop_on_exception_reached()), this, SLOT(machine_exception_reached())); e_regs = false; e_fail = (enum FailReason)0; @@ -69,6 +71,47 @@ void Reporter::machine_exit() { app->exit(); } +void Reporter::machine_exception_reached() { + ExceptionCause excause; + excause = machine->get_exception_cause(); + switch (excause) { + case EXCAUSE_NONE: + cout << "Machine stopped on NONE exception." << endl; + break; + case EXCAUSE_INT: + cout << "Machine stopped on INT exception." << endl; + break; + case EXCAUSE_ADDRL: + cout << "Machine stopped on ADDRL exception." << endl; + break; + case EXCAUSE_ADDRS: + cout << "Machine stopped on ADDRS exception." << endl; + break; + case EXCAUSE_IBUS: + cout << "Machine stopped on IBUS exception." << endl; + break; + case EXCAUSE_DBUS: + cout << "Machine stopped on DBUS exception." << endl; + break; + case EXCAUSE_SYSCALL: + cout << "Machine stopped on SYSCALL exception." << endl; + break; + case EXCAUSE_OVERFLOW: + cout << "Machine stopped on OVERFLOW exception." << endl; + break; + case EXCAUSE_TRAP: + cout << "Machine stopped on TRAP exception." << endl; + break; + case EXCAUSE_HWBREAK: + cout << "Machine stopped on HWBREAK exception." << endl; + break; + default: + break; + } + report(); + app->exit(); +} + void Reporter::machine_trap(QtMipsException &e) { report(); @@ -87,8 +130,42 @@ void Reporter::machine_trap(QtMipsException &e) { app->exit(expected ? 0 : 1); } +static void out_hex(ostream &out, std::uint64_t val, int digits) { + std::ios_base::fmtflags saveflg(out.flags()); + char prevfill = out.fill('0'); + out.setf(ios::hex, ios::basefield); + out << setfill('0') << setw(digits) << val; + out.fill(prevfill); + out.flags(saveflg); +} + void Reporter::report() { if (e_regs) { - // TODO + cout << "Machine state report:" << endl; + cout << "PC:0x"; + out_hex(cout, machine->registers()->read_pc(), 8); + cout << endl; + for (int i = 0; i < 32; i++) { + cout << "R" << i << ":0x"; + out_hex(cout, machine->registers()->read_gp(i), 8); + if (i != 31) + cout << " "; + else + cout << endl; + } + cout << "HI:0x"; + out_hex(cout, machine->registers()->read_hi_lo(true), 8); + cout << " LO:0x"; + out_hex(cout, machine->registers()->read_hi_lo(false), 8); + cout << endl; + for (int i = 1; i < Cop0State::COP0REGS_CNT; i++) { + cout << Cop0State::cop0reg_name((Cop0State::Cop0Registers)i).toLocal8Bit().data() << ":0x"; + out_hex(cout, machine->cop0state()->read_cop0reg((Cop0State::Cop0Registers)i), 8); + if (i != Cop0State::COP0REGS_CNT - 1) + cout << " "; + else + cout << endl; + } + } } diff --git a/qtmips_cli/reporter.h b/qtmips_cli/reporter.h index fbe3287..d5c67ed 100644 --- a/qtmips_cli/reporter.h +++ b/qtmips_cli/reporter.h @@ -61,6 +61,7 @@ public: private slots: void machine_exit(); void machine_trap(machine::QtMipsException &e); + void machine_exception_reached(); private: QCoreApplication *app; |