Object-xcoff.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  * AIX object files.
00033  * $Id: Object-xcoff.h,v 1.24 2008/07/01 19:26:43 legendre Exp $
00034 ************************************************************************/
00035 
00036 
00037 #if !defined(_Object_aix_h_)
00038 #define _Object_aix_h_
00039 
00040 /************************************************************************
00041  * header files.
00042 ************************************************************************/
00043 
00044 #include "common/h/headers.h"
00045 //#include <common/h/Line.h>
00046 #include "symtabAPI/h/Symbol.h"
00047 #include "symtabAPI/h/Symtab.h"
00048 #include "common/h/Types.h"
00049 
00050 #include <string>
00051 #include <vector>
00052 
00053 using namespace std;
00054 
00055 extern "C" {
00056 #include <a.out.h>
00057 };
00058 
00059 #include <fcntl.h>
00060 #include <stdlib.h>
00061 #include <unistd.h>
00062 
00063 #include <sys/types.h>
00064 #include <sys/mman.h>
00065 #include <sys/stat.h>
00066 
00067 #define __AR_BIG__
00068 #define __AR_SMALL__
00069 #include <ar.h>
00070 
00071 namespace Dyninst {
00072 namespace SymtabAPI {
00073 
00074 class fileOpener;
00075 
00076 // Object to represent both the 32-bit and 64-bit archive headers
00077 // for ar files (libraries)
00078 class xcoffArchive {
00079  public:
00080   xcoffArchive (fileOpener *f) : member_name(0), fo_(f) {}
00081   virtual ~xcoffArchive () {}
00082   
00083   virtual int read_arhdr() = 0;
00084   virtual int read_mbrhdr() = 0;
00085 
00086   unsigned long long aout_offset;
00087   unsigned long long next_offset;
00088   char *member_name;
00089   int member_len;
00090  protected:
00091   unsigned long long first_offset;
00092   unsigned long long last_offset;
00093 
00094   fileOpener *fo_;
00095 };
00096 
00097 class xcoffArchive_32 : private xcoffArchive {
00098  public:
00099   xcoffArchive_32 (fileOpener *file) : xcoffArchive(file) {};
00100   ~xcoffArchive_32 () {if (member_name) free(member_name);};
00101   virtual int read_arhdr();
00102   virtual int read_mbrhdr();
00103 
00104  private:
00105   struct fl_hdr filehdr;
00106   struct ar_hdr memberhdr;
00107 };
00108 
00109 class xcoffArchive_64 : private xcoffArchive {
00110  public:
00111   xcoffArchive_64 (fileOpener *file) : xcoffArchive(file) {};
00112   ~xcoffArchive_64 () {if (member_name) free(member_name);};
00113   virtual int read_arhdr();
00114   virtual int read_mbrhdr();
00115 
00116  private:
00117   struct fl_hdr_big filehdr;
00118   struct ar_hdr_big memberhdr;
00119 };
00120 
00121 // We want to mmap a file once, then go poking around inside it. So we
00122 // need to tie a few things together.
00123 
00124 class fileOpener {
00125  public:
00126     static std::vector<fileOpener *> openedFiles;
00127     static fileOpener *openFile(const std::string &file);
00128     static fileOpener *openFile(void *ptr, unsigned size);
00129     
00130     void closeFile();
00131 
00132 #if 0
00133     fileOpener(const std::string &file) : refcount_(1), 
00134         file_(file), fd_(0), 
00135         size_(0), mmapStart_(NULL),
00136         offset_(0) {}
00137 #endif
00138 
00139     fileOpener(void *ptr, unsigned size) : refcount_(1), 
00140         file_(""), fd_(0), 
00141         size_(size), mmapStart_(ptr),
00142         offset_(0) {}
00143     
00144     ~fileOpener();
00145 
00146 #if  0
00147     bool open();
00148     bool mmap();
00149     bool unmap();
00150     bool close();
00151 #endif
00152 
00153     bool pread(void *buf, unsigned size, unsigned offset);
00154     bool read(void *buf, unsigned size);
00155     bool seek(int offset);
00156     bool set(unsigned addr);
00157     // No write :)
00158     // Get me a pointer into the mapped area
00159     void *ptr() const;
00160     void *getPtrAtOffset(unsigned offset) const;
00161     
00162     const std::string &file() const { return file_; }
00163     int fd() const { return fd_; }
00164     unsigned size() const { return size_; }
00165     void *mem_image() const { return mmapStart_; }
00166     void set_file(std::string f) { file_ = f; }
00167 
00168  private:
00169     int refcount_;
00170     std::string file_;
00171     int fd_;
00172     unsigned size_;
00173     void *mmapStart_;
00174 
00175     // Where were we last reading?
00176     unsigned offset_;
00177 };
00178 
00179 
00180 class Symtab;
00181 
00182 /************************************************************************
00183  * class Object
00184 ************************************************************************/
00185 
00186 class Object : public AObject {
00187    friend class Symtab;
00188  public:
00189     Object (const Object &);
00190     Object&   operator= (const Object &);
00191     Object(){}  
00192     Object(MappedFile *, MappedFile *, bool, void (*)(const char *) = log_msg, Offset off = 0, bool alloc_syms = true);
00193     Object(MappedFile *, MappedFile *, dyn_hash_map<std::string, LineInformation> &, std::vector<Region *> &, 
00194           void (*)(const char *) = log_msg, Offset off = 0);
00195     Object(MappedFile *, MappedFile *, std::string &member_name, Offset offset, 
00196             void (*)(const char *) = log_msg, void *base = NULL);
00197     virtual ~Object ()
00198     {
00199 #if 0
00200         if (fo_)
00201             fo_->closeFile();
00202 #endif
00203     }
00204     
00205     Offset getTOCoffset() const { return toc_offset_; }
00206 
00207     // AIX does some weirdness with addresses. We don't want to touch local
00208     // symbols to get addresses right, but that means that the base address
00209     // needs to have a small value added back in. On shared objects.
00210     Offset data_reloc () const { return data_reloc_; }
00211     Offset text_reloc () const { return text_reloc_; }
00212     Offset bss_size () const { return bss_size_; }
00213     
00214     void get_stab_info(char *&stabstr, int &nstabs, void *&stabs, char *&stringpool) const;
00215     
00216     void get_line_info(int& nlines, char*& lines,unsigned long& fdptr) const {
00217     nlines = nlines_;
00218     lines = (char*) linesptr_; 
00219     fdptr = linesfdptr_;
00220     }
00221 
00222     Offset getLoadAddress() const { return loadAddress_; }
00223     Offset getEntryAddress() const { return entryAddress_; }
00224     Offset getBaseAddress() const { return baseAddress_; }
00225     void getModuleLanguageInfo(dyn_hash_map<std::string, supportedLanguages> *mod_langs);
00226     const char *interpreter_name() const { return NULL; }
00227 #if 0
00228     dyn_hash_map<std::string, LineInformation > &getLineInfo() { 
00229         parseFileLineInfo();
00230         return lineInfo_; 
00231     }
00232 #endif
00233 
00234     Dyninst::Architecture getArch();
00235     ObjectType objType() const;
00236     bool isEEL() const { return false; }
00237 
00238     void parseTypeInfo(Symtab *obj);
00239     bool emitDriver(Symtab *obj, string fName, std::vector<Symbol *>&allSymbols, unsigned flag);
00240 
00241 #if 0
00242     bool getRegValueAtFrame(Address pc, 
00243                             Dyninst::MachRegister reg, 
00244                             Dyninst::MachRegisterVal &reg_result,
00245                             MemRegReader *reader);
00246 #endif
00247 
00248 private:
00249 
00250     void load_object(bool alloc_syms);
00251     void load_archive(bool is_aout, bool alloc_syms);
00252     bool fillExceptionTable(struct exceptab *, unsigned int, bool, struct syment *);
00253     void parse_aout(int offset, bool is_aout, bool alloc_syms);
00254     void parseFileLineInfo(Symtab *, dyn_hash_map<std::string, LineInformation> &li);
00255     void parseLineInformation(dyn_hash_map<std::string, LineInformation> &li, std::string * currentSourceFile,
00256                                     char * symbolName,
00257                                     SYMENT * sym,
00258                                     Offset linesfdptr,
00259                                     char * lines,
00260                                     int nlines );
00261                                                                                                          
00262     // We mmap big files and piece them out; this handles the mapping
00263     // and reading and pointerage and...
00264     fileOpener *fo_;
00265 
00266     std::string member_;
00267     Offset offset_;
00268     Offset toc_offset_;
00269     Offset data_reloc_;
00270     Offset text_reloc_;
00271     Offset bss_size_;
00272 
00273     Offset   loadAddress_;      // The object may specify a load address
00274                                     //   Set to 0 if it may load anywhere
00275     Offset entryAddress_;
00276     Offset baseAddress_;
00277     
00278     char *stringPool;
00279 
00280     int  nstabs_;
00281     int  nlines_;
00282     void *stabstr_;
00283     void *stabs_;
00284     void *stringpool_;
00285     void *linesptr_;
00286     Offset linesfdptr_;
00287     bool is64_;
00288     dyn_hash_map<std::string, LineInformation > lineInfo_;
00289 };
00290 
00291 /* This class is only used in symtab.C; the only reason it's in
00292    this header file is so that template0.C can include it to
00293    instantiate pdvector< IncludeFileInfo >. */
00294 class IncludeFileInfo {
00295     public:
00296         unsigned int begin;
00297         unsigned int end;
00298         std::string name;
00299 
00300         IncludeFileInfo() : begin(0), end(0) {};
00301         IncludeFileInfo( int _begin, const char *_name ) : begin(_begin), end(0), name(_name) {};
00302     };
00303 
00304 }//namespace SymtabAPI
00305 
00306 }//namespace Dyninst
00307 
00308 char *P_cplus_demangle( const char * symbol, bool nativeCompiler, bool includeTypes );
00309 
00310 #endif /* !defined(_Object_aix_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