00001 /** 00002 * @file symbol_container.h 00003 * Internal container for symbols 00004 * 00005 * @remark Copyright 2002, 2003 OProfile authors 00006 * @remark Read the file COPYING 00007 * 00008 * @author Philippe Elie 00009 * @author John Levon 00010 */ 00011 00012 #ifndef SYMBOL_CONTAINER_H 00013 #define SYMBOL_CONTAINER_H 00014 00015 #include <string> 00016 #include <set> 00017 00018 #include "symbol.h" 00019 #include "symbol_functors.h" 00020 00021 /** 00022 * An arbitrary container of symbols. Supports lookup 00023 * by name, by VMA, and by file location. 00024 * 00025 * Lookup by name or by VMA is O(n). Lookup by file location 00026 * is O(log(n)). 00027 */ 00028 class symbol_container { 00029 public: 00030 /// container type 00031 typedef std::set<symbol_entry, less_symbol> symbols_t; 00032 00033 typedef symbols_t::size_type size_type; 00034 00035 /// return the number of symbols stored 00036 size_type size() const; 00037 00038 /** 00039 * Insert a new symbol. If the symbol already exists in the container, 00040 * then the sample counts are accumulated. 00041 * Returns the newly created symbol or the existing one. This pointer 00042 * remains valid during the whole life time of a symbol_container 00043 * object and is warranted unique according to less_symbol comparator. 00044 * Can only be done before any file-location based lookups, since the 00045 * two lookup methods are not synchronised. 00046 */ 00047 symbol_entry const * insert(symbol_entry const &); 00048 00049 /// find the symbols at the given filename and line number, if any 00050 symbol_collection const find(debug_name_id filename, size_t linenr) const; 00051 00052 /// find the symbols defined in the given filename, if any 00053 symbol_collection const find(debug_name_id filename) const; 00054 00055 /// find the symbol with the given image_name vma if any 00056 symbol_entry const * find_by_vma(std::string const & image_name, 00057 bfd_vma vma) const; 00058 00059 /// Search a symbol. Return NULL if not found. 00060 symbol_entry const * find(symbol_entry const & symbol) const; 00061 00062 /// return start of symbols 00063 symbols_t::iterator begin(); 00064 00065 /// return end of symbols 00066 symbols_t::iterator end(); 00067 00068 private: 00069 /// build the symbol by file-location cache 00070 void build_by_loc() const; 00071 00072 /** 00073 * The main container of symbols. Multiple symbols with the same 00074 * name are allowed. 00075 */ 00076 symbols_t symbols; 00077 00078 /** 00079 * Differently-named symbol at same file location are allowed e.g. 00080 * template instantiation. 00081 */ 00082 typedef std::multiset<symbol_entry const *, less_by_file_loc> 00083 symbols_by_loc_t; 00084 00085 // must be declared after the set to ensure a correct life-time. 00086 00087 /** 00088 * Symbols sorted by location order. Lazily built on request, 00089 * so mutable. 00090 */ 00091 mutable symbols_by_loc_t symbols_by_loc; 00092 }; 00093 00094 #endif /* SYMBOL_CONTAINER_H */
1.6.1