int main(int argc, char *argv[]) { ROSE_INITIALIZE; Diagnostics::initAndRegister(&mlog, "tool"); // Parse command line Settings settings; std::vector<std::string> args = parseCommandLine(argc, argv, settings).unreachedArgs(); if (args.size()!=2) throw std::runtime_error("invalid usage; see --help"); // Load the CSV files FunctionByAddress code1, data1, code2, data2; readCsvFile(args[0], code1 /*out*/, data1 /*out*/); readCsvFile(args[1], code2 /*out*/, data2 /*out*/); showStats(FileSystem::Path(args[0]).filename().string(), code1, data1, FileSystem::Path(args[1]).filename().string(), code2, data2); std::cout <<"\n"; // Parse the specimen if (!settings.specimenName.empty()) { P2::Engine engine; MemoryMap::Ptr map = engine.loadSpecimens(settings.specimenName); InstructionProvider::Ptr insns = InstructionProvider::instance(engine.obtainDisassembler(), map); map->dump(std::cout); listInstructions(insns, map, code1, code2); } }
int main(int argc, char *argv[]) { ROSE_INITIALIZE; Diagnostics::initAndRegister(&::mlog, "tool"); // Parse command-line P2::Engine engine; Settings settings; std::vector<std::string> specimen = parseCommandLine(argc, argv, engine, settings); if (specimen.empty()) { ::mlog[FATAL] <<"no specimen supplied on command-line; see --help\n"; exit(1); } // Load specimen into ROSE's simulated memory if (!engine.parseContainers(specimen.front())) { ::mlog[FATAL] <<"cannot parse specimen binary container\n"; exit(1); } Disassembler *disassembler = engine.obtainDisassembler(); if (!disassembler) { ::mlog[FATAL] <<"no disassembler for this architecture\n"; exit(1); } const RegisterDescriptor REG_IP = disassembler->instructionPointerRegister(); ASSERT_require2(REG_IP.is_valid(), "simulation must know what register serves as the instruction pointer"); // Single-step the specimen natively in a debugger and show each instruction. BinaryDebugger debugger(specimen); while (!debugger.isTerminated()) { uint64_t ip = debugger.readRegister(REG_IP).toInteger(); uint8_t buf[16]; // 16 should be large enough for any instruction size_t nBytes = debugger.readMemory(ip, sizeof buf, buf); if (0 == nBytes) { ::mlog[ERROR] <<"cannot read memory at " <<StringUtility::addrToString(ip) <<"\n"; } else if (SgAsmInstruction *insn = disassembler->disassembleOne(buf, ip, nBytes, ip)) { std::cout <<unparseInstructionWithAddress(insn) <<"\n"; } else { ::mlog[ERROR] <<"cannot disassemble instruction at " <<StringUtility::addrToString(ip) <<"\n"; } debugger.singleStep(); } std::cout <<debugger.howTerminated(); }
SgAsmInterpretation* RSIM_ColdFire::parseMainExecutable(RSIM_Process *process) { namespace P2 = rose::BinaryAnalysis::Partitioner2; using namespace Sawyer::CommandLine; // This is raw hardware, so assume that all the arguments are for loading the specimen. P2::Engine engine; Parser parser; parser .purpose("initializes ColdFire memory") .version(std::string(ROSE_SCM_VERSION_ID).substr(0, 8), ROSE_CONFIGURE_DATE) .chapter(1, "ROSE Command-line Tools") .doc("Synopsis", "@prop{programName} ... -- [@v{loader_switches}] @v{resources}") .doc("Description", "This part of the simulator command-line is responsible for configuring how @v{resources} are loaded into " "simulated FreeScale ColdFire system memory. If switches are provided here they must be separated from " "simulator switches with a \"--\" to prevent the simulator itself from interpreting them.\n\n" + engine.specimenNameDocumentation()) .with(Switch("help", 'h') .hidden(true) .action(showHelpAndExit(0))) .with(engine.loaderSwitches()); std::vector<std::string> resources = parser.parse(exeArgs()).apply().unreachedArgs(); engine.isaName("coldfire"); MemoryMap::Ptr map = engine.loadSpecimens(resources); process->mem_transaction_start("specimen main memory"); *process->get_memory() = *map; // shallow copy, new segments point to same old data // The initial program counter is stored at address 4, the second entry in the interrupt vector. uint32_t initialIpBe = 0; if (!map->at(4).limit(sizeof initialIpBe).read((uint8_t*)&initialIpBe)) { mlog[FATAL] <<"failed to read initial program counter from address zero\n"; exit(1); } uint32_t initialIp = ByteOrder::be_to_host(initialIpBe); process->entryPointOriginalVa(initialIp); process->entryPointStartVa(initialIp); process->disassembler(engine.obtainDisassembler()); return engine.interpretation(); // probably null since args not likely to be ELF or PE }