1 //===-- DWARFAttribute.cpp --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFAttribute.h"
11 #include "DWARFUnit.h"
12 #include "DWARFDebugInfo.h"
14 DWARFAttributes::DWARFAttributes() : m_infos() {}
16 DWARFAttributes::~DWARFAttributes() {}
18 uint32_t DWARFAttributes::FindAttributeIndex(dw_attr_t attr) const {
19 collection::const_iterator end = m_infos.end();
20 collection::const_iterator beg = m_infos.begin();
21 collection::const_iterator pos;
22 for (pos = beg; pos != end; ++pos) {
23 if (pos->attr.get_attr() == attr)
24 return std::distance(beg, pos);
29 void DWARFAttributes::Append(const DWARFUnit *cu, dw_offset_t attr_die_offset,
30 dw_attr_t attr, dw_form_t form) {
31 AttributeValue attr_value = {
32 cu, attr_die_offset, {attr, form, DWARFFormValue::ValueType()}};
33 m_infos.push_back(attr_value);
36 bool DWARFAttributes::ContainsAttribute(dw_attr_t attr) const {
37 return FindAttributeIndex(attr) != UINT32_MAX;
40 bool DWARFAttributes::RemoveAttribute(dw_attr_t attr) {
41 uint32_t attr_index = FindAttributeIndex(attr);
42 if (attr_index != UINT32_MAX) {
43 m_infos.erase(m_infos.begin() + attr_index);
49 bool DWARFAttributes::ExtractFormValueAtIndex(
50 uint32_t i, DWARFFormValue &form_value) const {
51 const DWARFUnit *cu = CompileUnitAtIndex(i);
52 form_value.SetCompileUnit(cu);
53 form_value.SetForm(FormAtIndex(i));
54 lldb::offset_t offset = DIEOffsetAtIndex(i);
55 return form_value.ExtractValue(cu->GetData(), &offset);
58 uint64_t DWARFAttributes::FormValueAsUnsigned(dw_attr_t attr,
59 uint64_t fail_value) const {
60 const uint32_t attr_idx = FindAttributeIndex(attr);
61 if (attr_idx != UINT32_MAX)
62 return FormValueAsUnsignedAtIndex(attr_idx, fail_value);
67 DWARFAttributes::FormValueAsUnsignedAtIndex(uint32_t i,
68 uint64_t fail_value) const {
69 DWARFFormValue form_value;
70 if (ExtractFormValueAtIndex(i, form_value))
71 return form_value.Reference();