gem5  v21.1.0.2
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
gem5::loader::Symbol::Binding
Binding
Definition: symtab.hh:53
gem5::loader::Symbol::name
std::string name
Definition: symtab.hh:61
gem5::loader::SymbolTable::unserialize
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
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::loader::SymbolTable
Definition: symtab.hh:65
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::loader::SymbolTable::addrMap
AddrMap addrMap
Definition: symtab.hh:79
gem5::loader::SymbolTable::nameMap
NameMap nameMap
Definition: symtab.hh:80
str.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
name
const std::string & name()
Definition: trace.cc:49
gem5::optParamIn
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
gem5::loader::SymbolTable::insert
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition: symtab.cc:55
gem5::paramOut
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition: types.cc:40
gem5::paramIn
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition: types.cc:72
gem5::loader::SymbolTable::NameMap
std::map< std::string, int > NameMap
Map a symbol name to an index into the symbol vector.
Definition: symtab.hh:76
gem5::loader::Symbol
Definition: symtab.hh:51
gem5::loader::Symbol::address
Addr address
Definition: symtab.hh:62
logging.hh
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
symtab.hh
gem5::loader::debugSymbolTable
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:44
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::loader::SymbolTable::clear
void clear()
Clears the table.
Definition: symtab.cc:47
gem5::loader::SymbolTable::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize the table's contents.
Definition: symtab.cc:93
gem5::loader::SymbolTable::symbols
SymbolVector symbols
Definition: symtab.hh:78

Generated on Tue Sep 21 2021 12:24:57 for gem5 by doxygen 1.8.17