ElfReader: Constructor tries to get ELF from ENV FAIL_ELF_PATH
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@2002 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -10,6 +10,7 @@ Required for Fail*:
|
||||
- protobuf-compiler
|
||||
- cmake
|
||||
- cmake-curses-gui
|
||||
- binutils-dev
|
||||
- AspectC++ (ag++, ac++): AspectC++ 1.1 or newer is known to work and can be
|
||||
obtained from http://www.aspectc.org; nightlies can be downloaded from
|
||||
http://akut.aspectc.org
|
||||
|
||||
@ -10,7 +10,8 @@ namespace fail {
|
||||
|
||||
const std::string ElfReader::NOTFOUND = "[ELFReader] Function not found.";
|
||||
|
||||
ElfReader::ElfReader(const char* path) : m_log("Fail*Elfinfo", false){
|
||||
|
||||
void ElfReader::setup(const char* path) {
|
||||
// Try to open the ELF file
|
||||
FILE * fp = fopen(path, "r");
|
||||
if (!fp) {
|
||||
@ -50,6 +51,20 @@ const std::string ElfReader::NOTFOUND = "[ELFReader] Function not found.";
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
ElfReader::ElfReader() : m_log("Fail*Elfinfo", false){
|
||||
// try to open elf file from environment variable
|
||||
char * elfpath = getenv("FAIL_ELF_PATH");
|
||||
if(elfpath == NULL){
|
||||
m_log << "FAIL_ELF_PATH not set :(" << std::endl;
|
||||
}else{
|
||||
setup(elfpath);
|
||||
}
|
||||
}
|
||||
|
||||
ElfReader::ElfReader(const char* path) : m_log("Fail*Elfinfo", false){
|
||||
setup(path);
|
||||
}
|
||||
|
||||
int ElfReader::process_symboltable(int sect_num, FILE* fp){
|
||||
|
||||
Elf32_Shdr sect_hdr;
|
||||
|
||||
@ -28,6 +28,12 @@ namespace fail {
|
||||
*/
|
||||
ElfReader(const char* path);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @note The path is guessed from a FAIL_ELF_PATH environment variable
|
||||
*/
|
||||
ElfReader();
|
||||
|
||||
/**
|
||||
* Get guest address by symbol name.
|
||||
* Both mangled an demangled symbols are searched.
|
||||
@ -79,6 +85,7 @@ namespace fail {
|
||||
Logger m_log;
|
||||
|
||||
|
||||
void setup(const char*);
|
||||
int process_symboltable(int sect_num, FILE* fp);
|
||||
#ifndef __puma
|
||||
typedef boost::bimap< std::string, guest_address_t > bimap_t;
|
||||
|
||||
@ -5,9 +5,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util/Logger.hpp"
|
||||
|
||||
#include "util/ElfReader.hpp"
|
||||
#include <stdlib.h>
|
||||
#include "experiment.hpp"
|
||||
#include "experimentInfo.hpp"
|
||||
@ -28,61 +26,58 @@ using namespace fail;
|
||||
#error This experiment needs: breakpoints, traps, save, and restore. Enable these in the configuration.
|
||||
#endif
|
||||
|
||||
#define SAVESTATE (1)
|
||||
|
||||
void VEZSExperiment::printEIP() {
|
||||
m_log << "EIP = 0x" << hex << simulator.getCPU(0).getInstructionPointer() <<" "<< m_elf.getNameByAddress(simulator.getCPU(0).getInstructionPointer()) << endl;
|
||||
}
|
||||
|
||||
bool VEZSExperiment::run()
|
||||
{
|
||||
Logger log("VEZS-Example", false);
|
||||
// Elf image path must be set in a environment variable.
|
||||
char * elfpath = getenv("CIAO_ELF_PATH");
|
||||
if(elfpath == NULL){
|
||||
log << " CIAO_ELF_PATH not set :(" << std::endl;
|
||||
simulator.terminate();
|
||||
}
|
||||
|
||||
ElfReader elf(elfpath);
|
||||
log << "STARTING EXPERIMENT" << endl;
|
||||
log << "main() address: " << elf.getAddressByName("main") << endl;
|
||||
//elf.printMangled();
|
||||
//elf.printDemangled();
|
||||
m_log << "STARTING EXPERIMENT" << endl;
|
||||
printEIP();
|
||||
|
||||
#if(SAVESTATE)
|
||||
m_log << "Booting, and saving state at ";
|
||||
BPSingleListener bp;
|
||||
#if 0
|
||||
// STEP 1: run until interesting function starts, and save state
|
||||
bp.setWatchInstructionPointer(elf.getAddressByName("main"));
|
||||
bp.setWatchInstructionPointer(m_elf.getAddressByName("main"));
|
||||
if(simulator.addListenerAndResume(&bp) == &bp){
|
||||
log << "test function entry reached, saving state" << endl;
|
||||
m_log << "test function entry reached, saving state" << endl;
|
||||
}
|
||||
log << "EIP = " << hex << bp.getTriggerInstructionPointer() << endl;
|
||||
printEIP();
|
||||
//simulator.terminate();
|
||||
simulator.save("vezs.state");
|
||||
simulator.terminate();
|
||||
#endif
|
||||
#if 1
|
||||
#else
|
||||
|
||||
//int bit_offset = 2;
|
||||
//for (int instr_offset = 0; instr_offset < OOSTUBS_NUMINSTR; ++instr_offset) {
|
||||
|
||||
// STEP 3: The actual experiment.
|
||||
log << "restoring state" << endl;
|
||||
m_log << "restoring state" << endl;
|
||||
simulator.restore("vezs.state");
|
||||
|
||||
log << " current EIP = " << simulator.getCPU(0).getInstructionPointer() << endl;
|
||||
BPSingleListener bpt0;
|
||||
BPSingleListener bpt1;
|
||||
bpt0.setWatchInstructionPointer(elf.getAddressByName("Alpha::functionTaskTask0"));
|
||||
bpt1.setWatchInstructionPointer(elf.getAddressByName("_ZN4Beta17functionTaskTask1Ev")); // both mangled and demangled name a working.
|
||||
printEIP();
|
||||
|
||||
simulator.addListener(&bpt1);
|
||||
simulator.addListenerAndResume(&bpt0);
|
||||
log << "EIP = " << simulator.getCPU(0).getInstructionPointer() <<" "<<elf.getMangledNameByAddress(simulator.getCPU(0).getInstructionPointer()) << endl;
|
||||
// BPSingleListener bpt0;
|
||||
// BPSingleListener bpt1;
|
||||
// m_elf.printDemangled();
|
||||
// bpt0.setWatchInstructionPointer(m_elf.getAddressByName("DOM1::functionTaskmainTask"));
|
||||
// bpt1.setWatchInstructionPointer(m_elf.getAddressByName("DOM1::functionTaskpersistentDetectorScopeEntryTask")); // both mangled and demangled name a working.
|
||||
//
|
||||
// simulator.addListener(&bpt1);
|
||||
// simulator.addListenerAndResume(&bpt0);
|
||||
// printEIP();
|
||||
simulator.resume();
|
||||
log << "EIP = " << simulator.getCPU(0).getInstructionPointer() <<" "<<elf.getNameByAddress(simulator.getCPU(0).getInstructionPointer()) << endl;
|
||||
|
||||
simulator.clearListeners();
|
||||
bpt1.setWatchInstructionPointer(elf.getAddressByName("os::krn::SchedImpl::superDispatch_impl"));
|
||||
for(int i = 0; i < 10; i++){
|
||||
simulator.addListenerAndResume(&bpt1);
|
||||
log << "EIP = " << simulator.getCPU(0).getInstructionPointer() <<" "<< elf.getNameByAddress(simulator.getCPU(0).getInstructionPointer()) << endl;
|
||||
}
|
||||
//
|
||||
// printEIP();
|
||||
// simulator.clearListeners();
|
||||
// bpt1.setWatchInstructionPointer(m_elf.getAddressByName("os::krn::SchedImpl::superDispatch_impl"));
|
||||
// for(;;){
|
||||
// simulator.addListenerAndResume(&bpt1);
|
||||
// printEIP();
|
||||
// }
|
||||
#endif
|
||||
#if 0
|
||||
int32_t data = simulator.getCPU(0).getRegister(RID_CAX)->getData();
|
||||
|
||||
@ -3,10 +3,19 @@
|
||||
|
||||
#include "efw/ExperimentFlow.hpp"
|
||||
#include "efw/JobClient.hpp"
|
||||
#include "util/Logger.hpp"
|
||||
#include "util/ElfReader.hpp"
|
||||
|
||||
class VEZSExperiment : public fail::ExperimentFlow {
|
||||
|
||||
fail::JobClient m_jc;
|
||||
fail::ElfReader m_elf;
|
||||
fail::Logger m_log;
|
||||
|
||||
void printEIP();
|
||||
|
||||
public:
|
||||
VEZSExperiment() : m_log("VEZS-example", false) {};
|
||||
bool run();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user