00001 00012 #include <string> 00013 #include <algorithm> 00014 #include <set> 00015 #include <vector> 00016 00017 #include "symbol_container.h" 00018 00019 using namespace std; 00020 00021 symbol_container::size_type symbol_container::size() const 00022 { 00023 return symbols.size(); 00024 } 00025 00026 00027 symbol_entry const * symbol_container::insert(symbol_entry const & symb) 00028 { 00029 pair<symbols_t::iterator, bool> p = symbols.insert(symb); 00030 if (!p.second) { 00031 // safe: count is not used by sorting criteria 00032 symbol_entry * symbol = const_cast<symbol_entry*>(&*p.first); 00033 symbol->sample.counts += symb.sample.counts; 00034 } 00035 00036 return &*p.first; 00037 } 00038 00039 00040 symbol_collection const 00041 symbol_container::find(debug_name_id filename, size_t linenr) const 00042 { 00043 build_by_loc(); 00044 00045 symbol_entry symbol; 00046 symbol.sample.file_loc.filename = filename; 00047 symbol.sample.file_loc.linenr = linenr; 00048 00049 symbol_collection result; 00050 00051 typedef symbols_by_loc_t::const_iterator it; 00052 pair<it, it> p_it = symbols_by_loc.equal_range(&symbol); 00053 for ( ; p_it.first != p_it.second; ++p_it.first) 00054 result.push_back(*p_it.first); 00055 00056 return result; 00057 } 00058 00059 00060 symbol_collection const 00061 symbol_container::find(debug_name_id filename) const 00062 { 00063 build_by_loc(); 00064 00065 symbol_entry symbol; 00066 symbol.sample.file_loc.filename = filename; 00067 symbol.sample.file_loc.linenr = 0; 00068 00069 typedef symbols_by_loc_t::const_iterator it; 00070 it first = symbols_by_loc.lower_bound(&symbol); 00071 symbol.sample.file_loc.linenr = (unsigned int)size_t(-1); 00072 it last = symbols_by_loc.upper_bound(&symbol); 00073 00074 symbol_collection result; 00075 for ( ; first != last ; ++first) 00076 result.push_back(*first); 00077 00078 return result; 00079 } 00080 00081 00082 void symbol_container::build_by_loc() const 00083 { 00084 if (!symbols_by_loc.empty()) 00085 return; 00086 00087 symbols_t::const_iterator cit = symbols.begin(); 00088 symbols_t::const_iterator end = symbols.end(); 00089 for (; cit != end; ++cit) 00090 symbols_by_loc.insert(&*cit); 00091 } 00092 00093 00094 symbol_entry const * symbol_container::find_by_vma(string const & image_name, 00095 bfd_vma vma) const 00096 { 00097 // FIXME: this is too inefficient probably 00098 symbols_t::const_iterator it; 00099 for (it = symbols.begin(); it != symbols.end(); ++it) { 00100 if (it->sample.vma == vma && 00101 image_names.name(it->image_name) == image_name) 00102 return &*it; 00103 } 00104 00105 return 0; 00106 } 00107 00108 00109 symbol_container::symbols_t::iterator symbol_container::begin() 00110 { 00111 return symbols.begin(); 00112 } 00113 00114 00115 symbol_container::symbols_t::iterator symbol_container::end() 00116 { 00117 return symbols.end(); 00118 } 00119 00120 symbol_entry const * symbol_container::find(symbol_entry const & symbol) const 00121 { 00122 symbols_t::const_iterator it = symbols.find(symbol); 00123 return it == symbols.end() ? 0 : &*it; 00124 }