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() :
26 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children) :
29 m_has_children (has_children),
35 DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor& data, lldb::offset_t* offset_ptr)
37 return Extract(data, offset_ptr, data.GetULEB128(offset_ptr));
41 DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor& data, lldb::offset_t *offset_ptr, dw_uleb128_t code)
47 m_tag = data.GetULEB128(offset_ptr);
48 m_has_children = data.GetU8(offset_ptr);
50 while (data.ValidOffset(*offset_ptr))
52 dw_attr_t attr = data.GetULEB128(offset_ptr);
53 dw_form_t form = data.GetULEB128(offset_ptr);
56 m_attributes.push_back(DWARFAttribute(attr, form));
74 DWARFAbbreviationDeclaration::Dump(Stream *s) const
76 // *ostrm_ptr << std::setfill(' ') << std::dec << '[' << std::setw(3) << std::right << m_code << ']' << ' ' << std::setw(30) << std::left << DW_TAG_value_to_name(m_tag) << DW_CHILDREN_value_to_name(m_has_children) << std::endl;
78 // DWARFAttribute::const_iterator pos;
80 // for (pos = m_attributes.begin(); pos != m_attributes.end(); ++pos)
81 // *ostrm_ptr << " " << std::setw(29) << std::left << DW_AT_value_to_name(pos->attr()) << ' ' << DW_FORM_value_to_name(pos->form()) << std::endl;
83 // *ostrm_ptr << std::endl;
89 DWARFAbbreviationDeclaration::IsValid()
91 return m_code != 0 && m_tag != 0;
96 DWARFAbbreviationDeclaration::CopyExcludingAddressAttributes(const DWARFAbbreviationDeclaration& abbr_decl, const uint32_t idx)
98 m_code = abbr_decl.Code(); // Invalidate the code since that can't be copied safely.
99 m_tag = abbr_decl.Tag();
100 m_has_children = abbr_decl.HasChildren();
102 const DWARFAttribute::collection& attributes = abbr_decl.Attributes();
103 const uint32_t num_abbr_decl_attributes = attributes.size();
109 for (i = 0; i < num_abbr_decl_attributes; ++i)
111 attributes[i].get(attr, form);
115 case DW_AT_frame_base:
116 // Only add these if they are location expressions (have a single
117 // value) and not location lists (have a lists of location
118 // expressions which are only valid over specific address ranges)
119 if (DWARFFormValue::IsBlockForm(form))
120 m_attributes.push_back(DWARFAttribute(attr, form));
127 // Don't add these attributes
130 // Fall through and add attribute
132 // Add anything that isn't address related
133 m_attributes.push_back(DWARFAttribute(attr, form));
140 DWARFAbbreviationDeclaration::CopyChangingStringToStrp(
141 const DWARFAbbreviationDeclaration& abbr_decl,
142 const DWARFDataExtractor& debug_info_data,
143 dw_offset_t debug_info_offset,
144 const DWARFCompileUnit* cu,
145 const uint32_t strp_min_len
148 m_code = InvalidCode;
149 m_tag = abbr_decl.Tag();
150 m_has_children = abbr_decl.HasChildren();
152 const DWARFAttribute::collection& attributes = abbr_decl.Attributes();
153 const uint32_t num_abbr_decl_attributes = attributes.size();
158 lldb::offset_t offset = debug_info_offset;
160 for (i = 0; i < num_abbr_decl_attributes; ++i)
162 attributes[i].get(attr, form);
163 dw_offset_t attr_offset = offset;
164 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
166 if (form == DW_FORM_string && ((offset - attr_offset) >= strp_min_len))
167 m_attributes.push_back(DWARFAttribute(attr, DW_FORM_strp));
169 m_attributes.push_back(DWARFAttribute(attr, form));
175 DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const
178 const uint32_t kNumAttributes = m_attributes.size();
179 for (i = 0; i < kNumAttributes; ++i)
181 if (m_attributes[i].get_attr() == attr)
184 return DW_INVALID_INDEX;
189 DWARFAbbreviationDeclaration::operator == (const DWARFAbbreviationDeclaration& rhs) const
191 return Tag() == rhs.Tag()
192 && HasChildren() == rhs.HasChildren()
193 && Attributes() == rhs.Attributes();
197 DWARFAbbreviationDeclaration::Append(BinaryStreamBuf& out_buff) const
199 out_buff.Append32_as_ULEB128(Code());
200 out_buff.Append32_as_ULEB128(Tag());
201 out_buff.Append8(HasChildren());
202 const uint32_t kNumAttributes = m_attributes.size();
203 for (uint32_t i = 0; i < kNumAttributes; ++i)
205 out_buff.Append32_as_ULEB128(m_attributes[i].attr());
206 out_buff.Append32_as_ULEB128(m_attributes[i].form());
208 out_buff.Append8(0); // Output a zero for attr (faster than using Append32_as_ULEB128)
209 out_buff.Append8(0); // Output a zero for attr (faster than using Append32_as_ULEB128)