comparison lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
comparison
equal deleted inserted replaced
146:3fc4d5c3e21e 148:63bd29f05246
1 //===- DWARFAbbreviationDeclaration.cpp -----------------------------------===// 1 //===- DWARFAbbreviationDeclaration.cpp -----------------------------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // 4 // See https://llvm.org/LICENSE.txt for license information.
5 // This file is distributed under the University of Illinois Open Source 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // License. See LICENSE.TXT for details.
7 // 6 //
8 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
9 8
10 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h" 9 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
11 10
14 #include "llvm/BinaryFormat/Dwarf.h" 13 #include "llvm/BinaryFormat/Dwarf.h"
15 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" 14 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
16 #include "llvm/DebugInfo/DWARF/DWARFUnit.h" 15 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
17 #include "llvm/Support/DataExtractor.h" 16 #include "llvm/Support/DataExtractor.h"
18 #include "llvm/Support/Format.h" 17 #include "llvm/Support/Format.h"
18 #include "llvm/Support/FormatVariadic.h"
19 #include "llvm/Support/raw_ostream.h" 19 #include "llvm/Support/raw_ostream.h"
20 #include <cstddef> 20 #include <cstddef>
21 #include <cstdint> 21 #include <cstdint>
22 22
23 using namespace llvm; 23 using namespace llvm;
35 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() { 35 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
36 clear(); 36 clear();
37 } 37 }
38 38
39 bool 39 bool
40 DWARFAbbreviationDeclaration::extract(DataExtractor Data, 40 DWARFAbbreviationDeclaration::extract(DataExtractor Data,
41 uint32_t* OffsetPtr) { 41 uint64_t* OffsetPtr) {
42 clear(); 42 clear();
43 const uint32_t Offset = *OffsetPtr; 43 const uint64_t Offset = *OffsetPtr;
44 Code = Data.getULEB128(OffsetPtr); 44 Code = Data.getULEB128(OffsetPtr);
45 if (Code == 0) { 45 if (Code == 0) {
46 return false; 46 return false;
47 } 47 }
48 CodeByteSize = *OffsetPtr - Offset; 48 CodeByteSize = *OffsetPtr - Offset;
94 break; 94 break;
95 95
96 default: 96 default:
97 // The form has a byte size that doesn't depend on Params. 97 // The form has a byte size that doesn't depend on Params.
98 // If it's a fixed size, keep track of it. 98 // If it's a fixed size, keep track of it.
99 if ((ByteSize = 99 if ((ByteSize = dwarf::getFixedFormByteSize(F, dwarf::FormParams()))) {
100 DWARFFormValue::getFixedByteSize(F, DWARFFormParams()))) {
101 if (FixedAttributeSize) 100 if (FixedAttributeSize)
102 FixedAttributeSize->NumBytes += *ByteSize; 101 FixedAttributeSize->NumBytes += *ByteSize;
103 break; 102 break;
104 } 103 }
105 // Indicate we no longer have a fixed byte size for this 104 // Indicate we no longer have a fixed byte size for this
125 } 124 }
126 return true; 125 return true;
127 } 126 }
128 127
129 void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { 128 void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
130 auto tagString = TagString(getTag());
131 OS << '[' << getCode() << "] "; 129 OS << '[' << getCode() << "] ";
132 if (!tagString.empty()) 130 OS << formatv("{0}", getTag());
133 OS << tagString;
134 else
135 OS << format("DW_TAG_Unknown_%x", getTag());
136 OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n'; 131 OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
137 for (const AttributeSpec &Spec : AttributeSpecs) { 132 for (const AttributeSpec &Spec : AttributeSpecs) {
138 OS << '\t'; 133 OS << formatv("\t{0}\t{1}", Spec.Attr, Spec.Form);
139 auto attrString = AttributeString(Spec.Attr);
140 if (!attrString.empty())
141 OS << attrString;
142 else
143 OS << format("DW_AT_Unknown_%x", Spec.Attr);
144 OS << '\t';
145 auto formString = FormEncodingString(Spec.Form);
146 if (!formString.empty())
147 OS << formString;
148 else
149 OS << format("DW_FORM_Unknown_%x", Spec.Form);
150 if (Spec.isImplicitConst()) 134 if (Spec.isImplicitConst())
151 OS << '\t' << Spec.getImplicitConstValue(); 135 OS << '\t' << Spec.getImplicitConstValue();
152 OS << '\n'; 136 OS << '\n';
153 } 137 }
154 OS << '\n'; 138 OS << '\n';
162 } 146 }
163 return None; 147 return None;
164 } 148 }
165 149
166 Optional<DWARFFormValue> DWARFAbbreviationDeclaration::getAttributeValue( 150 Optional<DWARFFormValue> DWARFAbbreviationDeclaration::getAttributeValue(
167 const uint32_t DIEOffset, const dwarf::Attribute Attr, 151 const uint64_t DIEOffset, const dwarf::Attribute Attr,
168 const DWARFUnit &U) const { 152 const DWARFUnit &U) const {
169 Optional<uint32_t> MatchAttrIndex = findAttributeIndex(Attr); 153 Optional<uint32_t> MatchAttrIndex = findAttributeIndex(Attr);
170 if (!MatchAttrIndex) 154 if (!MatchAttrIndex)
171 return None; 155 return None;
172 156
173 auto DebugInfoData = U.getDebugInfoExtractor(); 157 auto DebugInfoData = U.getDebugInfoExtractor();
174 158
175 // Add the byte size of ULEB that for the abbrev Code so we can start 159 // Add the byte size of ULEB that for the abbrev Code so we can start
176 // skipping the attribute data. 160 // skipping the attribute data.
177 uint32_t Offset = DIEOffset + CodeByteSize; 161 uint64_t Offset = DIEOffset + CodeByteSize;
178 uint32_t AttrIndex = 0; 162 uint32_t AttrIndex = 0;
179 for (const auto &Spec : AttributeSpecs) { 163 for (const auto &Spec : AttributeSpecs) {
180 if (*MatchAttrIndex == AttrIndex) { 164 if (*MatchAttrIndex == AttrIndex) {
181 // We have arrived at the attribute to extract, extract if from Offset. 165 // We have arrived at the attribute to extract, extract if from Offset.
166 if (Spec.isImplicitConst())
167 return DWARFFormValue::createFromSValue(Spec.Form,
168 Spec.getImplicitConstValue());
169
182 DWARFFormValue FormValue(Spec.Form); 170 DWARFFormValue FormValue(Spec.Form);
183 if (Spec.isImplicitConst()) {
184 FormValue.setSValue(Spec.getImplicitConstValue());
185 return FormValue;
186 }
187 if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U)) 171 if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U))
188 return FormValue; 172 return FormValue;
189 } 173 }
190 // March Offset along until we get to the attribute we want. 174 // March Offset along until we get to the attribute we want.
191 if (auto FixedSize = Spec.getByteSize(U)) 175 if (auto FixedSize = Spec.getByteSize(U))
215 if (isImplicitConst()) 199 if (isImplicitConst())
216 return 0; 200 return 0;
217 if (ByteSize.HasByteSize) 201 if (ByteSize.HasByteSize)
218 return ByteSize.ByteSize; 202 return ByteSize.ByteSize;
219 Optional<int64_t> S; 203 Optional<int64_t> S;
220 auto FixedByteSize = 204 auto FixedByteSize = dwarf::getFixedFormByteSize(Form, U.getFormParams());
221 DWARFFormValue::getFixedByteSize(Form, U.getFormParams());
222 if (FixedByteSize) 205 if (FixedByteSize)
223 S = *FixedByteSize; 206 S = *FixedByteSize;
224 return S; 207 return S;
225 } 208 }
226 209