Reverse search getNameByAddress.

Implemented with the help of boost bimap.



git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1983 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
hoffmann
2012-12-20 22:06:46 +00:00
parent f8aa1237e9
commit 5a3a66da25
2 changed files with 169 additions and 137 deletions

View File

@ -89,27 +89,42 @@ 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_log << " " << (i) << " " << name_buf+idx << " @ " << mysym.st_value << std::endl; m_log << " " << (i) << " " << name_buf+idx << " @ " << mysym.st_value << std::endl;
m_map[name_buf+idx] = mysym.st_value; #ifndef __puma
m_bimap.insert( entry(name_buf+idx, mysym.st_value) );
#endif
} }
} }
free (name_buf); free (name_buf);
return 0; return 0;
} }
guest_address_t ElfReader::getAddressByName(const std::string& name) { guest_address_t ElfReader::getAddressByName(const std::string& name) {
if( m_map.find(name) == m_map.end() ) { #ifndef __puma
typedef bimap_t::left_map::const_iterator const_iterator_t;
const_iterator_t iterator = m_bimap.left.find(name);
if(iterator == m_bimap.left.end()){
return ADDR_INV; return ADDR_INV;
}else{ }else{
return m_map[name]; return iterator->second;
} }
#endif
} }
std::string getNameByAddress(guest_address_t address) { std::string ElfReader::getNameByAddress(guest_address_t address) {
return "Test"; #ifndef __puma
// .right switches key/value
typedef bimap_t::right_map::const_iterator const_iterator_t;
const_iterator_t iterator = m_bimap.right.find(address);
if(iterator == m_bimap.right.end()){
return "[ElfReader] FUNCTION NOT FOUND";
}else{
return iterator->second;
}
#endif
} }
} // end-of-namespace fail } // end-of-namespace fail

View File

@ -2,11 +2,24 @@
#define __ELFREADER_HPP__ #define __ELFREADER_HPP__
#include <string> #include <string>
#include <map> #ifndef __puma
#include <boost/bimap.hpp>
#endif
#include "sal/SALConfig.hpp" #include "sal/SALConfig.hpp"
#include "Logger.hpp" #include "Logger.hpp"
template< class MapType >
void print_map(const MapType & map)
{
typedef typename MapType::const_iterator const_iterator;
for( const_iterator i = map.begin(), iend = map.end(); i != iend; ++i )
{
std::cout << i->first << " -- " << i->second << std::endl;
}
}
namespace fail { namespace fail {
/** /**
@ -47,8 +60,12 @@ public:
private: private:
Logger m_log; Logger m_log;
std::map<std::string, guest_address_t> m_map;
#ifndef __puma
typedef boost::bimap< std::string, guest_address_t > bimap_t;
typedef bimap_t::value_type entry;
bimap_t m_bimap;
#endif
int process_symboltable(int sect_num, FILE* fp); int process_symboltable(int sect_num, FILE* fp);
}; };