gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
nmtest.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 <iostream>
30 #include <string>
31 #include <vector>
32 
34 #include "base/loader/symtab.hh"
35 #include "base/logging.hh"
36 #include "base/str.hh"
37 
38 using namespace std;
39 
40 int
41 main(int argc, char *argv[])
42 {
43  if (argc != 2 && argc != 3)
44  panic("usage: %s <filename> <symbol>\n", argv[0]);
45 
46  auto *obj = Loader::createObjectFile(argv[1]);
47  if (!obj)
48  panic("file not found\n");
49 
50  Loader::SymbolTable symtab;
51  obj->loadGlobalSymbols(&symtab);
52  obj->loadLocalSymbols(&symtab);
53 
54  if (argc == 2) {
55  for (const Loader::Symbol &symbol: symtab)
56  cprintf("%#x %s\n", symbol.address, symbol.name);
57  } else {
58  string symbol = argv[2];
59  Addr address;
60 
61  if (symbol[0] == '0' && symbol[1] == 'x') {
63  if (to_number(symbol, address) &&
64  (it = symtab.find(address)) != symtab.end()) {
65  cprintf("address = %#x, symbol = %s\n", address, it->name);
66  } else {
67  cprintf("address = %#x was not found\n", address);
68  }
69  } else {
70  auto it = symtab.find(symbol);
71  if (it != symtab.end())
72  cprintf("symbol = %s address = %#x\n", symbol, it->address);
73  else
74  cprintf("symbol = %s was not found\n", symbol);
75  }
76  }
77 
78  return 0;
79 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Definition: object_file.cc:61
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
const_iterator end() const
Definition: symtab.hh:126
bool to_number(const std::string &value, VecPredRegContainer< NumBits, Packed > &p)
Helper functions used for serialization/de-serialization.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
int main(int argc, char *argv[])
Definition: nmtest.cc:41
SymbolVector::const_iterator const_iterator
Definition: symtab.hh:123
const_iterator find(Addr address) const
Definition: symtab.hh:181
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152

Generated on Mon Jun 8 2020 15:45:16 for gem5 by doxygen 1.8.13