Object.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 /************************************************************************
00032  * $Id: Object.h,v 1.20 2008/06/23 18:45:48 legendre Exp $
00033  * Object.h: interface to objects, symbols, lines and instructions.
00034 ************************************************************************/
00035 
00036 
00037 #if !defined(_Object_h_)
00038 #define _Object_h_
00039 
00040 /************************************************************************
00041  * header files.
00042 ************************************************************************/
00043 
00044 // trace data streams
00045 #include <string>
00046 #include <vector>
00047 
00048 #include "Symbol.h"
00049 #include "Symtab.h"
00050 #include "LineInformation.h"
00051 #include "common/h/headers.h"
00052 #include "common/h/MappedFile.h"
00053 #include "common/h/lprintf.h"
00054 
00055 namespace Dyninst{
00056 namespace SymtabAPI{
00057 
00058 extern bool symbol_compare(const Symbol *s1, const Symbol *s2);
00059 
00060 class Symtab;
00061 class Region;
00062 class ExceptionBlock;
00063 class relocationEntry;
00064 
00065 const char WILDCARD_CHARACTER = '?';
00066 const char MULTIPLE_WILDCARD_CHARACTER = '*';
00067 
00068 /************************************************************************
00069  * class AObject
00070  *
00071  *  WHAT IS THIS CLASS????  COMMENTS????
00072  *  Looks like it has a dictionary hash of symbols, as well as
00073  *   a ptr to to the code section, an offset into the code section,
00074  *   and a length of the code section, and ditto for the data
00075  *   section....
00076 ************************************************************************/
00077 
00078 class AObject {
00079 public:
00080     SYMTAB_EXPORT AObject() {};
00081     SYMTAB_EXPORT unsigned nsymbols () const;
00082     
00083     SYMTAB_EXPORT bool get_symbols( std::string & name, std::vector< Symbol *> & symbols);
00084 
00085     SYMTAB_EXPORT char*       code_ptr () const; 
00086     SYMTAB_EXPORT Offset           code_off () const;
00087     SYMTAB_EXPORT Offset           code_len () const;
00088 
00089     SYMTAB_EXPORT char*       data_ptr () const;
00090     SYMTAB_EXPORT Offset           data_off () const;
00091     SYMTAB_EXPORT Offset           data_len () const;
00092 
00093     SYMTAB_EXPORT bool        is_aout  () const;
00094     SYMTAB_EXPORT bool        isDynamic() const;
00095 
00096     SYMTAB_EXPORT unsigned        no_of_sections () const;
00097     SYMTAB_EXPORT unsigned        no_of_symbols  () const;
00098 
00099     SYMTAB_EXPORT bool getAllExceptions(std::vector<ExceptionBlock *>&excpBlocks) const;
00100     SYMTAB_EXPORT std::vector<Region *> getAllRegions() const;
00101 
00102     SYMTAB_EXPORT supportedLanguages pickLanguage(std::string &working_module, char *working_options,
00103                                                                     supportedLanguages working_lang);
00104 
00105     SYMTAB_EXPORT Offset loader_off() const;
00106     SYMTAB_EXPORT unsigned loader_len() const;
00107     SYMTAB_EXPORT int getAddressWidth() const;
00108 
00109     bool isStaticBinary() const {return is_static_binary_;}
00110 
00111     SYMTAB_EXPORT virtual char *  mem_image() const;
00112 
00113     SYMTAB_EXPORT virtual  bool   needs_function_binding()  const;
00114     SYMTAB_EXPORT virtual  bool   get_func_binding_table(std::vector<relocationEntry> &) const;
00115     SYMTAB_EXPORT virtual  bool   get_func_binding_table_ptr(const std::vector<relocationEntry> *&) const; 
00116     SYMTAB_EXPORT virtual  bool   addRelocationEntry(relocationEntry &re);
00117     SYMTAB_EXPORT bool   getSegments(std::vector<Segment> &segs) const;
00118 
00119     SYMTAB_EXPORT bool have_deferred_parsing( void ) const;
00120     // for debuggering....
00121     SYMTAB_EXPORT const std::ostream &dump_state_info(std::ostream &s);
00122 
00123     SYMTAB_EXPORT void * getErrFunc() const;
00124     SYMTAB_EXPORT dyn_hash_map< std::string, std::vector< Symbol *> > *getAllSymbols();
00125     
00126     SYMTAB_EXPORT virtual bool hasFrameDebugInfo() {return false;}
00127     SYMTAB_EXPORT virtual bool getRegValueAtFrame(Address /*pc*/,
00128                                                   Dyninst::MachRegister /*reg*/, 
00129                                                   Dyninst::MachRegisterVal & /*reg_result*/,
00130                                                   Dyninst::SymtabAPI::MemRegReader * /*reader*/) {return false;}
00131     
00132     SYMTAB_EXPORT virtual Dyninst::Architecture getArch() { return Arch_none; };
00133     SYMTAB_EXPORT const std::string findModuleForSym(Symbol *sym);
00134     SYMTAB_EXPORT void clearSymsToMods();
00135     SYMTAB_EXPORT bool hasError() const;
00136     
00137     virtual void setTruncateLinePaths(bool value);
00138     virtual bool getTruncateLinePaths();
00139     virtual Region::RegionType getRelType() const { return Region::RT_INVALID; }
00140 
00141     // Only implemented for ELF right now
00142     SYMTAB_EXPORT virtual void getSegmentsSymReader(std::vector<SymSegment> &) {};
00143 
00144 protected:
00145     SYMTAB_EXPORT virtual ~AObject();
00146     // explicitly protected
00147     SYMTAB_EXPORT AObject(MappedFile *, void (*err_func)(const char *));
00148     SYMTAB_EXPORT AObject(MappedFile *, 
00149                       dyn_hash_map<std::string, LineInformation> &, 
00150                       void (*)(const char *)) { assert(0); }
00151     SYMTAB_EXPORT AObject(const AObject &obj);
00152 
00153     MappedFile *mf;
00154 
00155     std::vector< Region *> regions_;
00156 
00157     // XXX symbols_ is the owner of Symbol pointers; memory
00158     //     is reclaimed from this structure
00159     dyn_hash_map< std::string, std::vector< Symbol *> > symbols_;
00160     std::map< Symbol *, std::string > symsToModules_;
00161     dyn_hash_map<Offset, std::vector<Symbol *> > symsByOffset_;
00162     std::vector<std::pair<std::string, Offset> > modules_;
00163 
00164     char*   code_ptr_;
00165     Offset code_off_;
00166     Offset code_len_;
00167 
00168     char*   data_ptr_;
00169     Offset data_off_;
00170     Offset data_len_;
00171 
00172     Offset code_vldS_;
00173     Offset code_vldE_;
00174 
00175     Offset data_vldS_;
00176     Offset data_vldE_;
00177 
00178     Offset loader_off_; //only used on aix right now.  could be
00179     Offset loader_len_; //needed on other platforms in the future
00180 
00181 //    Offset loadAddress_;
00182 //    Offset entryAddress_;
00183 //    Offset baseAddress_;
00184  
00185     bool is_aout_;
00186     bool is_dynamic_;
00187     bool has_error;
00188 
00189     bool is_static_binary_;
00190 
00191     unsigned no_of_sections_;
00192     unsigned no_of_symbols_;
00193 
00194     bool deferredParse;
00195     void (*err_func_)(const char*);
00196     int addressWidth_nbytes;
00197 
00198     std::vector<ExceptionBlock> catch_addrs_; //Addresses of C++ try/catch blocks;
00199     
00200 private:
00201     friend class SymbolIter;
00202     friend class Symtab;
00203 
00204 };
00205 
00206 }//namepsace Symtab
00207 }//namespace Dyninst
00208 
00209 /************************************************************************
00210  * include the architecture-operating system specific object files.
00211 ************************************************************************/
00212 
00213 #if defined(os_linux) || defined(os_bg) || defined(os_freebsd) || defined(os_vxworks)
00214 #include "Object-elf.h"
00215 #elif defined(os_aix)
00216 #include "Object-xcoff.h"
00217 #elif defined(os_windows)
00218 #include "Object-nt.h"
00219 #else
00220 #error "unknown platform"
00221 #endif
00222 
00223 /************************************************************************
00224  * class SymbolIter
00225 ************************************************************************/
00226 
00227 namespace Dyninst{
00228 namespace SymtabAPI{
00229 
00230 class SymbolIter {
00231  private:
00232    dyn_hash_map< std::string, std::vector< Symbol *> > *symbols;
00233    unsigned int currentPositionInVector;
00234    dyn_hash_map< std::string, std::vector< Symbol *> >::iterator symbolIterator;
00235    
00236  public:
00237    SymbolIter( Object & obj );
00238    SymbolIter( const SymbolIter & src );
00239    ~SymbolIter ();
00240    
00241    void reset ();
00242    
00243    operator bool() const;
00244    void operator++ ( int );
00245    const std::string & currkey() const;
00246    
00247    /* If it's important that this be const, we could try to initialize
00248       currentVector to '& symbolIterator.currval()' in the constructor. */
00249    Symbol *currval();
00250    
00251  private:   
00252    
00253    SymbolIter & operator = ( const SymbolIter & ); // explicitly disallowed
00254 }; /* end class SymbolIter() */
00255 
00256 }//namepsace SymtabAPI
00257 }//namespace Dyninst
00258 
00259 #endif /* !defined(_Object_h_) */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1