ElfReader: add some convenience functions
This commit is contained in:
@ -11,6 +11,8 @@
|
|||||||
#include "Event.hpp"
|
#include "Event.hpp"
|
||||||
#include "ConcreteCPU.hpp"
|
#include "ConcreteCPU.hpp"
|
||||||
#include "perf/BufferInterface.hpp"
|
#include "perf/BufferInterface.hpp"
|
||||||
|
#include "util/ElfReader.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace fail {
|
namespace fail {
|
||||||
|
|
||||||
@ -301,6 +303,11 @@ public:
|
|||||||
MemAccessEvent::access_type_t type = MemAccessEvent::MEM_READWRITE,
|
MemAccessEvent::access_type_t type = MemAccessEvent::MEM_READWRITE,
|
||||||
ConcreteCPU* cpu = NULL)
|
ConcreteCPU* cpu = NULL)
|
||||||
: BaseListener(cpu), m_WatchAddr(addr), m_WatchWidth(1), m_WatchType(type) { }
|
: BaseListener(cpu), m_WatchAddr(addr), m_WatchWidth(1), m_WatchType(type) { }
|
||||||
|
MemAccessListener(const ElfSymbol &symbol,
|
||||||
|
MemAccessEvent::access_type_t type = MemAccessEvent::MEM_READWRITE,
|
||||||
|
ConcreteCPU* cpu = NULL)
|
||||||
|
: BaseListener(cpu), m_WatchAddr(symbol.getAddress()), m_WatchWidth(symbol.getSize()), m_WatchType(type) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the physical memory address to be observed.
|
* Returns the physical memory address to be observed.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -18,6 +18,13 @@ bool operator==(guest_address_t address, const ElfSymbol & sym) {
|
|||||||
return sym.getAddress() == address;
|
return sym.getAddress() == address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<< (std::ostream &out, const ElfSymbol &symbol) {
|
||||||
|
return (out << symbol.getName()
|
||||||
|
<< " @ 0x" << std::hex << symbol.getAddress()
|
||||||
|
<< " size " << std::dec << symbol.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ElfReader::ElfReader() : m_log("Fail*Elfinfo", false){
|
ElfReader::ElfReader() : m_log("Fail*Elfinfo", false){
|
||||||
// try to open elf file from environment variable
|
// try to open elf file from environment variable
|
||||||
@ -157,7 +164,8 @@ int ElfReader::process_symboltable(int sect_num, FILE* fp){
|
|||||||
|
|
||||||
int type = ELF32_ST_TYPE(mysym.st_info);
|
int type = ELF32_ST_TYPE(mysym.st_info);
|
||||||
if((type != STT_SECTION) && (type != STT_FILE)){
|
if((type != STT_SECTION) && (type != STT_FILE)){
|
||||||
m_symboltable.push_back( ElfSymbol(name_buf+idx, mysym.st_value, mysym.st_size, ElfSymbol::SYMBOL) );
|
m_symboltable.push_back( ElfSymbol(name_buf+idx, mysym.st_value, mysym.st_size, ElfSymbol::SYMBOL,
|
||||||
|
type) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free (name_buf);
|
free (name_buf);
|
||||||
|
|||||||
@ -21,21 +21,26 @@ namespace fail {
|
|||||||
guest_address_t address;
|
guest_address_t address;
|
||||||
size_t size;
|
size_t size;
|
||||||
int m_type;
|
int m_type;
|
||||||
|
int m_symbol_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum { SECTION = 1, SYMBOL = 2, UNDEFINED = 3, };
|
enum { SECTION = 1, SYMBOL = 2, UNDEFINED = 3, };
|
||||||
|
|
||||||
ElfSymbol(const std::string & name = ELF::NOTFOUND, guest_address_t addr = ADDR_INV, size_t size = -1, int type = UNDEFINED)
|
ElfSymbol(const std::string & name = ELF::NOTFOUND, guest_address_t addr = ADDR_INV, size_t size = -1, int type = UNDEFINED,
|
||||||
: name(name), address(addr), size(size), m_type(type) {};
|
int symbol_type = 0)
|
||||||
|
: name(name), address(addr), size(size), m_type(type), m_symbol_type(symbol_type) {};
|
||||||
|
|
||||||
const std::string& getName() const { return name; };
|
const std::string& getName() const { return name; };
|
||||||
|
std::string getDemangledName() const { return Demangler::demangle(name); };
|
||||||
guest_address_t getAddress() const { return address; };
|
guest_address_t getAddress() const { return address; };
|
||||||
size_t getSize() const { return size; };
|
size_t getSize() const { return size; };
|
||||||
guest_address_t getStart() const { return getAddress(); }; // alias
|
guest_address_t getStart() const { return getAddress(); }; // alias
|
||||||
guest_address_t getEnd() const { return address + size; };
|
guest_address_t getEnd() const { return address + size; };
|
||||||
|
int getSymbolType() const { return m_symbol_type; };
|
||||||
|
|
||||||
bool isSection() const { return m_type == SECTION; };
|
bool isSection() const { return m_type == SECTION; };
|
||||||
bool isSymbol() const { return m_type == SYMBOL; };
|
bool isSymbol() const { return m_type == SYMBOL; };
|
||||||
|
bool isValid() const { return name != ELF::NOTFOUND; };
|
||||||
|
|
||||||
bool operator==(const std::string& rhs) const {
|
bool operator==(const std::string& rhs) const {
|
||||||
if(rhs == name){
|
if(rhs == name){
|
||||||
@ -56,7 +61,12 @@ namespace fail {
|
|||||||
return (ad >= address) && (ad < address+size);
|
return (ad >= address) && (ad < address+size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* \fn
|
||||||
|
* \relates ElfSymbol
|
||||||
|
* overloaded stream operator for printing ElfSymbol
|
||||||
|
*/
|
||||||
|
std::ostream& operator<< (std::ostream &out, const ElfSymbol &symbol);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class ElfReader
|
* \class ElfReader
|
||||||
@ -67,6 +77,9 @@ namespace fail {
|
|||||||
class ElfReader {
|
class ElfReader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef ElfSymbol entry_t;
|
||||||
|
typedef std::vector<entry_t> container_t;
|
||||||
|
typedef container_t::const_iterator symbol_iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -124,6 +137,13 @@ namespace fail {
|
|||||||
*/
|
*/
|
||||||
const ElfSymbol& getSection( const std::string& name );
|
const ElfSymbol& getSection( const std::string& name );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get symboltable iterator. Derefences to a ElfSymbol
|
||||||
|
* @return iterator
|
||||||
|
*/
|
||||||
|
container_t::const_iterator sym_begin() { return m_symboltable.begin(); }
|
||||||
|
container_t::const_iterator sym_end() { return m_symboltable.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Logger m_log;
|
Logger m_log;
|
||||||
|
|
||||||
@ -131,9 +151,6 @@ namespace fail {
|
|||||||
int process_symboltable(int sect_num, FILE* fp);
|
int process_symboltable(int sect_num, FILE* fp);
|
||||||
int process_section(Elf32_Shdr *sect_hdr, char* sect_name_buff);
|
int process_section(Elf32_Shdr *sect_hdr, char* sect_name_buff);
|
||||||
|
|
||||||
typedef ElfSymbol entry_t;
|
|
||||||
typedef std::vector<entry_t> container_t;
|
|
||||||
|
|
||||||
container_t m_symboltable;
|
container_t m_symboltable;
|
||||||
container_t m_sectiontable;
|
container_t m_sectiontable;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user