00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #if !defined(_Object_aix_h_)
00038 #define _Object_aix_h_
00039
00040
00041
00042
00043
00044 #include "common/h/headers.h"
00045
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
00077
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
00122
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
00158
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
00176 unsigned offset_;
00177 };
00178
00179
00180 class Symtab;
00181
00182
00183
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
00208
00209
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 ®_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
00263
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_;
00274
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
00292
00293
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 }
00305
00306 }
00307
00308 char *P_cplus_demangle( const char * symbol, bool nativeCompiler, bool includeTypes );
00309
00310 #endif