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 "DWARFDebugInfo.h"
12 #include "DWARFCompileUnit.h"
14 DWARFAttributes::DWARFAttributes() :
19 DWARFAttributes::~DWARFAttributes()
25 DWARFAttributes::FindAttributeIndex(dw_attr_t attr) const
27 collection::const_iterator end = m_infos.end();
28 collection::const_iterator beg = m_infos.begin();
29 collection::const_iterator pos;
30 for (pos = beg; pos != end; ++pos)
32 if (pos->attr.get_attr() == attr)
33 return std::distance(beg, pos);
39 DWARFAttributes::Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form)
41 AttributeValue attr_value = { cu, attr_die_offset, { attr, form } };
42 m_infos.push_back(attr_value);
46 DWARFAttributes::ContainsAttribute(dw_attr_t attr) const
48 return FindAttributeIndex(attr) != UINT32_MAX;
52 DWARFAttributes::RemoveAttribute(dw_attr_t attr)
54 uint32_t attr_index = FindAttributeIndex(attr);
55 if (attr_index != UINT32_MAX)
57 m_infos.erase(m_infos.begin() + attr_index);
64 DWARFAttributes::ExtractFormValueAtIndex (uint32_t i, DWARFFormValue &form_value) const
66 const DWARFCompileUnit *cu = CompileUnitAtIndex(i);
67 form_value.SetCompileUnit(cu);
68 form_value.SetForm(FormAtIndex(i));
69 lldb::offset_t offset = DIEOffsetAtIndex(i);
70 return form_value.ExtractValue(cu->GetSymbolFileDWARF()->get_debug_info_data(), &offset);
74 DWARFAttributes::FormValueAsUnsigned (dw_attr_t attr, uint64_t fail_value) const
76 const uint32_t attr_idx = FindAttributeIndex (attr);
77 if (attr_idx != UINT32_MAX)
78 return FormValueAsUnsignedAtIndex (attr_idx, fail_value);
83 DWARFAttributes::FormValueAsUnsignedAtIndex(uint32_t i, uint64_t fail_value) const
85 DWARFFormValue form_value;
86 if (ExtractFormValueAtIndex(i, form_value))
87 return form_value.Reference();