generic-tracing: --catch-trap aborts when a trap is observed

Enabling --catch-trap makes sure tracing aborts with an error message
in case a CPU exception/trap is observed in the fault-free golden run.
In most cases, this is an indication the analyzed program is broken in
the first place, which should be detected early in the FI process.

This is a refurbished version of a commit by Marcel Johannfunke.

Change-Id: I50cc8e12e0986d3623a1be78259cfad13dc56205
This commit is contained in:
Horst Schirmeier
2021-03-28 17:44:36 +02:00
parent 67f1be840f
commit 7bdefb6849
2 changed files with 23 additions and 2 deletions

View File

@ -73,6 +73,8 @@ void GenericTracing::parseOptions() {
"--e9-file FILE \tShorthand for --serial-file FILE --serial-port 0xe9"); "--e9-file FILE \tShorthand for --serial-file FILE --serial-port 0xe9");
CommandLine::option_handle CHECK_BOUNDS = cmd.addOption("", "check-bounds", Arg::None, CommandLine::option_handle CHECK_BOUNDS = cmd.addOption("", "check-bounds", Arg::None,
"--check-bounds \tWhether or not to enable outerspace and text segment checkers which are used in the experiment stage during tracing. If these trip, something is wrong with your architecture implementation."); "--check-bounds \tWhether or not to enable outerspace and text segment checkers which are used in the experiment stage during tracing. If these trip, something is wrong with your architecture implementation.");
CommandLine::option_handle CATCH_TRAP = cmd.addOption("", "catch-trap", Arg::None,
"--catch-trap \tCatch traps");
if (!cmd.parse()) { if (!cmd.parse()) {
cerr << "Error parsing arguments." << endl; cerr << "Error parsing arguments." << endl;
@ -253,6 +255,11 @@ void GenericTracing::parseOptions() {
m_log << "port E9 output is written to: " << serial_file << std::endl; m_log << "port E9 output is written to: " << serial_file << std::endl;
} }
if (cmd[CATCH_TRAP]) {
m_log << "Catch all traps" << endl;
enabled_trap = true;
}
if(cmd[CHECK_BOUNDS]) { if(cmd[CHECK_BOUNDS]) {
this->check_bounds = true; this->check_bounds = true;
m_log << "enabled bounds sanity check" << std::endl; m_log << "enabled bounds sanity check" << std::endl;
@ -305,6 +312,7 @@ bool GenericTracing::run()
BPSingleListener l_start_symbol(start_address); BPSingleListener l_start_symbol(start_address);
BPSingleListener l_stop_symbol(stop_address); BPSingleListener l_stop_symbol(stop_address);
TrapListener l_trap;
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// STEP 1: run until interesting function starts, save, and start tracing // STEP 1: run until interesting function starts, save, and start tracing
@ -313,6 +321,9 @@ bool GenericTracing::run()
m_log << start_symbol << " reached, save ..." << std::endl; m_log << start_symbol << " reached, save ..." << std::endl;
simulator.save(state_file); simulator.save(state_file);
if (enabled_trap)
simulator.addListener(&l_trap);
if (restore) { if (restore) {
m_log << "restoring clean state ..." << std::endl; m_log << "restoring clean state ..." << std::endl;
simulator.restore(state_file); simulator.restore(state_file);
@ -355,6 +366,12 @@ bool GenericTracing::run()
simulator.addListener(&l_stop_symbol); simulator.addListener(&l_stop_symbol);
fail::BaseListener* listener = simulator.resume(); fail::BaseListener* listener = simulator.resume();
int exitcode = 0;
if (listener == &l_trap)
{
m_log << "Trace encountered trap 0x" << hex << l_trap.getTriggerNumber() << "! Exiting tracing." << std::endl;
exitcode = 100;
}
if (check_bounds) { if (check_bounds) {
if(listener == &l_mem_text) { if(listener == &l_mem_text) {
@ -406,7 +423,7 @@ bool GenericTracing::run()
} }
simulator.clearListeners(); simulator.clearListeners();
simulator.terminate(); simulator.terminate(exitcode);
return true; return true;
} }

View File

@ -32,12 +32,16 @@ class GenericTracing : public fail::ExperimentFlow {
fail::Logger m_log; fail::Logger m_log;
fail::ElfReader *m_elf; fail::ElfReader *m_elf;
bool enabled_trap;
public: public:
void parseOptions(); void parseOptions();
bool run(); bool run();
GenericTracing() : restore(false), GenericTracing() : restore(false),
full_trace(false), check_bounds(false), m_log("GenericTracing", false) {} full_trace(false), check_bounds(false), m_log("GenericTracing", false),
enabled_trap(false)
{}
}; };
#endif // __TRACING_TEST_HPP__ #endif // __TRACING_TEST_HPP__