Collections.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 _Collections_h_
00032 #define _Collections_h_
00033 
00034 #include "Type.h"
00035 #include "Variable.h"
00036 #include "Serialization.h"
00037 
00038 namespace Dyninst {
00039 
00040 namespace SymtabAPI {
00041 
00042 class Module;
00043 class Symtab;
00044 class localVar;
00045 class DwarfWalker;
00046 
00047 /*
00048  * This class contains a collection of local variables.
00049  * Each function will have one of these objects associated with it.
00050  * This object will store all the local variables within this function.
00051  * Note: This class is unaware of scope.
00052  */
00053 class localVarCollection : public AnnotationContainer<localVar *> {
00054   
00055   std::vector<localVar *> localVars;
00056   
00057   SYMTAB_EXPORT bool addItem_impl(localVar *);
00058 public:
00059   SYMTAB_EXPORT localVarCollection(){}
00060   SYMTAB_EXPORT ~localVarCollection();
00061 
00062   SYMTAB_EXPORT void addLocalVar(localVar * var);
00063   SYMTAB_EXPORT localVar * findLocalVar(std::string &name);
00064   SYMTAB_EXPORT std::vector<localVar *> *getAllVars();  
00065 
00066   SYMTAB_EXPORT Serializable *ac_serialize_impl(SerializerBase *, const char * = "localVarCollection") THROW_SPEC (SerializerError);
00067 };
00068   
00069 
00070 
00071 /*
00072  * Due to DWARF weirdness, this can be shared between multiple BPatch_modules.
00073  * So we reference-count to make life easier.
00074  */
00075 class typeCollection : public Serializable//, public AnnotatableSparse 
00076 {
00077     friend class Symtab;
00078     friend class Object;
00079     friend class Module;
00080     friend class Type;
00081     friend class DwarfWalker;
00082 
00083     dyn_hash_map<std::string, Type *> typesByName;
00084     dyn_hash_map<std::string, Type *> globalVarsByName;
00085     dyn_hash_map<int, Type *> typesByID;
00086 
00087 
00088     // DWARF:
00089     /* Cache type collections on a per-image basis.  (Since
00090        BPatch_functions are solitons, we don't have to cache them.) */
00091     static dyn_hash_map< void *, typeCollection * > fileToTypesMap;
00092     //static dyn_hash_map<int, std::vector<std::pair<dataClass, Type **> > > deferred_lookups;
00093     static bool doDeferredLookups(typeCollection *);
00094 
00095     // DWARF...
00096     bool dwarfParsed_;
00097 
00098     SYMTAB_EXPORT Serializable *serialize_impl(SerializerBase *, const char * = "typeCollection") THROW_SPEC (SerializerError);
00099     public:
00100     SYMTAB_EXPORT typeCollection();
00101     SYMTAB_EXPORT ~typeCollection();
00102 public:
00103     static void addDeferredLookup(int, dataClass, Type **);
00104 
00105     SYMTAB_EXPORT static typeCollection *getModTypeCollection(Module *mod);
00106 #if 0
00107     SYMTAB_EXPORT static typeCollection *getGlobalTypeCollection();
00108     SYMTAB_EXPORT static void freeTypeCollection(typeCollection *tc);
00109 #endif
00110 
00111     // DWARF...
00112     SYMTAB_EXPORT bool dwarfParsed() { return dwarfParsed_; }
00113     SYMTAB_EXPORT void setDwarfParsed() { dwarfParsed_ = true; }
00114 
00115     SYMTAB_EXPORT Type  *findType(std::string name);
00116     SYMTAB_EXPORT Type  *findType(const int ID);
00117     SYMTAB_EXPORT Type  *findTypeLocal(std::string name);
00118     SYMTAB_EXPORT Type  *findTypeLocal(const int ID);
00119     SYMTAB_EXPORT void  addType(Type *type);
00120     SYMTAB_EXPORT void        addGlobalVariable(std::string &name, Type *type);
00121 
00122     /* Some debug formats allow forward references.  Rather than
00123        fill in forward in a second pass, generate placeholder
00124        types, and fill them in as we go.  Because we require
00125        One True Pointer for each type (in parseStab.C), when
00126        updating a type, return that One True Pointer. */
00127     SYMTAB_EXPORT Type * findOrCreateType( const int ID );
00128     template<class T>
00129     SYMTAB_EXPORT T* addOrUpdateType(T* type);
00130 
00131     SYMTAB_EXPORT Type *findVariableType(std::string &name);
00132 
00133     SYMTAB_EXPORT std::vector<Type *> *getAllTypes();
00134     SYMTAB_EXPORT std::vector<std::pair<std::string, Type *> > *getAllGlobalVariables();
00135     SYMTAB_EXPORT void clearNumberedTypes();
00136 };
00137 
00138 /*
00139  * This class defines the collection for the built-in Types
00140  * gnu ( and AIX??) use negative numbers to define other types
00141  * in terms of these built-in types.
00142  * This collection is global and built in the BPatch_image constructor.
00143  * This means that only one collection of built-in types is made
00144  * per image.  jdd 4/21/99
00145  *
00146  */
00147 
00148 class SYMTAB_EXPORT builtInTypeCollection {
00149    
00150     dyn_hash_map<std::string, Type *> builtInTypesByName;
00151     dyn_hash_map<int, Type *> builtInTypesByID;
00152 public:
00153 
00154     builtInTypeCollection();
00155     ~builtInTypeCollection();
00156 
00157     Type    *findBuiltInType(std::string &name);
00158     Type    *findBuiltInType(const int ID);
00159     void    addBuiltInType(Type *type);
00160     std::vector<Type *> *getAllBuiltInTypes();
00161    
00162 };
00163 
00164 }// namespace SymtabAPI
00165 }// namespace Dyninst
00166 
00167 #endif /* _Collections_h_ */
00168 
00169 
00170 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1