misc cleanups
This change touches several subsystems, tools and experiments (sal, util, cmake, import-trace, generic-tracing, nanojpeg), and changes details not worth separate commits. Change-Id: Icd1d664d1be5cfc2212dbf77801c271183214d08
This commit is contained in:
@ -117,7 +117,7 @@ bool Importer::copy_to_database(fail::ProtoIStream &ps) {
|
||||
m_last_ip = ev.ip(); // The last event in the log
|
||||
|
||||
/* Signal that the trace was completely imported */
|
||||
LOG << "trace duration: " << (curtime - m_time_trace_start) << " ticks" << std::endl;
|
||||
LOG << "trace duration: " << std::dec << (curtime - m_time_trace_start) << " ticks" << std::endl;
|
||||
LOG << "Inserted " << m_row_count << " real trace events into the database" << std::endl;
|
||||
|
||||
|
||||
|
||||
@ -54,4 +54,3 @@ bool MemoryImporter::handle_mem_event(simtime_t curtime, instruction_count_t ins
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -18,9 +18,9 @@ bool RandomJumpImporter::cb_commandline_init() {
|
||||
CommandLine &cmd = CommandLine::Inst();
|
||||
|
||||
FROM = cmd.addOption("", "jump-from", Arg::Required,
|
||||
"--jump-from\t RandomJump: Which addresses should be jumped from\n");
|
||||
"--jump-from \tRandomJump: Which addresses should be jumped from (a memory map; may be used more than once)");
|
||||
TO = cmd.addOption("", "jump-to", Arg::Required,
|
||||
"--jump-to\t RandomJump: Where to jump (a memory map>\n");
|
||||
"--jump-to \tRandomJump: Where to jump (a memory map; may be used more than once)");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ bool RandomJumpImporter::handle_ip_event(fail::simtime_t curtime, instruction_co
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read FROM memory file
|
||||
if (cmd[FROM].count() > 0) {
|
||||
// Read FROM memory map(s)
|
||||
if (cmd[FROM]) {
|
||||
m_mm_from = new MemoryMap();
|
||||
for (option::Option *o = cmd[FROM]; o; o = o->next()) {
|
||||
if (!m_mm_from->readFromFile(o->arg)) {
|
||||
@ -46,7 +46,8 @@ bool RandomJumpImporter::handle_ip_event(fail::simtime_t curtime, instruction_co
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd[TO].count() > 0) {
|
||||
// Read TO memory map(s)
|
||||
if (cmd[TO]) {
|
||||
m_mm_to = new MemoryMap();
|
||||
for (option::Option *o = cmd[TO]; o; o = o->next()) {
|
||||
if (!m_mm_to->readFromFile(o->arg)) {
|
||||
@ -81,7 +82,7 @@ bool RandomJumpImporter::handle_ip_event(fail::simtime_t curtime, instruction_co
|
||||
/* Collect all addresses we want to jump to */
|
||||
for (LLVMDisassembler::InstrMap::const_iterator instr = instr_map.begin();
|
||||
instr != instr_map.end(); ++instr) {
|
||||
if (m_mm_to->isMatching(instr->first)) {
|
||||
if (m_mm_to && m_mm_to->isMatching(instr->first)) {
|
||||
m_jump_to_addresses.push_back(instr->first);
|
||||
}
|
||||
}
|
||||
@ -91,12 +92,12 @@ bool RandomJumpImporter::handle_ip_event(fail::simtime_t curtime, instruction_co
|
||||
|
||||
// skip events that are outside the memory map. -m instruction map
|
||||
if (m_mm && !m_mm->isMatching(ev.ip())) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// skip events that are outside the --jump-from memory map.
|
||||
if (!m_mm_from->isMatching(ev.ip())) {
|
||||
return true;
|
||||
if (m_mm_from && !m_mm_from->isMatching(ev.ip())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -120,7 +121,7 @@ bool RandomJumpImporter::handle_ip_event(fail::simtime_t curtime, instruction_co
|
||||
// pass through potentially available extended trace information
|
||||
ev.set_accesstype(ev.READ); // instruction fetch is always a read
|
||||
ev.set_memaddr(to_addr);
|
||||
ev.set_width(4); // FIXME arbitrary?
|
||||
ev.set_width(4); // FIXME arbitrary, use Instr.length instead?
|
||||
if (!add_trace_event(margin, margin, ev)) {
|
||||
LOG << "add_trace_event failed" << std::endl;
|
||||
return false;
|
||||
|
||||
@ -16,6 +16,7 @@ class RandomJumpImporter : public Importer {
|
||||
fail::MemoryMap *m_mm_from, *m_mm_to;
|
||||
std::vector<fail::guest_address_t> m_jump_to_addresses;
|
||||
public:
|
||||
RandomJumpImporter() : m_mm_from(0), m_mm_to(0) {}
|
||||
/**
|
||||
* Callback function that can be used to add command line options
|
||||
* to the campaign
|
||||
|
||||
@ -17,12 +17,12 @@ static Logger LOG("RegisterImporter");
|
||||
bool RegisterImporter::cb_commandline_init() {
|
||||
CommandLine &cmd = CommandLine::Inst();
|
||||
|
||||
NO_GP = cmd.addOption("", "no-gp", Arg::None,
|
||||
"--no-gp\t RegisterImporter: do not inject general purpose registers\n");
|
||||
NO_GP = cmd.addOption("", "no-gp", Arg::None,
|
||||
"--no-gp \tRegisterImporter: do not inject general purpose registers");
|
||||
FLAGS = cmd.addOption("", "flags", Arg::None,
|
||||
"--flags: RegisterImporter: trace flags register\n");
|
||||
IP = cmd.addOption("", "ip", Arg::None,
|
||||
"--ip: RegisterImporter: trace instruction pointer\n");
|
||||
"--flags \tRegisterImporter: inject flags register");
|
||||
IP = cmd.addOption("", "ip", Arg::None,
|
||||
"--ip \tRegisterImporter: inject instruction pointer");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -85,17 +85,9 @@ bool RegisterImporter::handle_ip_event(fail::simtime_t curtime, instruction_coun
|
||||
std::cerr << "Error parsing arguments." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read FROM memory file
|
||||
if (cmd[NO_GP].count() > 0) {
|
||||
do_gp = false;
|
||||
}
|
||||
if (cmd[FLAGS].count() > 0) {
|
||||
do_flags = true;
|
||||
}
|
||||
if (cmd[IP].count() > 0) {
|
||||
do_ip = true;
|
||||
}
|
||||
do_gp = !cmd[NO_GP];
|
||||
do_flags = cmd[FLAGS];
|
||||
do_ip = cmd[IP];
|
||||
|
||||
/* Disassemble the binary if necessary */
|
||||
llvm::InitializeAllTargetInfos();
|
||||
@ -125,7 +117,7 @@ bool RegisterImporter::handle_ip_event(fail::simtime_t curtime, instruction_coun
|
||||
const LLVMDisassembler::Instr &opcode = instr_map.at(ev.ip());
|
||||
//const MCRegisterInfo ®_info = disas->getRegisterInfo();
|
||||
|
||||
fail::LLVMtoFailTranslator & ltof = disas->getTranslator() ;
|
||||
fail::LLVMtoFailTranslator & ltof = disas->getTranslator() ;
|
||||
|
||||
for (std::vector<LLVMDisassembler::register_t>::const_iterator it = opcode.reg_uses.begin();
|
||||
it != opcode.reg_uses.end(); ++it) {
|
||||
|
||||
@ -49,8 +49,7 @@ ProtoIStream openProtoStream(std::string input_file) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::string trace_file, username, hostname, database, benchmark;
|
||||
std::string variant;
|
||||
std::string trace_file, variant, benchmark;
|
||||
ElfReader *elf_file = 0;
|
||||
MemoryMap *memorymap = 0;
|
||||
|
||||
@ -108,7 +107,7 @@ int main(int argc, char *argv[]) {
|
||||
CommandLine::option_handle ENABLE_SANITYCHECKS =
|
||||
cmd.addOption("", "enable-sanitychecks", Arg::None,
|
||||
"--enable-sanitychecks \tEnable sanity checks "
|
||||
"(in case something looks fishy)"
|
||||
"(in case something looks fishy) "
|
||||
"(default: disabled)");
|
||||
|
||||
if (!cmd.parse()) {
|
||||
@ -118,28 +117,28 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
Importer *importer;
|
||||
|
||||
if (cmd[IMPORTER].count() > 0) {
|
||||
if (cmd[IMPORTER]) {
|
||||
std::string imp(cmd[IMPORTER].first()->arg);
|
||||
if (imp == "BasicImporter" || imp == "MemoryImporter" || imp == "memory" || imp == "mem") {
|
||||
LOG << "Using MemoryImporter" << endl;
|
||||
imp = "MemoryImporter";
|
||||
importer = new MemoryImporter();
|
||||
#ifdef BUILD_LLVM_DISASSEMBLER
|
||||
} else if (imp == "InstructionImporter" || imp == "code") {
|
||||
LOG << "Using InstructionImporter" << endl;
|
||||
imp = "InstructionImporter";
|
||||
importer = new InstructionImporter();
|
||||
|
||||
} else if (imp == "RegisterImporter" || imp == "regs") {
|
||||
LOG << "Using RegisterImporter" << endl;
|
||||
imp = "RegisterImporter";
|
||||
importer = new RegisterImporter();
|
||||
|
||||
} else if (imp == "RandomJumpImporter") {
|
||||
LOG << "Using RandomJumpImporter" << endl;
|
||||
importer = new RandomJumpImporter();
|
||||
#endif
|
||||
} else {
|
||||
LOG << "Unkown import method: " << imp << endl;
|
||||
exit(-1);
|
||||
}
|
||||
LOG << "Using " << imp << endl;
|
||||
|
||||
} else {
|
||||
LOG << "Using MemoryImporter" << endl;
|
||||
@ -160,30 +159,33 @@ int main(int argc, char *argv[]) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (cmd[TRACE_FILE].count() > 0)
|
||||
if (cmd[TRACE_FILE]) {
|
||||
trace_file = std::string(cmd[TRACE_FILE].first()->arg);
|
||||
else
|
||||
} else {
|
||||
trace_file = "trace.pb";
|
||||
}
|
||||
|
||||
ProtoIStream ps = openProtoStream(trace_file);
|
||||
Database *db = Database::cmdline_connect();
|
||||
|
||||
if (cmd[VARIANT].count() > 0)
|
||||
if (cmd[VARIANT]) {
|
||||
variant = std::string(cmd[VARIANT].first()->arg);
|
||||
else
|
||||
} else {
|
||||
variant = "none";
|
||||
}
|
||||
|
||||
if (cmd[BENCHMARK].count() > 0)
|
||||
if (cmd[BENCHMARK]) {
|
||||
benchmark = std::string(cmd[BENCHMARK].first()->arg);
|
||||
else
|
||||
} else {
|
||||
benchmark = "none";
|
||||
}
|
||||
|
||||
if (cmd[ELF_FILE].count() > 0) {
|
||||
if (cmd[ELF_FILE]) {
|
||||
elf_file = new ElfReader(cmd[ELF_FILE].first()->arg);
|
||||
}
|
||||
importer->set_elf(elf_file);
|
||||
|
||||
if (cmd[MEMORYMAP].count() > 0) {
|
||||
if (cmd[MEMORYMAP]) {
|
||||
memorymap = new MemoryMap();
|
||||
for (option::Option *o = cmd[MEMORYMAP]; o; o = o->next()) {
|
||||
if (!memorymap->readFromFile(o->arg)) {
|
||||
@ -193,7 +195,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
importer->set_memorymap(memorymap);
|
||||
|
||||
if (cmd[FAULTSPACE_RIGHTMARGIN].count() > 0) {
|
||||
if (cmd[FAULTSPACE_RIGHTMARGIN]) {
|
||||
std::string rightmargin(cmd[FAULTSPACE_RIGHTMARGIN].first()->arg);
|
||||
if (rightmargin == "W") {
|
||||
importer->set_faultspace_rightmargin('W');
|
||||
@ -207,12 +209,8 @@ int main(int argc, char *argv[]) {
|
||||
importer->set_faultspace_rightmargin('W');
|
||||
}
|
||||
|
||||
if (cmd[ENABLE_SANITYCHECKS].count() > 0) {
|
||||
importer->set_sanitychecks(true);
|
||||
}
|
||||
if (cmd[EXTENDED_TRACE].count() > 0) {
|
||||
importer->set_extended_trace(true);
|
||||
}
|
||||
importer->set_sanitychecks(cmd[ENABLE_SANITYCHECKS]);
|
||||
importer->set_extended_trace(cmd[EXTENDED_TRACE]);
|
||||
|
||||
if (!importer->init(variant, benchmark, db)) {
|
||||
LOG << "importer->init() failed" << endl;
|
||||
@ -228,7 +226,7 @@ int main(int argc, char *argv[]) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (cmd[NO_DELETE].count() == 0 && !importer->clear_database()) {
|
||||
if (!cmd[NO_DELETE] && !importer->clear_database()) {
|
||||
LOG << "clear_database() failed" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user