DWARFAbbreviationDeclaration.cpp revision 280031
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 16using namespace lldb_private; 17 18DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() : 19 m_code (InvalidCode), 20 m_tag (0), 21 m_has_children (0), 22 m_attributes() 23{ 24} 25 26DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children) : 27 m_code (InvalidCode), 28 m_tag (tag), 29 m_has_children (has_children), 30 m_attributes() 31{ 32} 33 34bool 35DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor& data, lldb::offset_t* offset_ptr) 36{ 37 return Extract(data, offset_ptr, data.GetULEB128(offset_ptr)); 38} 39 40bool 41DWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor& data, lldb::offset_t *offset_ptr, dw_uleb128_t code) 42{ 43 m_code = code; 44 m_attributes.clear(); 45 if (m_code) 46 { 47 m_tag = data.GetULEB128(offset_ptr); 48 m_has_children = data.GetU8(offset_ptr); 49 50 while (data.ValidOffset(*offset_ptr)) 51 { 52 dw_attr_t attr = data.GetULEB128(offset_ptr); 53 dw_form_t form = data.GetULEB128(offset_ptr); 54 55 if (attr && form) 56 m_attributes.push_back(DWARFAttribute(attr, form)); 57 else 58 break; 59 } 60 61 return m_tag != 0; 62 } 63 else 64 { 65 m_tag = 0; 66 m_has_children = 0; 67 } 68 69 return false; 70} 71 72 73void 74DWARFAbbreviationDeclaration::Dump(Stream *s) const 75{ 76 s->Printf("Debug Abbreviation Declaration: code = 0x%4.4x, tag = %s, has_children = %s\n", m_code, DW_TAG_value_to_name(m_tag), DW_CHILDREN_value_to_name(m_has_children)); 77 78 DWARFAttribute::const_iterator pos; 79 80 for (pos = m_attributes.begin(); pos != m_attributes.end(); ++pos) 81 s->Printf(" attr = %s, form = %s\n", DW_AT_value_to_name(pos->get_attr()), DW_FORM_value_to_name(pos->get_form())); 82 83 s->Printf("\n"); 84} 85 86 87 88bool 89DWARFAbbreviationDeclaration::IsValid() 90{ 91 return m_code != 0 && m_tag != 0; 92} 93 94 95 96uint32_t 97DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const 98{ 99 uint32_t i; 100 const uint32_t kNumAttributes = m_attributes.size(); 101 for (i = 0; i < kNumAttributes; ++i) 102 { 103 if (m_attributes[i].get_attr() == attr) 104 return i; 105 } 106 return DW_INVALID_INDEX; 107} 108 109 110bool 111DWARFAbbreviationDeclaration::operator == (const DWARFAbbreviationDeclaration& rhs) const 112{ 113 return Tag() == rhs.Tag() 114 && HasChildren() == rhs.HasChildren() 115 && Attributes() == rhs.Attributes(); 116} 117 118