Module.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 #ifndef __MODULE__H__
00032 #define __MODULE__H__
00033  
00034 #include "symutil.h"
00035 #include "Symbol.h"
00036 
00037 #include "Annotatable.h"
00038 #include "Serialization.h"
00039 
00040 namespace Dyninst{
00041 namespace SymtabAPI{
00042 
00043 class typeCollection;
00044 class LineInformation;
00045 class localVar;
00046 class Symtab;
00047 
00048 class Statement : public AnnotatableSparse, public Serializable
00049 {
00050     friend class Module;
00051     friend class std::vector<Statement>;
00052     friend class LineInformation;
00053 
00054     Statement(const char *file, unsigned int line, unsigned int col = 0,
00055              Offset start_addr = (Offset) -1L, Offset end_addr = (Offset) -1L) :
00056       file_(file ? std::string(file) : std::string()),
00057       line_(line),
00058       start_addr_(start_addr),
00059       end_addr_(end_addr),
00060       first(file_.c_str()),
00061       second(line_),
00062       column(col)
00063       {
00064       }
00065     
00066     std::string file_; // Maybe this should be module?
00067     unsigned int line_;
00068     Offset start_addr_;
00069     Offset end_addr_;
00070 
00071     public:
00072     const char *first;
00073     unsigned int second;
00074     unsigned int column;
00075 
00076     Statement() : first(NULL), second(line_) {}
00077     struct StatementLess {
00078         bool operator () ( const Statement &lhs, const Statement &rhs ) const;
00079     };
00080 
00081     typedef StatementLess LineNoTupleLess;
00082 
00083     bool operator==(const Statement &cmp) const;
00084     ~Statement() {}
00085 
00086     SYMTAB_EXPORT Offset startAddr() { return start_addr_;}
00087     SYMTAB_EXPORT Offset endAddr() {return end_addr_;}
00088     SYMTAB_EXPORT std::string getFile() { return file_;}
00089     SYMTAB_EXPORT unsigned int getLine() {return line_;}
00090     SYMTAB_EXPORT unsigned int getColumn() {return column;}
00091 
00092     SYMTAB_EXPORT Serializable *serialize_impl(SerializerBase *sb, const char *tag = "Statement") THROW_SPEC (SerializerError);
00093 
00094     //  Does dyninst really need these?
00095     SYMTAB_EXPORT void setLine(unsigned int l) {line_ = l;}
00096     SYMTAB_EXPORT void setColumn(unsigned int l) {column = l;}
00097     SYMTAB_EXPORT void setFile(const char * l) {file_ = std::string(l); first = file_.c_str();}
00098     SYMTAB_EXPORT void setStartAddr(Offset l) {start_addr_ = l;}
00099     SYMTAB_EXPORT void setEndAddr(Offset l) {end_addr_ = l;}
00100 };
00101 
00102 typedef Statement LineNoTuple;
00103 #define MODULE_ANNOTATABLE_CLASS AnnotatableSparse
00104 
00105 class Module : public LookupInterface,
00106                public Serializable, 
00107                public MODULE_ANNOTATABLE_CLASS
00108 {
00109     friend class Symtab;
00110 
00111     public:
00112 
00113     SYMTAB_EXPORT Module();
00114     SYMTAB_EXPORT Module(supportedLanguages lang, Offset adr, std::string fullNm,
00115                         Symtab *img);
00116     SYMTAB_EXPORT Module(const Module &mod);
00117     SYMTAB_EXPORT bool operator==(Module &mod);
00118 
00119     SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *sb, const char *tag = "Module") THROW_SPEC (SerializerError);
00120 
00121     SYMTAB_EXPORT const std::string &fileName() const;
00122     SYMTAB_EXPORT const std::string &fullName() const;
00123     SYMTAB_EXPORT bool setName(std::string newName);
00124 
00125     SYMTAB_EXPORT supportedLanguages language() const;
00126     SYMTAB_EXPORT void setLanguage(supportedLanguages lang);
00127 
00128     SYMTAB_EXPORT Offset addr() const;
00129     SYMTAB_EXPORT Symtab *exec() const;
00130 
00131     SYMTAB_EXPORT bool isShared() const;
00132     SYMTAB_EXPORT ~Module();
00133 
00134     // Symbol output methods
00135     SYMTAB_EXPORT virtual bool findSymbol(std::vector<Symbol *> &ret, 
00136                                               const std::string& name,
00137                                               Symbol::SymbolType sType = Symbol::ST_UNKNOWN, 
00138                                               NameType nameType = anyName,
00139                                               bool isRegex = false, 
00140                                               bool checkCase = false,
00141                                               bool includeUndefined = false);
00142     SYMTAB_EXPORT virtual bool getAllSymbolsByType(std::vector<Symbol *> &ret, 
00143             Symbol::SymbolType sType);
00144     SYMTAB_EXPORT virtual bool getAllSymbols(std::vector<Symbol *> &ret);
00145 
00146 
00147     // Function based methods
00148     SYMTAB_EXPORT bool getAllFunctions(std::vector<Function *>&ret);
00149     SYMTAB_EXPORT bool findFunctionByEntryOffset(Function *&ret, const Offset offset);
00150     SYMTAB_EXPORT bool findFunctionsByName(std::vector<Function *> &ret, const std::string& name,
00151             NameType nameType = anyName, 
00152             bool isRegex = false,
00153             bool checkCase = true);
00154 
00155     // Variable based methods
00156     SYMTAB_EXPORT bool findVariableByOffset(Variable *&ret, const Offset offset);
00157     SYMTAB_EXPORT bool findVariablesByName(std::vector<Variable *> &ret, const std::string& name,
00158             NameType nameType = anyName, 
00159             bool isRegex = false, 
00160             bool checkCase = true);
00161    SYMTAB_EXPORT bool getAllVariables(std::vector<Variable *> &ret);
00162 
00163 
00164    // Type output methods
00165    SYMTAB_EXPORT virtual bool findType(Type *&type, std::string name);
00166    SYMTAB_EXPORT virtual bool findVariableType(Type *&type, std::string name);
00167 
00168    SYMTAB_EXPORT std::vector<Type *> *getAllTypes();
00169    SYMTAB_EXPORT std::vector<std::pair<std::string, Type *> > *getAllGlobalVars();
00170 
00171    SYMTAB_EXPORT typeCollection *getModuleTypes();
00172 
00173    /***** Local Variable Information *****/
00174    SYMTAB_EXPORT bool findLocalVariable(std::vector<localVar *>&vars, std::string name);
00175 
00176    /***** Line Number Information *****/
00177    SYMTAB_EXPORT bool getAddressRanges(std::vector<std::pair<Offset, Offset> >&ranges,
00178          std::string lineSource, unsigned int LineNo);
00179    SYMTAB_EXPORT bool getSourceLines(std::vector<Statement *> &lines,
00180          Offset addressInRange);
00181    SYMTAB_EXPORT bool getSourceLines(std::vector<LineNoTuple> &lines,
00182          Offset addressInRange);
00183    SYMTAB_EXPORT bool getStatements(std::vector<Statement *> &statements);
00184    SYMTAB_EXPORT LineInformation *getLineInformation();
00185 
00186    SYMTAB_EXPORT bool hasLineInformation();
00187    SYMTAB_EXPORT bool setDefaultNamespacePrefix(std::string str);
00188 
00189 
00190    //  Super secret private methods that aren't really private
00191    SYMTAB_EXPORT typeCollection *getModuleTypesPrivate();
00192 
00193    private:
00194    bool setLineInfo(Dyninst::SymtabAPI::LineInformation *lineInfo);
00195 
00196 
00197    std::string fileName_;                   // short file 
00198    std::string fullName_;                   // full path to file 
00199    supportedLanguages language_;
00200    Offset addr_;                      // starting address of module
00201    Symtab *exec_;
00202 };
00203 
00204 
00205 
00206 
00207 
00208 }//namespace SymtabAPI
00209 
00210 }//namespace Dyninst
00211 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1