Symtab.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 __SYMTAB_H__
00032 #define __SYMTAB_H__
00033 
00034 #include <set>
00035 
00036 #include "Symbol.h"
00037 #include "Module.h"
00038 #include "Region.h"
00039 
00040 #include "Annotatable.h"
00041 #include "Serialization.h"
00042 
00043 #include "ProcReader.h"
00044 
00045 #include "boost/shared_ptr.hpp"
00046 
00047 class MappedFile;
00048 
00049 #define SYM_MAJOR 8
00050 #define SYM_MINOR 1
00051 #define SYM_BETA  2
00052  
00053 namespace Dyninst {
00054 
00055    struct SymSegment;
00056 
00057 namespace SymtabAPI {
00058 
00059 class Archive;
00060 class builtInTypeCollection;
00061 
00062 class ExceptionBlock;
00063 class Object;
00064 class localVar;
00065 class relocationEntry;
00066 class Type;
00067 
00068 typedef Dyninst::ProcessReader MemRegReader;
00069 
00070 class Symtab : public LookupInterface,
00071                public Serializable,
00072                public AnnotatableSparse
00073 {
00074 
00075    friend class Archive;
00076    friend class Symbol;
00077    friend class Function;
00078    friend class Variable;
00079    friend class Module;
00080    friend class Region;
00081    friend class emitElf;
00082    friend class emitElf64;
00083    friend class emitElfStatic;
00084    friend class emitWin;
00085    friend class Aggregate;
00086    friend class relocationEntry;
00087 
00088  public:
00089 
00090 
00091    /***** Public Member Functions *****/
00092    public:
00093    SYMTAB_EXPORT static void version(int& major, int& minor, int& maintenance);
00094    SYMTAB_EXPORT Symtab(MappedFile *);
00095 
00096    SYMTAB_EXPORT Symtab();
00097 
00098    SYMTAB_EXPORT Symtab(const Symtab& obj);
00099    SYMTAB_EXPORT Symtab(unsigned char *mem_image, size_t image_size, 
00100                         const std::string &name, bool defensive_binary, bool &err);
00101 
00102    typedef enum {
00103       NotDefensive,
00104       Defensive} def_t; 
00105 
00106    SYMTAB_EXPORT static bool openFile(Symtab *&obj, std::string filename, 
00107                                       def_t defensive_binary = NotDefensive);
00108    SYMTAB_EXPORT static bool openFile(Symtab *&obj, void *mem_image, size_t size, 
00109                                       std::string name, def_t defensive_binary = NotDefensive);
00110    SYMTAB_EXPORT static Symtab *findOpenSymtab(std::string filename);
00111    SYMTAB_EXPORT static bool closeSymtab(Symtab *);
00112 
00113    SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *sb, 
00114            const char *tag = "Symtab") THROW_SPEC (SerializerError);
00115    void rebuild_symbol_hashes(SerializerBase *);
00116    void rebuild_funcvar_hashes(SerializerBase *);
00117    void rebuild_module_hashes(SerializerBase *);
00118    void rebuild_region_indexes(SerializerBase *) THROW_SPEC(SerializerError);
00119    static bool setup_module_up_ptrs(SerializerBase *,Symtab *st);
00120    static bool fixup_relocation_symbols(SerializerBase *,Symtab *st);
00121 
00122    SYMTAB_EXPORT bool exportXML(std::string filename);
00123    SYMTAB_EXPORT bool exportBin(std::string filename);
00124    static Symtab *importBin(std::string filename);
00125    SYMTAB_EXPORT bool getRegValueAtFrame(Address pc, 
00126                                      Dyninst::MachRegister reg, 
00127                                      Dyninst::MachRegisterVal &reg_result,
00128                                      MemRegReader *reader);
00129    SYMTAB_EXPORT bool hasStackwalkDebugInfo();
00130 
00131    /**************************************
00132     *** LOOKUP FUNCTIONS *****************
00133     **************************************/
00134 
00135    // Symbol
00136 
00137    SYMTAB_EXPORT virtual bool findSymbol(std::vector<Symbol *> &ret, 
00138                                          const std::string& name,
00139                                          Symbol::SymbolType sType = Symbol::ST_UNKNOWN,
00140                                          NameType nameType = anyName,
00141                                          bool isRegex = false, 
00142                                          bool checkCase = false,
00143                                          bool includeUndefined = false);
00144 
00145    SYMTAB_EXPORT virtual bool getAllSymbols(std::vector<Symbol *> &ret);
00146    SYMTAB_EXPORT virtual bool getAllSymbolsByType(std::vector<Symbol *> &ret, 
00147          Symbol::SymbolType sType);
00148 
00149    std::vector<Symbol *> *findSymbolByOffset(Offset);
00150 
00151    // Return all undefined symbols in the binary. Currently used for finding
00152    // the .o's in a static archive that have definitions of these symbols
00153    SYMTAB_EXPORT bool getAllUndefinedSymbols(std::vector<Symbol *> &ret);
00154 
00155    // Inversely, return all non-undefined symbols in the binary
00156    SYMTAB_EXPORT bool getAllDefinedSymbols(std::vector<Symbol *> &ret);
00157 
00158    // Function
00159 
00160    SYMTAB_EXPORT bool findFuncByEntryOffset(Function *&ret, const Offset offset);
00161    SYMTAB_EXPORT bool findFunctionsByName(std::vector<Function *> &ret, const std::string name,
00162                                           NameType nameType = anyName, 
00163                                           bool isRegex = false,
00164                                           bool checkCase = true);
00165    SYMTAB_EXPORT bool getAllFunctions(std::vector<Function *>&ret);
00166    SYMTAB_EXPORT bool getContainingFunction(Offset offset, Function* &func);
00167 
00168    // Variable
00169    SYMTAB_EXPORT bool findVariableByOffset(Variable *&ret, const Offset offset);
00170    SYMTAB_EXPORT bool findVariablesByName(std::vector<Variable *> &ret, const std::string name,
00171                                           NameType nameType = anyName, 
00172                                           bool isRegex = false, 
00173                                           bool checkCase = true);
00174    SYMTAB_EXPORT bool getAllVariables(std::vector<Variable *> &ret);
00175 
00176    // Module
00177 
00178    SYMTAB_EXPORT bool getAllModules(std::vector<Module *>&ret);
00179    SYMTAB_EXPORT bool findModuleByOffset(Module *&ret, Offset off);
00180    SYMTAB_EXPORT bool findModuleByName(Module *&ret, const std::string name);
00181    SYMTAB_EXPORT Module *getDefaultModule();
00182 
00183    // Region
00184 
00185    SYMTAB_EXPORT bool getCodeRegions(std::vector<Region *>&ret);
00186    SYMTAB_EXPORT bool getDataRegions(std::vector<Region *>&ret);
00187    SYMTAB_EXPORT bool getAllRegions(std::vector<Region *>&ret);
00188    SYMTAB_EXPORT bool getAllNewRegions(std::vector<Region *>&ret);
00189    //  change me to use a hash
00190    SYMTAB_EXPORT bool findRegion(Region *&ret, std::string regname);
00191    SYMTAB_EXPORT bool findRegion(Region *&ret, const Offset addr, const unsigned long size);
00192    SYMTAB_EXPORT bool findRegionByEntry(Region *&ret, const Offset offset);
00193    SYMTAB_EXPORT Region *findEnclosingRegion(const Offset offset);
00194 
00195    // Exceptions
00196    SYMTAB_EXPORT bool findException(ExceptionBlock &excp,Offset addr);
00197    SYMTAB_EXPORT bool getAllExceptions(std::vector<ExceptionBlock *> &exceptions);
00198    SYMTAB_EXPORT bool findCatchBlock(ExceptionBlock &excp, Offset addr, 
00199          unsigned size = 0);
00200 
00201    // Relocation entries
00202    SYMTAB_EXPORT bool getFuncBindingTable(std::vector<relocationEntry> &fbt) const;
00203    SYMTAB_EXPORT bool updateFuncBindingTable(Offset stub_addr, Offset plt_addr);
00204 
00205    /**************************************
00206     *** SYMBOL ADDING FUNCS **************
00207     **************************************/
00208 
00209    SYMTAB_EXPORT bool addSymbol(Symbol *newsym);
00210    SYMTAB_EXPORT bool addSymbol(Symbol *newSym, Symbol *referringSymbol);
00211    SYMTAB_EXPORT Function *createFunction(std::string name, Offset offset, size_t size, Module *mod = NULL);
00212    SYMTAB_EXPORT Variable *createVariable(std::string name, Offset offset, size_t size, Module *mod = NULL);
00213 
00214    SYMTAB_EXPORT bool deleteFunction(Function *func);
00215    SYMTAB_EXPORT bool deleteVariable(Variable *var);
00216 
00217 
00218    /*****Query Functions*****/
00219    SYMTAB_EXPORT bool isExec() const;
00220    SYMTAB_EXPORT bool isStripped();
00221    SYMTAB_EXPORT ObjectType getObjectType() const;
00222    SYMTAB_EXPORT Dyninst::Architecture getArchitecture();
00223    SYMTAB_EXPORT bool isCode(const Offset where) const;
00224    SYMTAB_EXPORT bool isData(const Offset where) const;
00225    SYMTAB_EXPORT bool isValidOffset(const Offset where) const;
00226 
00227    SYMTAB_EXPORT bool isNativeCompiler() const;
00228    SYMTAB_EXPORT bool getMappedRegions(std::vector<Region *> &mappedRegs) const;
00229 
00230    /***** Line Number Information *****/
00231    SYMTAB_EXPORT bool getAddressRanges(std::vector<std::pair<Offset, Offset> >&ranges,
00232          std::string lineSource, unsigned int LineNo);
00233    SYMTAB_EXPORT bool getSourceLines(std::vector<Statement *> &lines, 
00234          Offset addressInRange);
00235    SYMTAB_EXPORT bool getSourceLines(std::vector<LineNoTuple> &lines, 
00236                                      Offset addressInRange);
00237    SYMTAB_EXPORT bool addLine(std::string lineSource, unsigned int lineNo,
00238          unsigned int lineOffset, Offset lowInclAddr,
00239          Offset highExclAddr);
00240    SYMTAB_EXPORT bool addAddressRange(Offset lowInclAddr, Offset highExclAddr, std::string lineSource,
00241          unsigned int lineNo, unsigned int lineOffset = 0);
00242    SYMTAB_EXPORT void setTruncateLinePaths(bool value);
00243    SYMTAB_EXPORT bool getTruncateLinePaths();
00244 
00245    /***** Type Information *****/
00246    SYMTAB_EXPORT virtual bool findType(Type *&type, std::string name);
00247    SYMTAB_EXPORT virtual Type *findType(unsigned type_id);
00248    SYMTAB_EXPORT virtual bool findVariableType(Type *&type, std::string name);
00249 
00250    SYMTAB_EXPORT bool addType(Type *typ);
00251 
00252    static boost::shared_ptr<builtInTypeCollection> builtInTypes();
00253    static boost::shared_ptr<typeCollection> stdTypes();
00254 
00255    SYMTAB_EXPORT static std::vector<Type *> *getAllstdTypes();
00256    SYMTAB_EXPORT static std::vector<Type *> *getAllbuiltInTypes();
00257 
00258    SYMTAB_EXPORT void parseTypesNow();
00259 
00260    /***** Local Variable Information *****/
00261    SYMTAB_EXPORT bool findLocalVariable(std::vector<localVar *>&vars, std::string name);
00262 
00263    /***** Relocation Sections *****/
00264    SYMTAB_EXPORT bool hasRel() const;
00265    SYMTAB_EXPORT bool hasRela() const;
00266    SYMTAB_EXPORT bool hasReldyn() const;
00267    SYMTAB_EXPORT bool hasReladyn() const;
00268    SYMTAB_EXPORT bool hasRelplt() const;
00269    SYMTAB_EXPORT bool hasRelaplt() const;
00270    
00271    SYMTAB_EXPORT bool isStaticBinary() const;
00272 
00273    /***** Write Back binary functions *****/
00274    SYMTAB_EXPORT bool emitSymbols(Object *linkedFile, std::string filename, unsigned flag = 0);
00275    SYMTAB_EXPORT bool addRegion(Offset vaddr, void *data, unsigned int dataSize, 
00276          std::string name, Region::RegionType rType_, bool loadable = false,
00277          unsigned long memAlign = sizeof(unsigned), bool tls = false);
00278    SYMTAB_EXPORT bool addRegion(Region *newreg);
00279    SYMTAB_EXPORT bool emit(std::string filename, unsigned flag = 0);
00280 
00281    SYMTAB_EXPORT void addDynLibSubstitution(std::string oldName, std::string newName);
00282    SYMTAB_EXPORT std::string getDynLibSubstitution(std::string name);
00283 
00284    SYMTAB_EXPORT bool getSegments(std::vector<Segment> &segs) const;
00285    
00286    SYMTAB_EXPORT void fixup_code_and_data(Offset newImageOffset,
00287                                           Offset newImageLength,
00288                                           Offset newDataOffset,
00289                                           Offset newDataLength);
00290    SYMTAB_EXPORT bool fixup_RegionAddr(const char* name, Offset memOffset, long memSize);
00291    SYMTAB_EXPORT bool fixup_SymbolAddr(const char* name, Offset newOffset);
00292    SYMTAB_EXPORT bool updateRegion(const char* name, void *buffer, unsigned size);
00293    SYMTAB_EXPORT bool updateCode(void *buffer, unsigned size);
00294    SYMTAB_EXPORT bool updateData(void *buffer, unsigned size);
00295    SYMTAB_EXPORT Offset getFreeOffset(unsigned size);
00296 
00297    SYMTAB_EXPORT bool addLibraryPrereq(std::string libname);
00298    SYMTAB_EXPORT bool addSysVDynamic(long name, long value);
00299 
00300    SYMTAB_EXPORT bool addLinkingResource(Archive *library);
00301    SYMTAB_EXPORT bool getLinkingResources(std::vector<Archive *> &libs);
00302 
00303    SYMTAB_EXPORT bool addExternalSymbolReference(Symbol *externalSym, Region *localRegion, relocationEntry localRel);
00304    SYMTAB_EXPORT bool addTrapHeader_win(Address ptr);
00305 
00306    SYMTAB_EXPORT bool updateRelocations(Address start, Address end, Symbol *oldsym, Symbol *newsym);
00307 
00308    /***** Data Member Access *****/
00309    SYMTAB_EXPORT std::string file() const;
00310    SYMTAB_EXPORT std::string name() const;
00311    SYMTAB_EXPORT std::string memberName() const;
00312 
00313    SYMTAB_EXPORT char *mem_image() const;
00314 
00315    SYMTAB_EXPORT Offset imageOffset() const;
00316    SYMTAB_EXPORT Offset dataOffset() const;
00317    SYMTAB_EXPORT Offset dataLength() const;
00318    SYMTAB_EXPORT Offset imageLength() const;
00319    //   SYMTAB_EXPORT char*  image_ptr ()  const;
00320    //   SYMTAB_EXPORT char*  data_ptr ()  const;
00321    SYMTAB_EXPORT Offset getInitOffset();
00322    SYMTAB_EXPORT Offset getFiniOffset();
00323 
00324    SYMTAB_EXPORT const char*  getInterpreterName() const;
00325 
00326    SYMTAB_EXPORT unsigned getAddressWidth() const;
00327    SYMTAB_EXPORT Offset getLoadOffset() const;
00328    SYMTAB_EXPORT Offset getEntryOffset() const;
00329    SYMTAB_EXPORT Offset getBaseOffset() const;
00330    SYMTAB_EXPORT Offset getTOCoffset(Function *func = NULL) const;
00331    SYMTAB_EXPORT Offset getTOCoffset(Offset off) const;
00332    SYMTAB_EXPORT Address getLoadAddress();
00333    SYMTAB_EXPORT bool isDefensiveBinary() const; 
00334    SYMTAB_EXPORT Offset fileToDiskOffset(Dyninst::Offset) const;
00335    SYMTAB_EXPORT Offset fileToMemOffset(Dyninst::Offset) const;
00336 
00337 
00338    SYMTAB_EXPORT std::string getDefaultNamespacePrefix() const;
00339 
00340    SYMTAB_EXPORT unsigned getNumberofRegions() const;
00341    SYMTAB_EXPORT unsigned getNumberofSymbols() const;
00342 
00343    SYMTAB_EXPORT std::vector<std::string> &getDependencies();
00344    SYMTAB_EXPORT bool removeLibraryDependency(std::string lib);
00345 
00346    SYMTAB_EXPORT Archive *getParentArchive() const;
00347 
00348    /***** Error Handling *****/
00349    SYMTAB_EXPORT static SymtabError getLastSymtabError();
00350    SYMTAB_EXPORT static std::string printError(SymtabError serr);
00351 
00352    SYMTAB_EXPORT ~Symtab();
00353 
00354    bool delSymbol(Symbol *sym) { return deleteSymbol(sym); }
00355    bool deleteSymbol(Symbol *sym); 
00356 
00357    Symbol *getSymbolByIndex(unsigned);
00358    protected:
00359    Symtab(std::string filename, std::string member_name, Offset offset, bool &err, void *base = NULL);
00360    Symtab(char *img, size_t size, std::string member_name, Offset offset, bool &err, void *base = NULL);
00361 
00362    /***** Private Member Functions *****/
00363    private:
00364 
00365    SYMTAB_EXPORT Symtab(std::string filename, bool defensive_bin, bool &err);
00366 
00367    SYMTAB_EXPORT bool extractInfo(Object *linkedFile);
00368 
00369    // Parsing code
00370 
00371    bool extractSymbolsFromFile(Object *linkedFile, std::vector<Symbol *> &raw_syms);
00372 
00373    bool fixSymRegion(Symbol *sym);
00374 
00375    bool fixSymModules(std::vector<Symbol *> &raw_syms);
00376    bool demangleSymbols(std::vector<Symbol *> &rawsyms);
00377    bool createIndices(std::vector<Symbol *> &raw_syms, bool undefined);
00378    bool createAggregates();
00379 
00380    bool fixSymModule(Symbol *&sym);
00381    bool demangleSymbol(Symbol *&sym);
00382    bool addSymbolToIndices(Symbol *&sym, bool undefined);
00383    bool addSymbolToAggregates(Symbol *&sym);
00384    bool doNotAggregate(Symbol *&sym);
00385    bool updateIndices(Symbol *sym, std::string newName, NameType nameType);
00386 
00387 
00388    void setModuleLanguages(dyn_hash_map<std::string, supportedLanguages> *mod_langs);
00389 
00390    bool buildDemangledName( const std::string &mangled, 
00391          std::string &pretty,
00392          std::string &typed,
00393          bool nativeCompiler, 
00394          supportedLanguages lang );
00395 
00396    // Change the type of a symbol after the fact
00397    bool changeType(Symbol *sym, Symbol::SymbolType oldType);
00398 
00399    bool changeSymbolOffset(Symbol *sym, Offset newOffset);
00400    bool deleteSymbolFromIndices(Symbol *sym);
00401 
00402    bool changeAggregateOffset(Aggregate *agg, Offset oldOffset, Offset newOffset);
00403    bool deleteAggregate(Aggregate *agg);
00404 
00405    // Used by binaryEdit.C...
00406  public:
00407    SYMTAB_EXPORT bool canBeShared();
00408    SYMTAB_EXPORT Module *getOrCreateModule(const std::string &modName, 
00409                                            const Offset modAddr);
00410 
00411  public:
00412    //Only valid on ELF formats
00413    SYMTAB_EXPORT Offset getElfDynamicOffset();
00414    // SymReader interface
00415    SYMTAB_EXPORT void getSegmentsSymReader(std::vector<SymSegment> &segs);
00416 
00417  private:
00418    void createDefaultModule();
00419 
00420    Module *newModule(const std::string &name, const Offset addr, supportedLanguages lang);
00421    
00422    //bool buildFunctionLists(std::vector <Symbol *> &raw_funcs);
00423    //void enterFunctionInTables(Symbol *func, bool wasSymtab);
00424 
00425 
00426    bool addSymtabVariables();
00427 
00428    void checkPPC64DescriptorSymbols(Object *linkedFile);
00429 
00430 
00431    void parseLineInformation();
00432    void parseTypes();
00433    bool setDefaultNamespacePrefix(std::string &str);
00434 
00435    bool addUserRegion(Region *newreg);
00436    bool addUserType(Type *newtypeg);
00437 
00438    void setTOCOffset(Offset offset);
00439 
00440    /***** Private Data Members *****/
00441    private:
00442 
00443    static boost::shared_ptr<typeCollection> setupStdTypes();
00444    static boost::shared_ptr<builtInTypeCollection> setupBuiltinTypes();
00445 
00446 
00447    std::string member_name_;
00448    Offset member_offset_;
00449    Archive * parentArchive_;
00450    MappedFile *mf;
00451    MappedFile *mfForDebugInfo;
00452 
00453    Offset imageOffset_;
00454    unsigned imageLen_;
00455    Offset dataOffset_;
00456    unsigned dataLen_;
00457 
00458    bool is_a_out;
00459    Offset main_call_addr_; // address of call to main()
00460 
00461    bool nativeCompiler;
00462 
00463    unsigned address_width_;
00464    char *code_ptr_;
00465    char *data_ptr_;
00466    std::string interpreter_name_;
00467    Offset entry_address_;
00468    Offset base_address_;
00469    Offset load_address_;
00470    ObjectType object_type_;
00471    bool is_eel_;
00472    std::vector<Segment> segments_;
00473    //  make sure is_a_out is set before calling symbolsToFunctions
00474 
00475    // A std::vector of all Symtabs. Used to avoid duplicating
00476    // a Symtab that already exists.
00477    static std::vector<Symtab *> allSymtabs;
00478    std::string defaultNamespacePrefix;
00479 
00480    //sections
00481    unsigned no_of_sections;
00482    std::vector<Region *> regions_;
00483    std::vector<Region *> codeRegions_;
00484    std::vector<Region *> dataRegions_;
00485    dyn_hash_map <Offset, Region *> regionsByEntryAddr;
00486 
00487    //Point where new loadable sections will be inserted
00488    unsigned newSectionInsertPoint;
00489 
00490    //symbols
00491    unsigned no_of_symbols;
00492 
00493    // Indices
00494 
00495    std::vector<Symbol *> everyDefinedSymbol;
00496    // hashtable for looking up undefined symbols in the dynamic symbol
00497    // tale. Entries are referred by the relocation table entries
00498    // NOT a subset of everyDefinedSymbol
00499    std::vector<Symbol *> undefDynSyms;
00500    std::map <std::string, std::vector<Symbol *> > undefDynSymsByMangledName;
00501    std::map <std::string, std::vector<Symbol *> > undefDynSymsByPrettyName;
00502    std::map <std::string, std::vector<Symbol *> > undefDynSymsByTypedName;
00503 
00504    
00505    // Symbols by offsets in the symbol table
00506    dyn_hash_map <Offset, std::vector<Symbol *> > symsByOffset;
00507 
00508    // The raw name from the symbol table
00509    dyn_hash_map <std::string, std::vector<Symbol *> > symsByMangledName;
00510 
00511    // The name after we've run it through the demangler
00512    dyn_hash_map <std::string, std::vector<Symbol *> > symsByPrettyName;
00513 
00514    // The name after we've derived the parameter types
00515    dyn_hash_map <std::string, std::vector<Symbol *> > symsByTypedName;
00516 
00517    // We also need per-Aggregate indices
00518    bool sorted_everyFunction;
00519    std::vector<Function *> everyFunction;
00520    // Since Functions are unique by address we require this structure to
00521    // efficiently track them.
00522    dyn_hash_map <Offset, Function *> funcsByOffset;
00523 
00524    // Similar for Variables
00525    std::vector<Variable *> everyVariable;
00526    dyn_hash_map <Offset, Variable *> varsByOffset;
00527 
00528    // For now, skip the index-by-name structures. We can use the Symbol
00529    // ones instead. 
00530    /*
00531    dyn_hash_map <std::string, std::vector<Function *> *> funcsByMangledName;
00532    dyn_hash_map <std::string, std::vector<Function *> *> funcsByPrettyName;
00533    dyn_hash_map <std::string, std::vector<Function *> *> funcsByTypedName;
00534    */
00535 
00536    //dyn_hash_map <Offset, std::vector<Function *> > funcsByEntryAddr;
00537    // note, a prettyName is not unique, it may map to a function appearing
00538    // in several modules.  Also only contains instrumentable functions....
00539    //dyn_hash_map <std::string, std::vector<Function *>*> funcsByPretty;
00540    // Hash table holding functions by mangled name.
00541    // Should contain same functions as funcsByPretty....
00542    //dyn_hash_map <std::string, std::vector<Function *>*> funcsByMangled;
00543    // A way to iterate over all the functions efficiently
00544    //std::vector<Symbol *> everyUniqueFunction;
00545    //std::vector<Function *> allFunctions;
00546    // And the counterpart "ones that are there right away"
00547    //std::vector<Symbol *> exportedFunctions;
00548 
00549    //dyn_hash_map <Address, Function *> funcsByAddr;
00550    dyn_hash_map <std::string, Module *> modsByFileName;
00551    dyn_hash_map <std::string, Module *> modsByFullName;
00552    std::vector<Module *> _mods;
00553 
00554    // Variables indexed by pretty (non-mangled) name
00555    /*
00556    dyn_hash_map <std::string, std::vector <Symbol *> *> varsByPretty;
00557    dyn_hash_map <std::string, std::vector <Symbol *> *> varsByMangled;
00558    dyn_hash_map <Offset, Symbol *> varsByAddr;
00559    std::vector<Symbol *> everyUniqueVariable;
00560    */
00561 
00562    //dyn_hash_map <std::string, std::vector <Symbol *> *> modsByName;
00563    //std::vector<Module *> _mods;
00564 
00565 
00566    std::vector<relocationEntry > relocation_table_;
00567    std::vector<ExceptionBlock *> excpBlocks;
00568 
00569    std::vector<std::string> deps_;
00570 
00571    // This set is used during static linking to satisfy dependencies
00572    std::vector<Archive *> linkingResources_;
00573 
00574    // This set represents Symtabs referenced by a new external Symbol
00575    bool getExplicitSymtabRefs(std::set<Symtab *> &refs);
00576    std::set<Symtab *> explicitSymtabRefs_;
00577 
00578    //Line Information valid flag;
00579    bool isLineInfoValid_;
00580    //type info valid flag
00581    bool isTypeInfoValid_;
00582 
00583    int nlines_;
00584    unsigned long fdptr_;
00585    char *lines_;
00586    char *stabstr_;
00587    int nstabs_;
00588    void *stabs_;
00589    char *stringpool_;
00590 
00591    //Relocation sections
00592    bool hasRel_;
00593    bool hasRela_;
00594    bool hasReldyn_;
00595    bool hasReladyn_;
00596    bool hasRelplt_;
00597    bool hasRelaplt_;
00598 
00599    bool isStaticBinary_;
00600    bool isDefensiveBinary_;
00601 
00602    //Don't use obj_private, use getObject() instead.
00603  public:
00604    Object *getObject();
00605  private:
00606    Object *obj_private;
00607 
00608    // dynamic library name substitutions
00609    std::map <std::string, std::string> dynLibSubs;
00610 
00611    public:
00612    static boost::shared_ptr<Type> type_Error();
00613    static boost::shared_ptr<Type> type_Untyped();
00614 
00615  private:
00616     unsigned _ref_cnt;
00617 };
00618 
00619 /**
00620  * Used to represent something like a C++ try/catch block.  
00621  * Currently only used on Linux/x86
00622  **/
00623 SYMTAB_EXPORT  std::ostream &operator<<(std::ostream &os, const ExceptionBlock &q);
00624 
00625 class ExceptionBlock : public Serializable, public AnnotatableSparse {
00626 
00627    public:
00628       SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *sb, 
00629               const char *tag = "exceptionBlock") THROW_SPEC (SerializerError);
00630       SYMTAB_EXPORT ExceptionBlock(Offset tStart, unsigned tSize, Offset cStart);
00631       SYMTAB_EXPORT ExceptionBlock(Offset cStart);
00632       SYMTAB_EXPORT ExceptionBlock(const ExceptionBlock &eb);
00633       SYMTAB_EXPORT ~ExceptionBlock();
00634       SYMTAB_EXPORT ExceptionBlock();
00635 
00636       SYMTAB_EXPORT bool hasTry() const;
00637       SYMTAB_EXPORT Offset tryStart() const;
00638       SYMTAB_EXPORT Offset tryEnd() const;
00639       SYMTAB_EXPORT Offset trySize() const;
00640       SYMTAB_EXPORT Offset catchStart() const;
00641       SYMTAB_EXPORT bool contains(Offset a) const;
00642 
00643       friend SYMTAB_EXPORT std::ostream &operator<<(std::ostream &os, const ExceptionBlock &q);
00644    private:
00645       Offset tryStart_;
00646       unsigned trySize_;
00647       Offset catchStart_;
00648       bool hasTry_;
00649 };
00650 
00651 // relocation information for calls to functions not in this image
00652 // on sparc-solaris: target_addr_ = rel_addr_ = PLT entry addr
00653 // on x86-solaris: target_addr_ = PLT entry addr
00654 //         rel_addr_ =  GOT entry addr  corr. to PLT_entry
00655 SYMTAB_EXPORT std::ostream &operator<<(std::ostream &os, const relocationEntry &q);
00656 
00657 class relocationEntry : public Serializable, public AnnotatableSparse {
00658    public:
00659 
00660       SYMTAB_EXPORT relocationEntry();
00661       SYMTAB_EXPORT relocationEntry(Offset ta, Offset ra, Offset add, 
00662               std::string n, Symbol *dynref = NULL, unsigned long relType = 0);
00663       SYMTAB_EXPORT relocationEntry(Offset ta, Offset ra, std::string n, 
00664               Symbol *dynref = NULL, unsigned long relType = 0);
00665       SYMTAB_EXPORT relocationEntry(Offset ra, std::string n, Symbol *dynref = NULL, 
00666               unsigned long relType = 0, Region::RegionType rtype = Region::RT_REL);
00667       SYMTAB_EXPORT relocationEntry(Offset ta, Offset ra, Offset add,
00668                           std::string n, Symbol *dynref = NULL, unsigned long relType = 0,
00669                           Region::RegionType rtype = Region::RT_REL);
00670 
00671       SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *sb, 
00672               const char *tag = "relocationEntry") THROW_SPEC (SerializerError);
00673 
00674       SYMTAB_EXPORT Offset target_addr() const;
00675       SYMTAB_EXPORT Offset rel_addr() const;
00676       SYMTAB_EXPORT Offset addend() const;
00677       SYMTAB_EXPORT Region::RegionType regionType() const;
00678       SYMTAB_EXPORT const std::string &name() const;
00679       SYMTAB_EXPORT Symbol *getDynSym() const;
00680       SYMTAB_EXPORT bool addDynSym(Symbol *dynref);
00681       SYMTAB_EXPORT unsigned long getRelType() const;
00682 
00683       SYMTAB_EXPORT void setTargetAddr(const Offset);
00684       SYMTAB_EXPORT void setRelAddr(const Offset);
00685       SYMTAB_EXPORT void setAddend(const Offset);
00686       SYMTAB_EXPORT void setRegionType(const Region::RegionType);
00687       SYMTAB_EXPORT void setName(const std::string &newName);
00688       SYMTAB_EXPORT void setRelType(unsigned long relType) { relType_ = relType; }
00689 
00690       // dump output.  Currently setup as a debugging aid, not really
00691       //  for object persistance....
00692       //SYMTAB_EXPORT std::ostream & operator<<(std::ostream &s) const;
00693       friend SYMTAB_EXPORT std::ostream &operator<<(std::ostream &os, const relocationEntry &q);
00694 
00695       enum {pltrel = 1, dynrel = 2} relocationType;
00696       SYMTAB_EXPORT bool operator==(const relocationEntry &) const;
00697 
00698       // Architecture-specific functions
00699       SYMTAB_EXPORT static unsigned long getGlobalRelType(unsigned addressWidth, Symbol *sym = NULL);
00700       static const char *relType2Str(unsigned long r, unsigned addressWidth = sizeof(Address));
00701 
00702    private:
00703       Offset target_addr_;  // target address of call instruction 
00704       Offset rel_addr_;     // address of corresponding relocation entry 
00705       Offset addend_;       // addend (from RELA entries)
00706       Region::RegionType rtype_;        // RT_REL vs. RT_RELA
00707       std::string  name_;
00708       Symbol *dynref_;
00709       unsigned long relType_;
00710       Offset rel_struct_addr_;
00711 };
00712 
00713 #if 1
00714 #if 1
00715 SYMTAB_EXPORT SerializerBase *nonpublic_make_bin_symtab_serializer(Symtab *t, std::string file);
00716 SYMTAB_EXPORT SerializerBase *nonpublic_make_bin_symtab_deserializer(Symtab *t, std::string file);
00717 SYMTAB_EXPORT void nonpublic_free_bin_symtab_serializer(SerializerBase *sb);
00718 #else
00719 
00720 template <class T>
00721 SerializerBase *nonpublic_make_bin_serializer(T *t, std::string file)
00722 {
00723     SerializerBin<T> *ser;
00724     ser = new SerializerBin<T>(t, "SerializerBin", file, sd_serialize, true);
00725     T *test_st = ser->getScope();
00726     assert(test_st == t);
00727     return ser;
00728 }
00729 
00730 template <class T>
00731 SerializerBase *nonpublic_make_bin_deserializer(T *t, std::string file)
00732 {
00733     SerializerBin<T> *ser;
00734     ser = new SerializerBin<T>(t, "DeserializerBin", file, sd_deserialize, true);
00735     T *test_st = ser->getScope();
00736     assert(test_st == t);
00737     return ser;
00738 }
00739 
00740 template <class T>
00741 void nonpublic_free_bin_serializer(SerializerBase *sb)
00742 {
00743     SerializerBin<T> *sbin = dynamic_cast<SerializerBin<T> *>(sb);
00744     if (sbin)
00745     {
00746         delete(sbin);
00747     }
00748     else
00749         fprintf(stderr, "%s[%d]:  FIXME\n", FILE__, __LINE__);
00750 
00751 }
00752 #endif
00753 #endif
00754 
00755 }//namespace SymtabAPI
00756 
00757 }//namespace Dyninst
00758 #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