SymLite-elf.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 #include "dynutil/h/SymReader.h"
00032 #include "elf/h/Elf_X.h"
00033 #include "common/h/headers.h"
00034 
00035 #include <map>
00036 
00037 namespace Dyninst {
00038 
00039 struct SymCacheEntry {
00040    Dyninst::Offset symaddress;
00041    void *symloc;
00042    const char *demangled_name;
00043 };
00044 
00045 class SymElf : public Dyninst::SymReader
00046 {
00047    friend class SymElfFactory;
00048  private:
00049    Elf_X *elf;
00050    int fd;
00051    bool need_odp;
00052    Elf_X_Shdr *odp_section;
00053 
00054    std::string file;
00055    const char *buffer;
00056    unsigned long buffer_size;
00057 
00058    SymElf(std::string file_);
00059    SymElf(const char *buffer_, unsigned long size_);
00060    virtual ~SymElf();
00061 
00062    SymCacheEntry *cache;
00063    unsigned cache_size;
00064 
00065    Elf_X_Shdr *sym_sections;
00066    unsigned sym_sections_size;
00067    
00068    void createSymCache();
00069    Symbol_t lookupCachedSymbol(Dyninst::Offset offset);
00070    
00071    void init();
00072    unsigned long getSymOffset(const Elf_X_Sym &symbol, unsigned idx);   
00073    unsigned long getSymTOC(const Elf_X_Sym &symbol, unsigned idx);   
00074  public:
00075    virtual Symbol_t getSymbolByName(std::string symname);
00076    virtual Symbol_t getContainingSymbol(Dyninst::Offset offset);
00077    virtual std::string getInterpreterName();
00078 
00079    virtual unsigned numSegments();
00080    virtual bool getSegment(unsigned num, SymSegment &reg); 
00081 
00082    virtual Dyninst::Offset getSymbolOffset(const Symbol_t &sym);
00083    virtual Dyninst::Offset getSymbolTOC(const Symbol_t &sym);
00084    virtual std::string getSymbolName(const Symbol_t &sym);
00085    virtual std::string getDemangledName(const Symbol_t &sym);
00086 
00087    virtual bool isValidSymbol(const Symbol_t &sym);
00088    virtual unsigned getAddressWidth();
00089    virtual unsigned long getSymbolSize(const Symbol_t &sym);
00090 
00091    virtual Section_t getSectionByName(std::string name);
00092    virtual Section_t getSectionByAddress(Dyninst::Address addr);
00093    virtual Dyninst::Address getSectionAddress(Section_t sec);
00094    virtual std::string getSectionName(Section_t sec);
00095    virtual bool isValidSection(Section_t sec);
00096 
00097    virtual Dyninst::Offset imageOffset();
00098    virtual Dyninst::Offset dataOffset();
00099    int ref_count;
00100    bool construction_error;
00101    
00102    void *getElfHandle();
00103    int getFD();
00104    
00105 };
00106 
00107 class SymElfFactory : public Dyninst::SymbolReaderFactory
00108 {
00109 private:
00110    std::map<std::string, SymElf *> *open_symelfs;
00111 public:
00112    SymElfFactory();
00113    virtual ~SymElfFactory();
00114    virtual SymReader *openSymbolReader(std::string pathname);
00115    virtual SymReader *openSymbolReader(const char *buffer, unsigned long size);
00116    virtual bool closeSymbolReader(SymReader *sr);
00117 };
00118 
00119 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1