OpenASIP 2.2
Loading...
Searching...
No Matches
DumpTPEF.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file DumpTPEF.cc
26 *
27 * Program for outputting TPEF hierarchy in textual format.
28 *
29 * @author Mikael Lepist� 2005 (tmlepist-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <ostream>
34
35#include "Exception.hh"
36#include "CmdLineOptions.hh"
37#include "BinaryReader.hh"
38#include "BinaryStream.hh"
39#include "Binary.hh"
40#include "TPEFDumper.hh"
41#include "tce_config.h"
42
44using TPEF::Binary;
46
47#if 0
48 Those flags that dumptpef support are marked with asterisk.
49
50 objdump
51 [-a|---archive-headers]
52 [-b bfdname| ---target=bfdname]
53 [-C|---demangle[= style] ]
54 [-d|---disassemble]
55 [-D|---disassemble-all]
56 [-z|---disassemble-zeroes]
57 [-EB|-EL| ---endian={big | little }]
58(*)[-f|---file-headers]
59 [---file-start-context]
60 [-g|---debugging]
61(*)[-h|---section-headers| ---headers] NOTE: -h is replaced with -s
62 [-i|---info]
63(*)[-j section| ---section=section]
64 [-l|---line-numbers]
65 [-S|---source]
66 [-m machine| ---architecture=machine]
67 [-M options| ---disassembler-options=options]
68 [-p|---private-headers]
69(*)[-r|---reloc]
70 [-R|---dynamic-reloc]
71 [-s|---full-contents]
72 [-G|---stabs]
73(*)[-t|---syms]
74 [-T|---dynamic-syms]
75 [-x|---all-headers]
76 [-w|---wide]
77 [---start-address= address]
78 [---stop-address= address]
79 [---prefix-addresses]
80 [--[no-]show-raw-insn]
81 [---adjust-vma= offset]
82(*)[-V|---version]
83(*)[-H|---help]
84 objfile...
85#endif
86
87/**
88 * Commandline options.
89 */
91public:
93 CmdLineOptions("Usage: dumptpef [options] tpeffile") {
94
95 BoolCmdLineOptionParser* fileHeadersFlag =
97 "file-headers", "Print file headers.", "f");
98 addOption(fileHeadersFlag);
99
100 // NOTE: -h was reserved for help
101 BoolCmdLineOptionParser* sectionHeadersFlag =
103 "section-headers", "Print section headers.", "s");
104 addOption(sectionHeadersFlag);
105
108 "section",
109 "Print elements of section by section index.", "j");
110 addOption(sectionId);
111
112 BoolCmdLineOptionParser* relocTablesFlag =
114 "reloc", "Print relocation tables.", "r");
115 addOption(relocTablesFlag);
116
117 BoolCmdLineOptionParser* symbolTablesFlag =
118 new BoolCmdLineOptionParser("syms", "Print symbol tables.", "t");
119 addOption(symbolTablesFlag);
120
121 BoolCmdLineOptionParser* memoryInfoFlag =
123 "mem", "Print information about memory usage of reserved sections.", "m");
124 addOption(memoryInfoFlag);
125
126 BoolCmdLineOptionParser* logicalInfoFlag =
128 "logical", "Print only logical information. "
129 "Can be used for checking if two files contains same program "
130 "and data and connections even if it's in different order in "
131 "tpef file.",
132 "l");
133 addOption(logicalInfoFlag);
134 }
135
137 return findOption("file-headers")->isDefined();
138 }
139
141 return findOption("section-headers")->isDefined();
142 }
143
145 return findOption("syms")->isDefined();
146 }
147
149 return findOption("reloc")->isDefined();
150 }
151
153 return findOption("mem")->isDefined();
154 }
155
157 return findOption("logical")->isDefined();
158 }
159
161 return findOption("section")->listSize();
162 }
163
164 int sectionId(int index) {
165 return findOption("section")->integer(index);
166 }
167
168 void printVersion() const {
169 std::cout << "dumptpef - TPEF Dumper "
171 << std::endl;
172 }
173};
174
175
176/**
177 * Calls TPEFDumper with parameters given in commandline.
178 */
179int main(int argc, char* argv[]) {
180
182
183 try {
184 options.parse(argv, argc);
185 } catch (ParserStopRequest const&) {
186 return 0;
187 } catch (IllegalCommandLine const& e) {
188 std::cerr << "Illegal command line parameters: "
189 << e.errorMessage() << std::endl;
190
192 return 0;
193 }
194
195 if (options.numberOfArguments() != 1) {
196 std::cerr << "Error: Must give input binary file.\n\n";
198 return 0;
199 }
200
201 BinaryStream stream(options.argument(1));
202
203 Binary* tpef = NULL;
204 try {
205 tpef = BinaryReader::readBinary(stream);
206 } catch (UnresolvedReference& e) {
207 std::cerr
208 << "Misread the input file: " << options.argument(1) << std::endl
209 << "error: " << e.errorMessage() << std::endl;
210 return 0;
211 } catch (const Exception& e) {
212 std::cerr
213 << "Can't read input file: " << options.argument(1) << std::endl
214 << "error: " << e.errorMessage() << std::endl;
215 return 0;
216 }
217
218 TPEFDumper dumper(*tpef, std::cout);
219
220 dumper.setOnlyLogical(options.onlyLogicalInfo());
221
222 if (options.printFileHeaders()) {
223 dumper.fileHeaders();
224 }
225
226 if (options.printSectionHeaders()) {
227 dumper.sectionHeaders();
228 }
229
230 if (options.printMemoryInfo()) {
231 dumper.memoryInfo();
232 }
233
234 if (options.printSymbols()) {
235 dumper.symbolTables();
236 }
237
238 if (options.printRelocations()) {
239 dumper.relocationTables();
240 }
241
242 for (int i = 1; i < options.sectionIdCount() + 1; i++) {
243 dumper.section(options.sectionId(i));
244 }
245
246 delete tpef;
247
248 return 0;
249}
int main(int argc, char *argv[])
Definition DumpTPEF.cc:179
TTAMachine::Machine * machine
the architecture definition of the estimated processor
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
static RegisterPass< MachineDCE > R("machinedce","Symbol string based machine DCE for removing not used emulation functions", false, true)
static std::string TCEVersionString()
void parse(char *argv[], int argc)
virtual std::string argument(int index) const
virtual int numberOfArguments() const
int sectionId(int index)
Definition DumpTPEF.cc:164
void printVersion() const
Definition DumpTPEF.cc:168
std::string errorMessage() const
Definition Exception.cc:123
virtual void printHelp() const
void section(Word sectionIndex)
void fileHeaders()
void sectionHeaders()
void symbolTables()
void setOnlyLogical(bool flag)
void relocationTables()
void memoryInfo()
static Binary * readBinary(BinaryStream &stream)