Enhanced logging in ALUInstr

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1723 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
unzner
2012-10-05 12:02:39 +00:00
parent 0c3568dc2f
commit 37f030b9a3
3 changed files with 34 additions and 13 deletions

View File

@ -1,4 +1,6 @@
#include "aluinstr.hpp"
#include <iostream>
#include <sstream>
#include <string.h>
#include <time.h>
#include "bochs.h"
@ -90,12 +92,14 @@ bool BochsALUInstructions::isALUInstruction(bxInstruction_c const *src) {
return false;
}
bxInstruction_c BochsALUInstructions::randomEquivalent() const {
void BochsALUInstructions::randomEquivalent(bxInstruction_c &result,
std::string &details) const {
// find a random member of the same equivalence class
X86AluClass equClassID = lastInstr.aluClass;
if (equClassID == ALU_UNDEF) {
// something went wrong - just return the original instruction
return lastOrigInstr;
result = lastOrigInstr;
return;
}
InstrList const &destList = equivalenceClasses.at(equClassID);
@ -106,8 +110,16 @@ bxInstruction_c BochsALUInstructions::randomEquivalent() const {
dest = destList[index];
} while (memcmp(&dest, &lastInstr, sizeof(BochsALUInstr)) == 0);
// alternative chosen -- now store the necessary details
std::ostringstream oss;
oss << "Opcode 0x" << std::hex << static_cast<unsigned>(dest.opcode) << std::dec;
if (dest.reg < dest.REG_COUNT) oss << " # " << static_cast<unsigned>(dest.reg);
if (dest.opcodeRegisterOffset <= dest.REG_COUNT)
oss << " # " << static_cast<unsigned>(dest.opcodeRegisterOffset);
details = oss.str();
// first, copy everything
bxInstruction_c result = lastOrigInstr;
result = lastOrigInstr;
// then change what has to be different
// execute functions
@ -124,12 +136,9 @@ bxInstruction_c BochsALUInstructions::randomEquivalent() const {
if (dest.opcodeRegisterOffset < BochsALUInstr::REG_COUNT) {
result.setRm(dest.opcodeRegisterOffset);
}
// finally, return the result
return result;
}
#ifdef DEBUG
#include <iostream>
void BochsALUInstructions::printNestedMap() {
for (EquivClassMap::iterator it = equivalenceClasses.begin();

View File

@ -3,6 +3,7 @@
#include <map>
#include <vector>
#include <string>
#include <stdlib.h>
#include "config.h"
#include "cpu/instr.h"
@ -321,9 +322,10 @@ public:
/**
* Determines a new bxInstruction_c object with an equivalent
* addressing mode.
* @returns a bxInstruction_c object as described above
* @param result the resulting bxInstruction_c object as described above
* @param details after completion contains details about \c result
*/
bxInstruction_c randomEquivalent() const;
void randomEquivalent(bxInstruction_c &result, std::string &details) const;
protected:
/**
* Convert a bxInstruction_c object into its matching BochsALUInstr object.

View File

@ -377,6 +377,7 @@ bool L4SysExperiment::run() {
stringstream ss;
ss << "Sent package did not contain the injection location (register offset)" << endl;
param.msg.set_details(ss.str());
m_jc.sendResult(param);
simulator.terminate(30);
}
int reg_offset = param.msg.register_offset();
@ -540,8 +541,14 @@ bool L4SysExperiment::run() {
currInstr = simulator.getCurrentInstruction())) {
singleStep();
}
// store the real injection point
param.msg.set_injection_ip(simulator.getRegisterManager().getInstructionPointer());
// now exchange it with a random equivalent
bxInstruction_c newInstr = aluInstrObject.randomEquivalent();
bxInstruction_c newInstr;
string details;
aluInstrObject.randomEquivalent(newInstr, details);
if (memcmp(&newInstr, currInstr, sizeof(bxInstruction_c)) == 0) {
// something went wrong - exit experiment
param.msg.set_resulttype(param.msg.UNKNOWN);
@ -549,11 +556,15 @@ bool L4SysExperiment::run() {
simulator.getRegisterManager().getInstructionPointer());
param.msg.set_output(sanitised(output.c_str()));
stringstream ss;
ss << "Did not hit an ALU instruction - correct the source code please!" << endl;
param.msg.set_details(ss.str());
ostringstream oss;
oss << "Did not hit an ALU instruction - correct the source code please!" << endl;
param.msg.set_details(oss.str());
m_jc.sendResult(param);
simulator.terminate(40);
}
// record information on the new instruction
param.msg.set_details(details);
// inject it
injectInstruction(currInstr, &newInstr);
@ -567,7 +578,6 @@ bool L4SysExperiment::run() {
BPSingleListener ev_incomplete(ANY_ADDR, L4SYS_ADDRESS_SPACE);
ev_incomplete.setCounter(static_cast<unsigned>(L4SYS_NUMINSTR * 1.1));
simulator.addListener(&ev_incomplete);
log << calculateTimeout() << endl;
TimerListener ev_timeout(calculateTimeout());
simulator.addListener(&ev_timeout);