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"
14 #include "DWARFFormValue.h"
16 using namespace lldb_private;
18 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration()
19 : m_code(InvalidCode), m_tag(0), m_has_children(0), m_attributes() {}
21 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag,
23 : m_code(InvalidCode), m_tag(tag), m_has_children(has_children),
26 bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor &data,
27 lldb::offset_t *offset_ptr) {
28 return Extract(data, offset_ptr, data.GetULEB128(offset_ptr));
31 bool DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor &data,
32 lldb::offset_t *offset_ptr,
37 m_tag = data.GetULEB128(offset_ptr);
38 m_has_children = data.GetU8(offset_ptr);
40 while (data.ValidOffset(*offset_ptr)) {
41 dw_attr_t attr = data.GetULEB128(offset_ptr);
42 dw_form_t form = data.GetULEB128(offset_ptr);
45 m_attributes.push_back(DWARFAttribute(attr, form));
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));
65 DWARFAttribute::const_iterator pos;
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()));
75 bool DWARFAbbreviationDeclaration::IsValid() {
76 return m_code != 0 && m_tag != 0;
80 DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const {
82 const uint32_t kNumAttributes = m_attributes.size();
83 for (i = 0; i < kNumAttributes; ++i) {
84 if (m_attributes[i].get_attr() == attr)
87 return DW_INVALID_INDEX;
90 bool DWARFAbbreviationDeclaration::
91 operator==(const DWARFAbbreviationDeclaration &rhs) const {
92 return Tag() == rhs.Tag() && HasChildren() == rhs.HasChildren() &&
93 Attributes() == rhs.Attributes();