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 #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 }
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 }
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 }
00090
00091 bool LineInformation::getSourceLines( Offset addressInRange,
00092 vector< Statement *> & lines )
00093 {
00094 return getValues( addressInRange, lines );
00095 }
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 }
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 }
00119
00120 LineInformation::const_iterator LineInformation::begin() const
00121 {
00122 return Dyninst::SymtabAPI::RangeLookup< Statement, Statement::StatementLess >::begin();
00123 }
00124
00125 LineInformation::const_iterator LineInformation::end() const
00126 {
00127 return Dyninst::SymtabAPI::RangeLookup< Statement, Statement::StatementLess >::end();
00128 }
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
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 }
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
00159 return (file_ == cmp.file_);
00160 }
00161
00162
00163
00164
00165
00166
00167
00168 LineInformation::~LineInformation()
00169 {
00170 }
00171
00172 #if !defined(SERIALIZATION_DISABLED)
00173 Serializable *LineInformation::ac_serialize_impl(SerializerBase *sb, const char *tag) THROW_SPEC (SerializerError)
00174 {
00175
00176
00177
00178 std::pair<int, int> mypair;
00179 std::pair<std::pair<int, int>, int> mypair2;
00180
00181 ifxml_start_element(sb, tag);
00182
00183
00184 gtranslate(sb, valuesByAddressRangeMap, "valuesByAddressRangeMap", "valueByAddressRange");
00185 gtranslate(sb, addressRangesByValueMap, "addressRangesByValueMap", "addressRangeByValue");
00186 gtranslate(sb, size_, "size");
00187
00188
00189
00190
00191
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