blob: 73ca581d21a0fb1d03928573b35cbe4d441c5775 [file] [log] [blame]
Upstreamcc2ee171970-01-12 13:46:40 +00001/**
2 * @file symbol_container.h
3 * Internal container for symbols
4 *
5 * @remark Copyright 2002, 2003 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author Philippe Elie
9 * @author John Levon
10 */
11
12#ifndef SYMBOL_CONTAINER_H
13#define SYMBOL_CONTAINER_H
14
15#include <string>
16#include <set>
17
18#include "symbol.h"
19#include "symbol_functors.h"
20
21/**
22 * An arbitrary container of symbols. Supports lookup
23 * by name, by VMA, and by file location.
24 *
25 * Lookup by name or by VMA is O(n). Lookup by file location
26 * is O(log(n)).
27 */
28class symbol_container {
29public:
30 /// container type
31 typedef std::set<symbol_entry, less_symbol> symbols_t;
32
33 typedef symbols_t::size_type size_type;
34
35 /// return the number of symbols stored
36 size_type size() const;
37
38 /**
39 * Insert a new symbol. If the symbol already exists in the container,
40 * then the sample counts are accumulated.
41 * Returns the newly created symbol or the existing one. This pointer
42 * remains valid during the whole life time of a symbol_container
43 * object and is warranted unique according to less_symbol comparator.
44 * Can only be done before any file-location based lookups, since the
45 * two lookup methods are not synchronised.
46 */
47 symbol_entry const * insert(symbol_entry const &);
48
49 /// find the symbol at the given filename and line number, if any
50 symbol_entry const * find(debug_name_id filename,
51 size_t linenr) const;
52
53 /// find the symbol with the given image_name vma if any
54 symbol_entry const * find_by_vma(std::string const & image_name,
55 bfd_vma vma) const;
56
57 /// Search a symbol. Return NULL if not found.
58 symbol_entry const * find(symbol_entry const & symbol) const;
59
60 /// return start of symbols
61 symbols_t::iterator begin();
62
63 /// return end of symbols
64 symbols_t::iterator end();
65
66private:
67 /// build the symbol by file-location cache
68 void build_by_loc() const;
69
70 /**
71 * The main container of symbols. Multiple symbols with the same
72 * name are allowed.
73 */
74 symbols_t symbols;
75
76 /**
77 * Differently-named symbol at same file location are allowed e.g.
78 * template instantiation.
79 */
80 typedef std::multiset<symbol_entry const *, less_by_file_loc>
81 symbols_by_loc_t;
82
83 // must be declared after the set to ensure a correct life-time.
84
85 /**
86 * Symbols sorted by location order. Lazily built on request,
87 * so mutable.
88 */
89 mutable symbols_by_loc_t symbols_by_loc;
90};
91
92#endif /* SYMBOL_CONTAINER_H */