addrtranslate.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 addrtranslate_h_
00032 #define addrtranslate_h_
00033 
00034 #include <string>
00035 #include <vector>
00036 #include <utility>
00037 
00038 #include "common/h/Dictionary.h"
00039 #include "common/h/Types.h"
00040 #include "dynutil/h/dyntypes.h"
00041 #include "dynutil/h/SymReader.h"
00042 #include "dynutil/h/ProcReader.h"
00043 #include "common/h/debug_common.h"
00044 
00045 using namespace std;
00046 
00047 namespace Dyninst {
00048 
00049 class LoadedLib {
00050    friend class AddressTranslate;
00051    friend class AddressTranslateSysV;
00052  protected:
00053    string name;
00054    Address load_addr;
00055    Address data_load_addr;
00056    Address dynamic_addr;
00057    bool should_clean;
00058    vector< pair<Address, unsigned long> > mapped_regions;
00059    SymReader *symreader;
00060    SymbolReaderFactory *symreader_factory;
00061    void *up_ptr;
00062 
00063  public:
00064    COMMON_EXPORT LoadedLib(string name, Address load_addr);
00065    COMMON_EXPORT virtual ~LoadedLib();
00066    COMMON_EXPORT void add_mapped_region(Address addr, unsigned long size);
00067    
00068    COMMON_EXPORT string getName() const;
00069    COMMON_EXPORT void setDataLoadAddr(Address a);
00070    COMMON_EXPORT vector< pair<Address, unsigned long> > *getMappedRegions();
00071 
00072    COMMON_EXPORT virtual Address offToAddress(Offset off);
00073    COMMON_EXPORT virtual Offset addrToOffset(Address addr);
00074 
00075    COMMON_EXPORT virtual Address getCodeLoadAddr() const;
00076    COMMON_EXPORT virtual Address getDataLoadAddr() const;
00077    COMMON_EXPORT virtual Address getDynamicAddr() const;
00078    COMMON_EXPORT virtual void getOutputs(string &filename, Address &code, Address &data);
00079 
00080    COMMON_EXPORT void* getUpPtr();
00081    COMMON_EXPORT void setUpPtr(void *v);
00082 
00083    COMMON_EXPORT void setShouldClean(bool b);
00084    COMMON_EXPORT bool shouldClean();
00085 
00086    COMMON_EXPORT void setFactory(SymbolReaderFactory *factory);
00087 };
00088 
00089 struct LoadedLibCmp
00090 {
00091    COMMON_EXPORT bool operator()(const LoadedLib *a, const LoadedLib *b) const
00092    {
00093       if (a->getCodeLoadAddr() != b->getCodeLoadAddr()) 
00094          return a->getCodeLoadAddr() < b->getCodeLoadAddr();
00095       return (a->getName() < b->getName());
00096    }
00097 };
00098 
00099 class AddressTranslate {
00100  protected:
00101    PID pid;
00102    PROC_HANDLE phandle;
00103    bool creation_error;
00104 
00105    AddressTranslate(PID pid, PROC_HANDLE phand = INVALID_HANDLE_VALUE, std::string exename = std::string(""));
00106    vector<LoadedLib *> libs;
00107    std::string exec_name;
00108    LoadedLib *exec;
00109    SymbolReaderFactory *symfactory;
00110    bool read_abort;
00111  public:
00112 
00113    COMMON_EXPORT static AddressTranslate *createAddressTranslator(PID pid_,
00114                                          ProcessReader *reader_ = NULL,
00115                                          SymbolReaderFactory *symfactory_ = NULL,
00116                                          PROC_HANDLE phand = INVALID_HANDLE_VALUE,
00117                                          std::string exename = std::string(""),
00118                                          Address interp_base = (Address) -1);
00119    COMMON_EXPORT static AddressTranslate *createAddressTranslator(ProcessReader *reader_ = NULL,
00120                                          SymbolReaderFactory *symfactory_ = NULL,
00121                                          std::string exename = std::string(""),
00122                                          Address interp_base = (Address) -1);
00123    
00124    COMMON_EXPORT virtual bool refresh() = 0;
00125    COMMON_EXPORT virtual ~AddressTranslate();
00126   
00127    COMMON_EXPORT PID getPid();
00128    COMMON_EXPORT bool getLibAtAddress(Address addr, LoadedLib* &lib);
00129    COMMON_EXPORT bool getLibs(vector<LoadedLib *> &libs_);
00130    COMMON_EXPORT bool getArchLibs(vector<LoadedLib *> &olibs);
00131    COMMON_EXPORT LoadedLib *getLoadedLib(std::string name);
00132    COMMON_EXPORT LoadedLib *getLoadedLib(SymReader *sym);
00133    COMMON_EXPORT LoadedLib *getExecutable();
00134 
00135    COMMON_EXPORT virtual Address getLibraryTrapAddrSysV();
00136    
00137    void setReadAbort(bool b);
00138 };
00139 
00140 }
00141 
00142 
00143 #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