]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp
MFV r301238:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFAttribute.cpp
1 //===-- DWARFAttribute.cpp --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "DWARFAttribute.h"
11 #include "DWARFDebugInfo.h"
12 #include "DWARFCompileUnit.h"
13
14 DWARFAttributes::DWARFAttributes() :
15     m_infos()
16 {
17 }
18
19 DWARFAttributes::~DWARFAttributes()
20 {
21 }
22
23
24 uint32_t
25 DWARFAttributes::FindAttributeIndex(dw_attr_t attr) const
26 {
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)
31     {
32         if (pos->attr.get_attr() == attr)
33             return std::distance(beg, pos);
34     }
35     return UINT32_MAX;
36 }
37
38 void
39 DWARFAttributes::Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form)
40 {
41     AttributeValue attr_value = { cu, attr_die_offset, { attr, form } };
42     m_infos.push_back(attr_value);
43 }
44
45 bool
46 DWARFAttributes::ContainsAttribute(dw_attr_t attr) const
47 {
48     return FindAttributeIndex(attr) != UINT32_MAX;
49 }
50
51 bool
52 DWARFAttributes::RemoveAttribute(dw_attr_t attr)
53 {
54     uint32_t attr_index = FindAttributeIndex(attr);
55     if (attr_index != UINT32_MAX)
56     {
57         m_infos.erase(m_infos.begin() + attr_index);
58         return true;
59     }
60     return false;
61 }
62
63 bool
64 DWARFAttributes::ExtractFormValueAtIndex (uint32_t i, DWARFFormValue &form_value) const
65 {
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);
71 }
72
73 uint64_t
74 DWARFAttributes::FormValueAsUnsigned (dw_attr_t attr, uint64_t fail_value) const
75 {
76     const uint32_t attr_idx = FindAttributeIndex (attr);
77     if (attr_idx != UINT32_MAX)
78         return FormValueAsUnsignedAtIndex (attr_idx, fail_value);
79     return fail_value;
80 }
81
82 uint64_t
83 DWARFAttributes::FormValueAsUnsignedAtIndex(uint32_t i, uint64_t fail_value) const
84 {
85     DWARFFormValue form_value;
86     if (ExtractFormValueAtIndex(i, form_value))
87         return form_value.Reference();
88     return fail_value;
89 }
90