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 "DWARFCompileUnit.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 DWARFCompileUnit *cu,
30 dw_offset_t attr_die_offset, dw_attr_t attr,
32 AttributeValue attr_value = {cu, attr_die_offset, {attr, form}};
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 DWARFCompileUnit *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(
56 cu->GetSymbolFileDWARF()->get_debug_info_data(), &offset);
59 uint64_t DWARFAttributes::FormValueAsUnsigned(dw_attr_t attr,
60 uint64_t fail_value) const {
61 const uint32_t attr_idx = FindAttributeIndex(attr);
62 if (attr_idx != UINT32_MAX)
63 return FormValueAsUnsignedAtIndex(attr_idx, fail_value);
68 DWARFAttributes::FormValueAsUnsignedAtIndex(uint32_t i,
69 uint64_t fail_value) const {
70 DWARFFormValue form_value;
71 if (ExtractFormValueAtIndex(i, form_value))
72 return form_value.Reference();