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