1 //===-- DWARFAbbreviationDeclaration.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 "DWARFAbbreviationDeclaration.h"
12 #include "lldb/Core/dwarf.h"
13 #include "lldb/Utility/Stream.h"
15 #include "DWARFFormValue.h"
17 using namespace lldb_private;
19 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration()
20 : m_code(InvalidCode), m_tag(0), m_has_children(0), m_attributes() {}
22 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag,
24 : m_code(InvalidCode), m_tag(tag), m_has_children(has_children),
27 bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor &data,
28 lldb::offset_t *offset_ptr) {
29 return Extract(data, offset_ptr, data.GetULEB128(offset_ptr));
32 bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor &data,
33 lldb::offset_t *offset_ptr,
38 m_tag = data.GetULEB128(offset_ptr);
39 m_has_children = data.GetU8(offset_ptr);
41 while (data.ValidOffset(*offset_ptr)) {
42 dw_attr_t attr = data.GetULEB128(offset_ptr);
43 dw_form_t form = data.GetULEB128(offset_ptr);
46 m_attributes.push_back(DWARFAttribute(attr, form));
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));
66 DWARFAttribute::const_iterator pos;
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()));
76 bool DWARFAbbreviationDeclaration::IsValid() {
77 return m_code != 0 && m_tag != 0;
81 DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const {
83 const uint32_t kNumAttributes = m_attributes.size();
84 for (i = 0; i < kNumAttributes; ++i) {
85 if (m_attributes[i].get_attr() == attr)
88 return DW_INVALID_INDEX;
91 bool DWARFAbbreviationDeclaration::
92 operator==(const DWARFAbbreviationDeclaration &rhs) const {
93 return Tag() == rhs.Tag() && HasChildren() == rhs.HasChildren() &&
94 Attributes() == rhs.Attributes();