OpenASIP 2.2
Loading...
Searching...
No Matches
TPEFDebugSectionReader.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 TPEFDebugSectionReader.cc
26 *
27 * Definition of TPEFDebugSectionReader class.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
35#include "SafePointer.hh"
36#include "Exception.hh"
37#include "ReferenceKey.hh"
38#include "SectionReader.hh"
39#include "TPEFBaseType.hh"
40#include "DebugSection.hh"
41#include "DebugStabElem.hh"
42#include "BinaryStream.hh"
43
44
45namespace TPEF {
46
47using ReferenceManager::SafePointer;
48using ReferenceManager::SectionIndexKey;
49using ReferenceManager::SectionOffsetKey;
50using ReferenceManager::SectionKey;
51
52TPEFDebugSectionReader TPEFDebugSectionReader::proto_;
53
54/**
55 * Constructor.
56 *
57 * Registers itself to SectionReader.
58 */
62
63/**
64 * Destructor.
65 */
68
69/**
70 * Returns the type of section it is meant to read.
71 *
72 * @return The type of section it can read.
73 */
78
79/**
80 * Reads section data from TPEF binary file.
81 *
82 * @param stream Stream to be read from.
83 * @param section Section where the information is to be stored.
84 * @exception UnreachableStream If reading of section fails.
85 * @exception KeyAlreadyExists Key was in use when trying to register object.
86 * @exception EndOfFile If end of file were reached while it shouldn't.
87 * @exception OutOfRange Some of read value were out of range.
88 * @exception WrongSubclass Some class couldn't do what it was asked for.
89 * @exception UnexpectedValue If there was unexpected value when reading.
90 */
91void
93 // size taken by fields common to any type of debug section element
94 const std::size_t BASE_ELEM_SIZE = 10;
95
96 // base classes implementation must be called with these.
97 TPEFSectionReader::readData(stream, section);
98
99 DebugSection* debugSection =
100 dynamic_cast<DebugSection*>(section);
101 assert(debugSection != NULL);
102
103 // check that link section is defined properly
104 assert(header().linkId != 0);
105
106 if (!section->noBits()) {
107 // start of first element
108 SectionOffset currElement = header().bodyOffset;
109
110 while (currElement < header().bodyOffset + header().bodyLength) {
111
112 HalfWord type = stream.readHalfWord();
113 Word stringOffset = stream.readWord();
114 Word size = stream.readWord();
115
116 std::vector<Byte> data;
117
118 for (unsigned i = 0; i < size; i++) {
119 data.push_back(stream.readByte());
120 }
121
122 DebugElement* newElem = NULL;
123
124 switch (static_cast<DebugElement::ElementType>(type)) {
126 newElem = new DebugStabElem(data);
127 break;
128 default:
129 throw UnexpectedValue(
130 __FILE__, __LINE__, __func__,
131 "Unknown debug element type: " +
133 }
134
135 // set name string for element
136 SectionOffsetKey sOffKey(header().linkId, stringOffset);
137 newElem->setDebugString(CREATE_SAFEPOINTER(sOffKey));
138
139 section->addElement(newElem);
140
141 currElement += size + BASE_ELEM_SIZE;
142 stream.setReadPosition(currElement);
143 }
144 }
145}
146
147} // namespace TPEF
#define __func__
#define assert(condition)
static std::string toString(const T &source)
void setReadPosition(unsigned int position)
HalfWord readHalfWord()
void setDebugString(const ReferenceManager::SafePointer *aString)
static void registerSectionReader(const SectionReader *sReader)
virtual void addElement(SectionElement *element)
Definition Section.cc:133
@ ST_DEBUG
Debug section.
Definition Section.hh:73
bool noBits() const
static TPEFDebugSectionReader proto_
Prototype instance of TPEFDebugSectionReader to be registered to SectionReader.
virtual Section::SectionType type() const
virtual void readData(BinaryStream &stream, Section *section) const
virtual void readData(BinaryStream &stream, Section *section) const
static const Header & header()
Word SectionOffset
Type for storing offsets relative to a given base offset value.