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

Generated on Wed Sep 30 2020 14:02:18 for gem5 by doxygen 1.8.17