class DWARFAbbreviationDeclaration {
public:
struct AttributeSpec {
- AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<int64_t> V)
- : Attr(A), Form(F), ByteSizeOrValue(V) {}
+ AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value)
+ : Attr(A), Form(F), Value(Value) {
+ assert(isImplicitConst());
+ }
+ AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<uint8_t> ByteSize)
+ : Attr(A), Form(F) {
+ assert(!isImplicitConst());
+ this->ByteSize.HasByteSize = ByteSize.hasValue();
+ if (this->ByteSize.HasByteSize)
+ this->ByteSize.ByteSize = *ByteSize;
+ }
dwarf::Attribute Attr;
dwarf::Form Form;
+ private:
/// The following field is used for ByteSize for non-implicit_const
/// attributes and as value for implicit_const ones, indicated by
/// Form == DW_FORM_implicit_const.
/// The following cases are distinguished:
- /// * Form != DW_FORM_implicit_const and ByteSizeOrValue has a value:
- /// ByteSizeOrValue contains the fixed size in bytes
- /// for the Form in this object.
- /// * Form != DW_FORM_implicit_const and ByteSizeOrValue is None:
+ /// * Form != DW_FORM_implicit_const and HasByteSize is true:
+ /// ByteSize contains the fixed size in bytes for the Form in this
+ /// object.
+ /// * Form != DW_FORM_implicit_const and HasByteSize is false:
/// byte size of Form either varies according to the DWARFUnit
/// that it is contained in or the value size varies and must be
/// decoded from the debug information in order to determine its size.
/// * Form == DW_FORM_implicit_const:
- /// ByteSizeOrValue contains value for the implicit_const attribute.
- Optional<int64_t> ByteSizeOrValue;
-
+ /// Value contains value for the implicit_const attribute.
+ struct ByteSizeStorage {
+ bool HasByteSize;
+ uint8_t ByteSize;
+ };
+ union {
+ ByteSizeStorage ByteSize;
+ int64_t Value;
+ };
+
+ public:
bool isImplicitConst() const {
return Form == dwarf::DW_FORM_implicit_const;
}
+ int64_t getImplicitConstValue() const {
+ assert(isImplicitConst());
+ return Value;
+ }
+
/// Get the fixed byte size of this Form if possible. This function might
/// use the DWARFUnit to calculate the size of the Form, like for
/// DW_AT_address and DW_AT_ref_addr, so this isn't just an accessor for
auto A = static_cast<Attribute>(Data.getULEB128(OffsetPtr));
auto F = static_cast<Form>(Data.getULEB128(OffsetPtr));
if (A && F) {
- Optional<int64_t> V;
bool IsImplicitConst = (F == DW_FORM_implicit_const);
if (IsImplicitConst) {
- V = Data.getSLEB128(OffsetPtr);
+ int64_t V = Data.getSLEB128(OffsetPtr);
AttributeSpecs.push_back(AttributeSpec(A, F, V));
continue;
}
+ Optional<uint8_t> ByteSize;
// If this abbrevation still has a fixed byte size, then update the
// FixedAttributeSize as needed.
switch (F) {
default:
// The form has a byte size that doesn't depend on Params.
// If it's a fixed size, keep track of it.
- if (auto Size =
- DWARFFormValue::getFixedByteSize(F, DWARFFormParams())) {
- V = *Size;
+ if ((ByteSize =
+ DWARFFormValue::getFixedByteSize(F, DWARFFormParams()))) {
if (FixedAttributeSize)
- FixedAttributeSize->NumBytes += *V;
+ FixedAttributeSize->NumBytes += *ByteSize;
break;
}
// Indicate we no longer have a fixed byte size for this
break;
}
// Record this attribute and its fixed size if it has one.
- AttributeSpecs.push_back(AttributeSpec(A, F, V));
+ AttributeSpecs.push_back(AttributeSpec(A, F, ByteSize));
} else if (A == 0 && F == 0) {
// We successfully reached the end of this abbreviation declaration
// since both attribute and form are zero.
else
OS << format("DW_FORM_Unknown_%x", Spec.Form);
if (Spec.isImplicitConst())
- OS << '\t' << *Spec.ByteSizeOrValue;
+ OS << '\t' << Spec.getImplicitConstValue();
OS << '\n';
}
OS << '\n';
// We have arrived at the attribute to extract, extract if from Offset.
DWARFFormValue FormValue(Spec.Form);
if (Spec.isImplicitConst()) {
- FormValue.setSValue(*Spec.ByteSizeOrValue);
+ FormValue.setSValue(Spec.getImplicitConstValue());
return FormValue;
}
if (FormValue.extractValue(DebugInfoData, &Offset, &U))
const DWARFUnit &U) const {
if (isImplicitConst())
return 0;
- if (ByteSizeOrValue)
- return ByteSizeOrValue;
+ if (ByteSize.HasByteSize)
+ return ByteSize.ByteSize;
Optional<int64_t> S;
auto FixedByteSize =
DWARFFormValue::getFixedByteSize(Form, U.getFormParams());