gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
symtab.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Nathan Binkert
29  * Steve Reinhardt
30  */
31 
32 #ifndef __SYMTAB_HH__
33 #define __SYMTAB_HH__
34 
35 #include <iosfwd>
36 #include <map>
37 #include <string>
38 
39 #include "base/types.hh"
40 #include "sim/serialize.hh"
41 
43 {
44  public:
45  typedef std::multimap<Addr, std::string> ATable;
46  typedef std::map<std::string, Addr> STable;
47 
48  private:
51 
52  private:
53  bool
54  upperBound(Addr addr, ATable::const_iterator &iter) const
55  {
56  // find first key *larger* than desired address
57  iter = addrTable.upper_bound(addr);
58 
59  // if very first key is larger, we're out of luck
60  if (iter == addrTable.begin())
61  return false;
62 
63  return true;
64  }
65 
66  public:
68  SymbolTable(const std::string &file) { load(file); }
70 
71  void clear();
72  bool insert(Addr address, std::string symbol);
73  bool load(const std::string &file);
74 
75  const ATable &getAddrTable() const { return addrTable; }
76  const STable &getSymbolTable() const { return symbolTable; }
77 
78  public:
79  void serialize(const std::string &base, CheckpointOut &cp) const;
80  void unserialize(const std::string &base, CheckpointIn &cp);
81 
82  public:
83  bool
84  findSymbol(Addr address, std::string &symbol) const
85  {
86  ATable::const_iterator i = addrTable.find(address);
87  if (i == addrTable.end())
88  return false;
89 
90  // There are potentially multiple symbols that map to the same
91  // address. For simplicity, just return the first one.
92  symbol = (*i).second;
93  return true;
94  }
95 
96  bool
97  findAddress(const std::string &symbol, Addr &address) const
98  {
99  STable::const_iterator i = symbolTable.find(symbol);
100  if (i == symbolTable.end())
101  return false;
102 
103  address = (*i).second;
104  return true;
105  }
106 
115  bool
116  findNearestSymbol(Addr addr, std::string &symbol, Addr &symaddr,
117  Addr &nextaddr) const
118  {
119  ATable::const_iterator i;
120  if (!upperBound(addr, i))
121  return false;
122 
123  nextaddr = i->first;
124  --i;
125  symaddr = i->first;
126  symbol = i->second;
127  return true;
128  }
129 
132  bool
133  findNearestSymbol(Addr addr, std::string &symbol, Addr &symaddr) const
134  {
135  ATable::const_iterator i;
136  if (!upperBound(addr, i))
137  return false;
138 
139  --i;
140  symaddr = i->first;
141  symbol = i->second;
142  return true;
143  }
144 
145 
146  bool
147  findNearestAddr(Addr addr, Addr &symaddr, Addr &nextaddr) const
148  {
149  ATable::const_iterator i;
150  if (!upperBound(addr, i))
151  return false;
152 
153  nextaddr = i->first;
154  --i;
155  symaddr = i->first;
156  return true;
157  }
158 
159  bool
160  findNearestAddr(Addr addr, Addr &symaddr) const
161  {
162  ATable::const_iterator i;
163  if (!upperBound(addr, i))
164  return false;
165 
166  --i;
167  symaddr = i->first;
168  return true;
169  }
170 };
171 
177 
178 #endif // __SYMTAB_HH__
bool findNearestSymbol(Addr addr, std::string &symbol, Addr &symaddr) const
Overload for findNearestSymbol() for callers who don't care about nextaddr.
Definition: symtab.hh:133
Bitfield< 7 > i
Definition: miscregs.hh:1378
const STable & getSymbolTable() const
Definition: symtab.hh:76
bool findNearestAddr(Addr addr, Addr &symaddr) const
Definition: symtab.hh:160
ip6_addr_t addr
Definition: inet.hh:335
bool findAddress(const std::string &symbol, Addr &address) const
Definition: symtab.hh:97
void clear()
Definition: symtab.cc:48
~SymbolTable()
Definition: symtab.hh:69
bool load(const std::string &file)
Definition: symtab.cc:72
STable symbolTable
Definition: symtab.hh:50
void serialize(const std::string &base, CheckpointOut &cp) const
Definition: symtab.cc:113
bool upperBound(Addr addr, ATable::const_iterator &iter) const
Definition: symtab.hh:54
const ATable & getAddrTable() const
Definition: symtab.hh:75
std::map< std::string, Addr > STable
Definition: symtab.hh:46
Bitfield< 51, 12 > base
Definition: pagetable.hh:85
bool insert(Addr address, std::string symbol)
Definition: symtab.cc:55
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
std::multimap< Addr, std::string > ATable
Definition: symtab.hh:45
SymbolTable()
Definition: symtab.hh:67
std::ostream CheckpointOut
Definition: serialize.hh:67
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:45
ATable addrTable
Definition: symtab.hh:49
bool findSymbol(Addr address, std::string &symbol) const
Definition: symtab.hh:84
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: symtab.cc:127
bool findNearestSymbol(Addr addr, std::string &symbol, Addr &symaddr, Addr &nextaddr) const
Find the nearest symbol equal to or less than the supplied address (e.g., the label for the enclosing...
Definition: symtab.hh:116
bool findNearestAddr(Addr addr, Addr &symaddr, Addr &nextaddr) const
Definition: symtab.hh:147
SymbolTable(const std::string &file)
Definition: symtab.hh:68

Generated on Fri Jun 9 2017 13:03:41 for gem5 by doxygen 1.8.6