]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / Plugins / SymbolFile / DWARF / DWARFAbbreviationDeclaration.cpp
1 //===-- DWARFAbbreviationDeclaration.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 "DWARFAbbreviationDeclaration.h"
11
12 #include "lldb/Core/dwarf.h"
13
14 #include "DWARFFormValue.h"
15
16 using namespace lldb_private;
17
18 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration()
19     : m_code(InvalidCode), m_tag(0), m_has_children(0), m_attributes() {}
20
21 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag,
22                                                            uint8_t has_children)
23     : m_code(InvalidCode), m_tag(tag), m_has_children(has_children),
24       m_attributes() {}
25
26 bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor &data,
27                                            lldb::offset_t *offset_ptr) {
28   return Extract(data, offset_ptr, data.GetULEB128(offset_ptr));
29 }
30
31 bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor &data,
32                                            lldb::offset_t *offset_ptr,
33                                            dw_uleb128_t code) {
34   m_code = code;
35   m_attributes.clear();
36   if (m_code) {
37     m_tag = data.GetULEB128(offset_ptr);
38     m_has_children = data.GetU8(offset_ptr);
39
40     while (data.ValidOffset(*offset_ptr)) {
41       dw_attr_t attr = data.GetULEB128(offset_ptr);
42       dw_form_t form = data.GetULEB128(offset_ptr);
43
44       if (attr && form)
45         m_attributes.push_back(DWARFAttribute(attr, form));
46       else
47         break;
48     }
49
50     return m_tag != 0;
51   } else {
52     m_tag = 0;
53     m_has_children = 0;
54   }
55
56   return false;
57 }
58
59 void DWARFAbbreviationDeclaration::Dump(Stream *s) const {
60   s->Printf("Debug Abbreviation Declaration: code = 0x%4.4x, tag = %s, "
61             "has_children = %s\n",
62             m_code, DW_TAG_value_to_name(m_tag),
63             DW_CHILDREN_value_to_name(m_has_children));
64
65   DWARFAttribute::const_iterator pos;
66
67   for (pos = m_attributes.begin(); pos != m_attributes.end(); ++pos)
68     s->Printf("        attr = %s, form = %s\n",
69               DW_AT_value_to_name(pos->get_attr()),
70               DW_FORM_value_to_name(pos->get_form()));
71
72   s->Printf("\n");
73 }
74
75 bool DWARFAbbreviationDeclaration::IsValid() {
76   return m_code != 0 && m_tag != 0;
77 }
78
79 uint32_t
80 DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const {
81   uint32_t i;
82   const uint32_t kNumAttributes = m_attributes.size();
83   for (i = 0; i < kNumAttributes; ++i) {
84     if (m_attributes[i].get_attr() == attr)
85       return i;
86   }
87   return DW_INVALID_INDEX;
88 }
89
90 bool DWARFAbbreviationDeclaration::
91 operator==(const DWARFAbbreviationDeclaration &rhs) const {
92   return Tag() == rhs.Tag() && HasChildren() == rhs.HasChildren() &&
93          Attributes() == rhs.Attributes();
94 }