Object.h
Go to the documentation of this file.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_h_)
00038 #define _Object_h_
00039
00040
00041
00042
00043
00044
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
00070
00071
00072
00073
00074
00075
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
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 ,
00128 Dyninst::MachRegister ,
00129 Dyninst::MachRegisterVal & ,
00130 Dyninst::SymtabAPI::MemRegReader * ) {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
00142 SYMTAB_EXPORT virtual void getSegmentsSymReader(std::vector<SymSegment> &) {};
00143
00144 protected:
00145 SYMTAB_EXPORT virtual ~AObject();
00146
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
00158
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_;
00179 Offset loader_len_;
00180
00181
00182
00183
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_;
00199
00200 private:
00201 friend class SymbolIter;
00202 friend class Symtab;
00203
00204 };
00205
00206 }
00207 }
00208
00209
00210
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
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
00248
00249 Symbol *currval();
00250
00251 private:
00252
00253 SymbolIter & operator = ( const SymbolIter & );
00254 };
00255
00256 }
00257 }
00258
00259 #endif