HPCToolkit
SimpleSymbols.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 #ifndef __SIMPLESYMBOLS__
48 #define __SIMPLESYMBOLS__
49 
50 //******************************************************************************
51 // system includes
52 //******************************************************************************
53 
54 #include <string>
55 #include <stdint.h>
56 #include <set>
57 
58 
59 //******************************************************************************
60 // type declarations
61 //******************************************************************************
62 
63 typedef enum {
70 
71 
72 typedef enum {
78 
79 
80 class SimpleSymbol {
81 public:
82  SimpleSymbol(uint64_t __addr, SimpleSymbolKind __kind,
83  SimpleSymbolBinding __binding, const char *__name);
84 
85  uint64_t addr() const { return _addr; };
86  SimpleSymbolKind kind() const { return _kind; };
87  SimpleSymbolBinding binding() const { return _binding; };
88  const std::string &name() const { return _name; };
89 
90  void setName(std::string __name) { _name = __name; }
91  void setBinding(SimpleSymbolBinding __binding) { _binding = __binding; }
92  void setKind(SimpleSymbolKind __kind) { _kind = __kind; }
93 
94  void dump();
95 
96 private:
97  uint64_t _addr;
100  std::string _name;
101 };
102 
103 
104 // SimpleSymbolsCoalesceCallback must yield its result in left
105 typedef void
107 (
108  SimpleSymbol *left,
109  const SimpleSymbol *right
110 );
111 
112 
113 // a useful coalescing callback
115 
116 
118 public:
119  SimpleSymbols(const char *name);
120  virtual ~SimpleSymbols() {}
121 
122  const std::string& name();
123 
124  // simply add the element as presented. there is no attempt to incrementally
125  // coalesce symbols with the same address. use the coalesce method after
126  // all insertions if symbols at the same address should be pruned.
128  const char *name);
129 
130  // note: the internal representation is a vector and find causes the
131  // vector to be sorted. don't find while still inserting! insert
132  // and coalesce at the end to avoid O(n^2) cost.
133  SimpleSymbol *find(uint64_t vma);
134 
135  // wrapper around find to support name query only
136  bool findEnclosingFunction(uint64_t vma, std::string &fnName);
137 
138  virtual bool parse(const std::set<std::string> &directorySet, const char *pathname) = 0;
139 
140  // invoke the coalesce method to collapse a pair of symbols at the same
141  // address into one. for n symbols at the same address, there will be
142  // n - 1 callse to coalesce.
143  void coalesce(SimpleSymbolsCoalesceCallback coalesce);
144 
145  uint64_t count();
146 
147  void dump();
148 
149 private:
150  void sort();
151 
153 };
154 
155 
157 public:
158  virtual bool match(const char *pathname) = 0;
159  virtual SimpleSymbols *create() = 0;
160 
161  virtual void id(uint _id) = 0;
162  virtual uint id() = 0;
163 
164  virtual void fileId(uint _id) = 0;
165  virtual uint fileId() = 0;
166 
167  virtual const char*unified_name() = 0;
168 };
169 
170 #endif
SimpleSymbolBinding
int find(char s1[], char s2[])
Definition: CStrUtil.cpp:177
SimpleSymbol(uint64_t __addr, SimpleSymbolKind __kind, SimpleSymbolBinding __binding, const char *__name)
uint64_t _addr
struct SimpleSymbolsRepr * R
void setKind(SimpleSymbolKind __kind)
SimpleSymbolKind _kind
uint64_t addr() const
void() SimpleSymbolsCoalesceCallback(SimpleSymbol *left, const SimpleSymbol *right)
unsigned int uint
Definition: uint.h:124
std::string _name
SimpleSymbolBinding binding() const
const std::string & name() const
void setName(std::string __name)
virtual ~SimpleSymbols()
SimpleSymbolKind kind() const
SimpleSymbolsCoalesceCallback chooseHighestBinding
SimpleSymbolKind
SimpleSymbolBinding _binding
void setBinding(SimpleSymbolBinding __binding)