gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 namespace loader
41 {
42 
44 
45 void
47 {
48  addrMap.clear();
49  nameMap.clear();
50  symbols.clear();
51 }
52 
53 bool
55 {
56  if (symbol.name.empty())
57  return false;
58 
59  int idx = symbols.size();
60 
61  if (!nameMap.insert({ symbol.name, idx }).second)
62  return false;
63 
64  // There can be multiple symbols for the same address, so always
65  // update the addrTable multimap when we see a new symbol name.
66  addrMap.insert({ symbol.address, idx });
67 
68  symbols.emplace_back(symbol);
69 
70  return true;
71 }
72 
73 bool
75 {
76  // Check if any symbol in other already exists in our table.
77  NameMap intersection;
78  std::set_intersection(other.nameMap.begin(), other.nameMap.end(),
79  nameMap.begin(), nameMap.end(),
80  std::inserter(intersection, intersection.begin()),
81  nameMap.value_comp());
82  if (!intersection.empty())
83  return false;
84 
85  for (const Symbol &symbol: other)
86  insert(symbol);
87 
88  return true;
89 }
90 
91 void
92 SymbolTable::serialize(const std::string &base, CheckpointOut &cp) const
93 {
94  paramOut(cp, base + ".size", symbols.size());
95 
96  int i = 0;
97  for (auto &symbol: symbols) {
98  paramOut(cp, csprintf("%s.addr_%d", base, i), symbol.address);
99  paramOut(cp, csprintf("%s.symbol_%d", base, i), symbol.name);
100  paramOut(cp, csprintf("%s.binding_%d", base, i), (int)symbol.binding);
101  i++;
102  }
103 }
104 
105 void
107  Symbol::Binding default_binding)
108 {
109  clear();
110  int size;
111  paramIn(cp, base + ".size", size);
112  for (int i = 0; i < size; ++i) {
113  Addr address;
114  std::string name;
115  Symbol::Binding binding = default_binding;
116 
117  paramIn(cp, csprintf("%s.addr_%d", base, i), address);
118  paramIn(cp, csprintf("%s.symbol_%d", base, i), name);
119  if (!optParamIn(cp, csprintf("%s.binding_%d", base, i), binding))
120  binding = default_binding;
121  insert({binding, name, address});
122  }
123 }
124 
125 } // namespace loader
126 } // namespace gem5
gem5::loader::Symbol::Binding
Binding
Definition: symtab.hh:52
gem5::loader::Symbol::name
std::string name
Definition: symtab.hh:60
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:106
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::loader::SymbolTable
Definition: symtab.hh:64
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:67
gem5::loader::SymbolTable::addrMap
AddrMap addrMap
Definition: symtab.hh:78
gem5::loader::SymbolTable::nameMap
NameMap nameMap
Definition: symtab.hh:79
str.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
name
const std::string & name()
Definition: trace.cc:48
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:54
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:75
gem5::loader::Symbol
Definition: symtab.hh:50
gem5::loader::Symbol::address
Addr address
Definition: symtab.hh:61
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:43
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::loader::SymbolTable::clear
void clear()
Clears the table.
Definition: symtab.cc:46
gem5::loader::SymbolTable::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize the table's contents.
Definition: symtab.cc:92
gem5::loader::SymbolTable::symbols
SymbolVector symbols
Definition: symtab.hh:77

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17