From 125e510ee95e9e1aaba461a7ec0c962eeb39dd9b Mon Sep 17 00:00:00 2001 From: jdh8d <jdh8d@git.zephyr-software.com> Date: Fri, 12 Feb 2016 02:52:49 +0000 Subject: [PATCH] Former-commit-id: 63354dfe518e5dd8426ac7590775936d931f5a3b --- libIRDB/include/core/file.hpp | 1 + libIRDB/include/core/fileir.hpp | 5 +++ libIRDB/include/core/scoop.hpp | 2 ++ libIRDB/src/core/SConscript | 1 + libIRDB/src/core/fileir.cpp | 58 +++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/libIRDB/include/core/file.hpp b/libIRDB/include/core/file.hpp index aefafef8b..26e297721 100644 --- a/libIRDB/include/core/file.hpp +++ b/libIRDB/include/core/file.hpp @@ -60,6 +60,7 @@ class File_t : public BaseObj_t friend class AggregateType_t; friend class FuncType_t; friend class ICFS_t; + friend class DataScoop_t; // friend class IBTargets; private: diff --git a/libIRDB/include/core/fileir.hpp b/libIRDB/include/core/fileir.hpp index 017173d03..73e7fc699 100644 --- a/libIRDB/include/core/fileir.hpp +++ b/libIRDB/include/core/fileir.hpp @@ -105,6 +105,11 @@ class FileIR_t : public BaseObj_t std::map<db_id_t,AddressID_t*> &addrMap, std::map<db_id_t,Type_t*> &typeMap ); + void ReadScoopsFromDB + ( + std::map<db_id_t,AddressID_t*> &addrMap, + std::map<db_id_t,Type_t*> &typeMap + ); std::map<db_id_t,Instruction_t*> ReadInsnsFromDB ( std::map<db_id_t,Function_t*> &funcMap, diff --git a/libIRDB/include/core/scoop.hpp b/libIRDB/include/core/scoop.hpp index 98d74c2d2..343bfc08d 100644 --- a/libIRDB/include/core/scoop.hpp +++ b/libIRDB/include/core/scoop.hpp @@ -63,6 +63,8 @@ class DataScoop_t : public BaseObj_t void ClearWriteable() { permissions &= ~permissions_w; } void ClearExecuteable() { permissions &= ~permissions_x; } + std::string WriteToDB(File_t *fid, db_id_t newid); + private: const int permissions_r=4; const int permissions_w=2; diff --git a/libIRDB/src/core/SConscript b/libIRDB/src/core/SConscript index 0090dbe1b..4152768f8 100644 --- a/libIRDB/src/core/SConscript +++ b/libIRDB/src/core/SConscript @@ -18,6 +18,7 @@ files= ''' instruction.cpp pqxxdb.cpp type.cpp + scoop.cpp variantid.cpp ''' cpppath=''' diff --git a/libIRDB/src/core/fileir.cpp b/libIRDB/src/core/fileir.cpp index af2bbcc89..0df0ff72e 100644 --- a/libIRDB/src/core/fileir.cpp +++ b/libIRDB/src/core/fileir.cpp @@ -117,6 +117,7 @@ void FileIR_t::ReadFromDB() std::map<db_id_t,Type_t*> typesMap = ReadTypesFromDB(types); std::map<db_id_t,AddressID_t*> addrMap=ReadAddrsFromDB(); std::map<db_id_t,Function_t*> funcMap=ReadFuncsFromDB(addrMap, typesMap); + ReadScoopsFromDB(addrMap, typesMap); std::map<db_id_t,Instruction_t*> addressToInstructionMap; std::map<Instruction_t*, db_id_t> unresolvedICFS; @@ -615,6 +616,13 @@ void FileIR_t::WriteToDB() string q = icfs->WriteToDB(fileptr); dbintr->IssueQuery(q); } + for(DataScoopSet_t::const_iterator it=scoops.begin(); it!=scoops.end(); ++it) + { + DataScoop_t* scoop = *it; + assert(scoop); + string q = scoop->WriteToDB(fileptr,j); + dbintr->IssueQuery(q); + } } @@ -632,6 +640,10 @@ void FileIR_t::SetBaseIDS() j=MAX(j,(*i)->GetBaseID()); for(std::set<Relocation_t*>::const_iterator i=relocs.begin(); i!=relocs.end(); ++i) j=MAX(j,(*i)->GetBaseID()); + for(std::set<Type_t*>::const_iterator i=types.begin(); i!=types.end(); ++i) + j=MAX(j,(*i)->GetBaseID()); + for(DataScoopSet_t::const_iterator i=scoops.begin(); i!=scoops.end(); ++i) + j=MAX(j,(*i)->GetBaseID()); /* increment past the max ID so we don't duplicate */ j++; @@ -652,6 +664,9 @@ void FileIR_t::SetBaseIDS() for(std::set<Type_t*>::const_iterator i=types.begin(); i!=types.end(); ++i) if((*i)->GetBaseID()==NOT_IN_DATABASE) (*i)->SetBaseID(j++); + for(DataScoopSet_t::const_iterator i=scoops.begin(); i!=scoops.end(); ++i) + if((*i)->GetBaseID()==NOT_IN_DATABASE) + (*i)->SetBaseID(j++); } std::string Relocation_t::WriteToDB(File_t* fid, Instruction_t* myinsn) @@ -1111,3 +1126,46 @@ void FileIR_t::CleanupICFS() GarbageCollectICFS(); DedupICFS(); } + +void FileIR_t::ReadScoopsFromDB + ( + std::map<db_id_t,AddressID_t*> &addrMap, + std::map<db_id_t,Type_t*> &typeMap + ) +{ +/* + scoop_id SERIAL PRIMARY KEY, -- key + name text DEFAULT '', -- string representation of the type + type_id integer, -- the type of the data, as an index into the table table. + start_address_id integer, -- address id for start. + end_address_id integer, -- address id for end + permissions integer -- in umask format (bitmask for rwx) + + */ + + std::string q= "select * from " + fileptr->scoop_table_name + " ; "; + + dbintr->IssueQuery(q); + + while(!dbintr->IsDone()) + { + + db_id_t sid=atoi(dbintr->GetResultColumn("scoop_id").c_str()); + std::string name=dbintr->GetResultColumn("name"); + db_id_t type_id=atoi(dbintr->GetResultColumn("type_id").c_str()); + Type_t *type=typeMap[type_id]; + db_id_t start_id=atoi(dbintr->GetResultColumn("start_address_id").c_str()); + AddressID_t* start_addr=addrMap[start_id]; + db_id_t end_id=atoi(dbintr->GetResultColumn("end_address_id").c_str()); + AddressID_t* end_addr=addrMap[end_id]; + int permissions=atoi(dbintr->GetResultColumn("permissions").c_str()); + + DataScoop_t* newscoop=new DataScoop_t(sid,name,start_addr,end_addr,type,permissions); + assert(newscoop); + GetDataScoops().insert(newscoop); + dbintr->MoveToNextRow(); + } + + return; +} + -- GitLab