Archive.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 #ifndef __ARCHIVE_H__
00032 #define __ARCHIVE_H__
00033  
00034 using namespace std;
00035 
00036 class MappedFile;
00037 
00038 namespace Dyninst{
00039 namespace SymtabAPI{
00040 
00041 class Symtab;
00042 
00043 /**
00044  * Helps facilitate lazy parsing and quick lookup once parsing is finished
00045  */
00046 class ArchiveMember {
00047     public:
00048         ArchiveMember() : name_(""), offset_(0), member_(NULL) {}
00049         ArchiveMember(const string name, const Offset offset,
00050                 Symtab * img = NULL) :
00051             name_(name), 
00052             offset_(offset), 
00053             member_(img) 
00054         {}
00055 
00056         ~ArchiveMember() {
00057             if( member_ != NULL ) {
00058                 delete member_;
00059                 member_ = NULL;
00060             }
00061         }
00062 
00063         const string& getName()  { return name_; }
00064         Offset getOffset() { return offset_; }
00065         Symtab * getSymtab() { return member_; }
00066         void setSymtab(Symtab *img) { member_ = img; }
00067 
00068     private:
00069         const string name_;
00070         Offset offset_;
00071         Symtab *member_;
00072 };
00073 
00074 class Archive : public AnnotatableSparse {
00075    public:
00076       static bool openArchive(Archive *&img, string filename);
00077       static bool openArchive(Archive *&img, char *mem_image, size_t image_size);
00078       static SymtabError getLastError();
00079       static string printError(SymtabError err);
00080 
00081       ~Archive();
00082       bool getMember(Symtab *&img, string& member_name);
00083       bool getMemberByOffset(Symtab *&img, Offset memberOffset);
00084       bool getMemberByGlobalSymbol(Symtab *&img, string& symbol_name);
00085       bool getAllMembers(vector<Symtab *> &members);
00086       bool isMemberInArchive(string& member_name);
00087       bool findMemberWithDefinition(Symtab *&obj, string& name);
00088       std::string name();
00089 
00090       bool getMembersBySymbol(string name, std::vector<Symtab *> &matches);
00091 
00092    private:
00093       Archive(string &filename, bool &err);
00094       Archive(char *mem_image, size_t image_size, bool &err);
00095 
00096       /**
00097        * This method is architecture specific
00098        *
00099        * Post-condition:
00100        *        sets serr and errMsg if there is an error 
00101        *        sets Symtab field of passed ArchiveMember
00102        */
00103       bool parseMember(Symtab *&img, ArchiveMember *member);
00104 
00105       /**
00106        * This method is architecture specific
00107        *
00108        * Post-condition:
00109        *        sets serr and errMsg if there is an error
00110        */
00111       bool parseSymbolTable();      
00112 
00113       MappedFile *mf;
00114 
00115       //architecture specific data - 
00116       //For ELF the elf pointer for the archive
00117       //NONE as of now for xcoff
00118       void *basePtr;
00119 
00120       dyn_hash_map<string, ArchiveMember *> membersByName;
00121       dyn_hash_map<Offset, ArchiveMember *> membersByOffset;
00122       std::multimap<string, ArchiveMember *> membersBySymbol;
00123 
00124       // The symbol table is lazily parsed
00125       bool symbolTableParsed;
00126 
00127       // A vector of all Archives. Used to avoid duplicating
00128       // an Archive that already exists.
00129       static vector<Archive *> allArchives;
00130 
00131       static SymtabError serr;
00132       static std::string errMsg;
00133 };
00134 
00135 }//namespace SymtabAPI
00136 }//namespace Dyninst
00137 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1