LineInformation.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 "LineInformation.h"
00032 #include <assert.h>
00033 #include <list>
00034 #include <cstring>
00035 #include "boost/functional/hash.hpp"
00036 #include "common/h/headers.h"
00037 #include "Module.h"
00038 #include "Serialization.h"
00039 
00040 using namespace Dyninst;
00041 using namespace Dyninst::SymtabAPI;
00042 using namespace std;
00043 
00044 LineInformation::LineInformation() : 
00045     AnnotationContainer<Statement>(),
00046    Dyninst::SymtabAPI::RangeLookup< Statement, Statement::StatementLess >()
00047 {
00048    size_ = 0;
00049 } /* end LineInformation constructor */
00050 
00051 bool LineInformation::addItem_impl(Statement s)
00052 {
00053    size_++;
00054 
00055    bool ret = addValue( s, s.startAddr(), s.endAddr() );
00056     return ret;
00057 }
00058 bool LineInformation::addLine( const char * lineSource, 
00059       unsigned int lineNo, 
00060       unsigned int lineOffset, 
00061       Offset lowInclusiveAddr, 
00062       Offset highExclusiveAddr ) 
00063 {
00064 
00065    bool ret = addItem_impl( Statement(lineSource, lineNo, lineOffset, 
00066                                       lowInclusiveAddr, highExclusiveAddr)); 
00067 
00068    return ret;
00069 } /* end setLineToAddressRangeMapping() */
00070 
00071 void LineInformation::addLineInfo(LineInformation *lineInfo)
00072 {
00073    const_iterator iter = lineInfo->begin();
00074 
00075    for (; iter != lineInfo->end(); iter++)
00076    {
00077       addLine(iter->second.file_.c_str(), iter->second.line_, iter->second.column, 
00078             iter->first.first, iter->first.second);
00079    }
00080 }
00081 
00082 bool LineInformation::addAddressRange( Offset lowInclusiveAddr, 
00083       Offset highExclusiveAddr, 
00084       const char * lineSource, 
00085       unsigned int lineNo, 
00086       unsigned int lineOffset ) 
00087 {
00088    return addLine( lineSource, lineNo, lineOffset, lowInclusiveAddr, highExclusiveAddr );
00089 } /* end setAddressRangeToLineMapping() */
00090 
00091 bool LineInformation::getSourceLines( Offset addressInRange, 
00092       vector< Statement *> & lines ) 
00093 {
00094    return getValues( addressInRange, lines );
00095 } /* end getLinesFromAddress() */
00096 
00097 bool LineInformation::getSourceLines( Offset addressInRange, 
00098                                       vector<LineNoTuple> &lines) 
00099 {
00100    vector<Statement *> plines;
00101    bool result = getValues(addressInRange, plines);
00102    if (!result) {
00103       return false;
00104    }
00105    for (vector<Statement *>::iterator i = plines.begin(); i != plines.end(); i++) {
00106       LineNoTuple lnt = **i;
00107       lines.push_back(lnt);
00108    }
00109    return true;
00110 } /* end getLinesFromAddress() */
00111 
00112 bool LineInformation::getAddressRanges( const char * lineSource, 
00113       unsigned int lineNo, vector< AddressRange > & ranges ) 
00114 {
00115    bool ret = Dyninst::SymtabAPI::RangeLookup< Statement, Statement::StatementLess >::getAddressRanges( Statement( lineSource, lineNo ), ranges );
00116 
00117    return ret;
00118 } /* end getAddressRangesFromLine() */
00119 
00120 LineInformation::const_iterator LineInformation::begin() const 
00121 {
00122    return Dyninst::SymtabAPI::RangeLookup< Statement, Statement::StatementLess >::begin();
00123 } /* end begin() */
00124 
00125 LineInformation::const_iterator LineInformation::end() const 
00126 {
00127    return Dyninst::SymtabAPI::RangeLookup< Statement, Statement::StatementLess >::end();
00128 } /* end begin() */
00129 
00130 unsigned LineInformation::getSize() const
00131 {
00132    return size_;
00133 }
00134 
00135 bool Statement::StatementLess::operator () ( const Statement &lhs, const Statement &rhs ) const
00136 {
00137     //  dont bother with ordering by column information yet.
00138 
00139     int strcmp_res = strcmp( lhs.file_.c_str(), rhs.file_.c_str());
00140 
00141     if (strcmp_res < 0 )
00142         return true;
00143 
00144     if ( strcmp_res == 0 )
00145     {
00146         if ( lhs.line_ < rhs.line_ )
00147             return true;
00148     }
00149 
00150     return false;
00151 } /* end StatementLess() */
00152 
00153 bool Statement::operator==(const Statement &cmp) const 
00154 {
00155     if (line_ != cmp.line_) return false;
00156     if (column != cmp.column) return false;
00157 
00158     //  is compare-by-pointer OK here, or do we really have to really strcmp?
00159     return (file_ == cmp.file_);
00160 }
00161 
00162 /* We free the strings we allocated, and let the compiler clean up everything else:
00163 
00164    Section 10.4.6 [Stroustroup's C++]: "When a class object containing class
00165    objects is destroyed, the body of that object's own destructor is executed first,
00166    and then the members' destructors are executed in the reverse order of declaration." */
00167 
00168 LineInformation::~LineInformation() 
00169 {
00170 } /* end LineInformation destructor */
00171 
00172 #if !defined(SERIALIZATION_DISABLED)
00173 Serializable *LineInformation::ac_serialize_impl(SerializerBase *sb, const char *tag) THROW_SPEC (SerializerError)
00174 {
00175    //fprintf(stderr, "%s[%d]:  LineInformation::serialize -- IMPLEMENT ME sb = %p\n", 
00176    //      FILE__, __LINE__, sb);
00177 
00178     std::pair<int, int> mypair;
00179     std::pair<std::pair<int, int>, int> mypair2;
00180 
00181     ifxml_start_element(sb, tag);
00182     //gtranslate(sb, mypair);
00183     //gtranslate(sb, mypair2);
00184     gtranslate(sb, valuesByAddressRangeMap, "valuesByAddressRangeMap", "valueByAddressRange");
00185     gtranslate(sb, addressRangesByValueMap, "addressRangesByValueMap", "addressRangeByValue");
00186     gtranslate(sb, size_, "size");
00187     //multimap_translator<std::pair<Address, Address>, Statement> mt;
00188     //mt(sb, valuesByAddressRangeMap, "valuesByAddressRangeMap", "valueByAddressRange");
00189     //translate_multimap(sb, valuesByAddressRangeMap, "valuesByAddressRangeMap", "valueByAddressRange");
00190 
00191     //multimap_translator<std::pair<Address, Address>, Statement>(sb, addressRangesByValueMap, "addressRangesByValueMap", "addressRangeByValue");
00192     ifxml_end_element(sb, tag);
00193     return NULL;
00194 }
00195 #else
00196 Serializable *LineInformation::ac_serialize_impl(SerializerBase *, const char *) THROW_SPEC (SerializerError)
00197 {
00198    return NULL;
00199 }
00200 #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