LinkMap.C

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 #include "LinkMap.h"
00032 #include <iostream>
00033 
00034 using namespace Dyninst;
00035 using namespace SymtabAPI;
00036 
00037 LinkMap::LinkMap() :
00038     allocatedData(NULL), allocatedSize(0), commonStorage(NULL),
00039     bssRegionOffset(0), bssSize(0), bssRegionAlign(0),
00040     dataRegionOffset(0), dataSize(0), dataRegionAlign(0),
00041     stubRegionOffset(0), stubSize(0),
00042     codeRegionOffset(0), codeSize(0), codeRegionAlign(0),
00043     tlsRegionOffset(0), tlsSize(0), tlsRegionAlign(0),
00044     gotRegionOffset(0), gotSize(0), gotRegionAlign(0),
00045     ctorDtorHandler(NULL), ctorRegionOffset(0), ctorSize(0),
00046     ctorRegionAlign(0), originalCtorRegion(NULL), dtorRegionOffset(0),
00047     dtorSize(0), dtorRegionAlign(0), originalDtorRegion(NULL) 
00048 {
00049 }
00050 
00051 LinkMap::~LinkMap() {
00052     if( commonStorage ) delete commonStorage;
00053 }
00054 
00055 ostream & operator<<(ostream &os, LinkMap &lm) {
00056      lm.printAll(os, 0);
00057      return os;
00058 }
00059 
00060 void LinkMap::print(Offset globalOffset) {
00061     printAll(std::cout, globalOffset);
00062 }
00063 
00064 void LinkMap::printAll(ostream &os, Offset globalOffset) {
00065     os << "Size of allocated space = 0x" << hex << allocatedSize << dec << endl;
00066 
00067     if( codeRegions.size() > 0 ) {
00068         os << "New CODE Region: Offset: 0x" << hex << (globalOffset + codeRegionOffset) << dec
00069            << " Size: 0x" << hex << codeSize << dec 
00070            << " Alignment: 0x" << hex << codeRegionAlign << dec
00071            << endl;
00072         printRegions(os, codeRegions, globalOffset);
00073         os << endl;
00074     }
00075 
00076     if( dataRegions.size() > 0 ) {
00077         os << "New DATA Region: Offset: 0x" << hex << (globalOffset + dataRegionOffset) << dec
00078            << " Size: 0x" << hex << dataSize << dec 
00079            << " Alignment: 0x" << hex << dataRegionAlign << dec
00080            << endl;
00081         printRegions(os, dataRegions, globalOffset);
00082         os << endl;
00083     }
00084 
00085     if( tlsRegions.size() > 0 ) {
00086         os << "New TLS Region: Offset: 0x" << hex << (globalOffset + tlsRegionOffset) << dec
00087            << " Size: 0x" << hex << tlsSize << dec 
00088            << " Alignment: 0x" << hex << tlsRegionAlign << dec
00089            << endl;
00090         printRegions(os, tlsRegions, globalOffset);
00091 
00092         os << endl;
00093 
00094         // Print each symbol ordered by its offset from the TCB
00095         map<Offset, Symbol *> off2Sym;
00096         vector<Symbol *>::iterator sym_it;
00097         for(sym_it = tlsSymbols.begin(); sym_it != tlsSymbols.end(); ++sym_it) {
00098             off2Sym.insert(make_pair((*sym_it)->getOffset(), *sym_it));
00099         }
00100 
00101         map<Offset, Symbol *>::iterator off_it;
00102         for(off_it = off2Sym.begin(); off_it != off2Sym.end(); ++off_it) {
00103             os << "\tSymbol: " << off_it->second->getMangledName() 
00104                << " Offset: 0x" << hex << off_it->first << dec 
00105                << endl;
00106         }
00107 
00108         os << endl;
00109     }
00110 
00111     if( gotSize > 0 ) {
00112         os << "New GOT Region: Offset: 0x" << hex << (globalOffset + gotRegionOffset) << dec
00113            << " Size: 0x" << hex << gotSize << dec 
00114            << " Alignment: 0x" << hex << gotRegionAlign << dec
00115            << endl;
00116 
00117         // Print out GOT entries in order
00118         map<Offset, Symbol *> gotByEntry;
00119         map<Symbol *, Offset>::iterator sym_it;
00120         for(sym_it = gotSymbols.begin(); sym_it != gotSymbols.end(); ++sym_it) {
00121             gotByEntry.insert(make_pair(sym_it->second, sym_it->first));
00122         }
00123 
00124         map<Offset, Symbol *>::iterator off_it;
00125         for(off_it = gotByEntry.begin(); off_it != gotByEntry.end(); ++off_it) {
00126             os << "\tGOT Offset: 0x" << hex << off_it->first << dec
00127                << " Symbol: " << off_it->second->getMangledName()
00128                << " Offset: 0x" << hex << off_it->second->getOffset() << dec << endl;
00129         }
00130 
00131         os << endl;
00132     }
00133 
00134     if( newCtorRegions.size() > 0 ) {
00135         os << "New .ctors region: Offset: 0x" << hex << (globalOffset + ctorRegionOffset) << dec
00136            << " Size: 0x" << hex << ctorSize << dec
00137            << " Alignment: 0x" << hex << ctorRegionAlign << dec
00138            << endl;
00139 
00140         if( originalCtorRegion != NULL ) {
00141             printRegionFromInfo(os, originalCtorRegion, 0, 0);
00142         }
00143 
00144         vector<Region *>::iterator reg_it;
00145         for(reg_it = newCtorRegions.begin(); reg_it != newCtorRegions.end(); ++reg_it) {
00146             printRegion(os, *reg_it, globalOffset);
00147         }
00148 
00149         os << endl;
00150     }
00151 
00152     if( newDtorRegions.size() > 0 ) {
00153          os << "New .dtors region: Offset: 0x" << hex << (globalOffset + dtorRegionOffset) << dec
00154            << " Size: 0x" << hex << dtorSize << dec
00155            << " Alignment: 0x" << hex << dtorRegionAlign << dec
00156            << endl;
00157 
00158         if( originalDtorRegion != NULL ) {
00159             printRegionFromInfo(os, originalDtorRegion, 0, 0);
00160         }
00161 
00162         vector<Region *>::iterator reg_it;
00163         for(reg_it = newDtorRegions.begin(); reg_it != newDtorRegions.end(); ++reg_it) {
00164             printRegion(os, *reg_it, globalOffset);
00165         }
00166 
00167         os << endl;
00168         
00169     }
00170 
00171     if( bssRegions.size() > 0 ) {
00172         os << "New BSS Region: Offset: 0x" << hex << (globalOffset + bssRegionOffset) << dec
00173            << " Size: 0x" << hex << bssSize << dec 
00174            << " Alignment: 0x" << hex << bssRegionAlign << dec
00175            << endl;
00176         printRegions(os, bssRegions, globalOffset);
00177         os << endl;
00178     }
00179 
00180 }
00181 
00182 void LinkMap::printBySymtab(ostream &os, vector<Symtab *> &symtabs, Offset globalOffset) {
00183     vector<Symtab *>::iterator symtab_it;
00184     for(symtab_it = symtabs.begin(); symtab_it != symtabs.end(); ++symtab_it) {
00185         os << "Object: " << (*symtab_it)->memberName() << endl;
00186 
00187         // Print the location of all the Regions
00188         vector<Region *> regions;
00189         if( !(*symtab_it)->getAllRegions(regions) ) continue;
00190 
00191         vector<Region *>::iterator reg_it;
00192         for(reg_it = regions.begin(); reg_it != regions.end(); ++reg_it) {
00193             printRegion(os, *reg_it, globalOffset);
00194         }
00195 
00196         os << endl;
00197 
00198         // Print the location of all the Functions
00199         vector<Function *> funcs;
00200         if( !(*symtab_it)->getAllFunctions(funcs) ) continue;
00201 
00202         vector<Function *>::iterator func_it;
00203         for(func_it = funcs.begin(); func_it != funcs.end(); ++func_it) {
00204             Symbol *symbol = (*func_it)->getFirstSymbol();
00205             os << "\tFunction: " << symbol->getPrettyName()
00206                << " Offset: 0x" << hex << symbol->getOffset() << dec
00207                << " - 0x" << hex << (symbol->getOffset() + symbol->getSize() - 1) << dec
00208                << " Size: 0x" << hex << symbol->getSize() << dec
00209                << endl;
00210         }
00211 
00212         os << endl;
00213     }
00214 }
00215 
00216 void LinkMap::printRegions(ostream &os, deque<Region *> &regions, Offset globalOffset) {
00217     deque<Region *>::iterator reg_it;
00218     for(reg_it = regions.begin(); reg_it != regions.end(); ++reg_it) {
00219         printRegion(os, *reg_it, globalOffset);
00220     }
00221 }
00222 
00223 void LinkMap::printRegion(ostream &os, Region *region, Offset globalOffset) {
00224     map<Region *, AllocPair>::iterator result;
00225     result = regionAllocs.find(region);
00226     if( result != regionAllocs.end() ) {
00227         AllocPair pair = result->second;
00228         printRegionFromInfo(os, region, globalOffset + pair.second,
00229                 pair.first);
00230     }
00231 }
00232 
00233 void LinkMap::printRegionFromInfo(ostream &os, Region *region, Offset regionOffset, Offset padding)
00234 {
00235     os << "\tRegion " << region->getRegionName() 
00236            << " Padding: 0x" << hex << padding << dec
00237            << " Offset: 0x" << hex << regionOffset << dec
00238            << " - 0x" << hex << (regionOffset + region->getMemSize() - 1) << dec
00239            << " Size: 0x" << hex << region->getMemSize() << dec
00240            << " Alignment: 0x" << hex << region->getMemAlignment() << dec
00241            << endl;
00242 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1