gem5  v22.1.0.0
symtab.cc
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 
29 #include "base/loader/symtab.hh"
30 
31 #include <fstream>
32 #include <iostream>
33 
34 #include "base/logging.hh"
35 #include "base/str.hh"
36 
37 namespace gem5
38 {
39 
40 GEM5_DEPRECATED_NAMESPACE(Loader, loader);
41 namespace loader
42 {
43 
45 
46 void
48 {
49  addrMap.clear();
50  nameMap.clear();
51  symbols.clear();
52 }
53 
54 bool
56 {
57  if (symbol.name.empty())
58  return false;
59 
60  int idx = symbols.size();
61 
62  if (!nameMap.insert({ symbol.name, idx }).second)
63  return false;
64 
65  // There can be multiple symbols for the same address, so always
66  // update the addrTable multimap when we see a new symbol name.
67  addrMap.insert({ symbol.address, idx });
68 
69  symbols.emplace_back(symbol);
70 
71  return true;
72 }
73 
74 bool
76 {
77  // Check if any symbol in other already exists in our table.
78  NameMap intersection;
79  std::set_intersection(other.nameMap.begin(), other.nameMap.end(),
80  nameMap.begin(), nameMap.end(),
81  std::inserter(intersection, intersection.begin()),
82  nameMap.value_comp());
83  if (!intersection.empty())
84  return false;
85 
86  for (const Symbol &symbol: other)
87  insert(symbol);
88 
89  return true;
90 }
91 
92 void
93 SymbolTable::serialize(const std::string &base, CheckpointOut &cp) const
94 {
95  paramOut(cp, base + ".size", symbols.size());
96 
97  int i = 0;
98  for (auto &symbol: symbols) {
99  paramOut(cp, csprintf("%s.addr_%d", base, i), symbol.address);
100  paramOut(cp, csprintf("%s.symbol_%d", base, i), symbol.name);
101  paramOut(cp, csprintf("%s.binding_%d", base, i), (int)symbol.binding);
102  i++;
103  }
104 }
105 
106 void
108  Symbol::Binding default_binding)
109 {
110  clear();
111  int size;
112  paramIn(cp, base + ".size", size);
113  for (int i = 0; i < size; ++i) {
114  Addr address;
115  std::string name;
116  Symbol::Binding binding = default_binding;
117 
118  paramIn(cp, csprintf("%s.addr_%d", base, i), address);
119  paramIn(cp, csprintf("%s.symbol_%d", base, i), name);
120  if (!optParamIn(cp, csprintf("%s.binding_%d", base, i), binding))
121  binding = default_binding;
122  insert({binding, name, address});
123  }
124 }
125 
126 } // namespace loader
127 } // namespace gem5
std::map< std::string, int > NameMap
Map a symbol name to an index into the symbol vector.
Definition: symtab.hh:76
void clear()
Clears the table.
Definition: symtab.cc:47
SymbolVector symbols
Definition: symtab.hh:78
void unserialize(const std::string &base, CheckpointIn &cp, Symbol::Binding default_binding=Symbol::Binding::Global)
Populate the table by unserializing a checkpoint.
Definition: symtab.cc:107
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize the table's contents.
Definition: symtab.cc:93
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition: symtab.cc:55
bool optParamIn(CheckpointIn &cp, const std::string &name, T &param, bool do_warn=true)
This function is used for restoring optional parameters from the checkpoint.
Definition: serialize.hh:357
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:44
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition: types.cc:40
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition: types.cc:72
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
std::string name
Definition: symtab.hh:61
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1