1 //===-- DWARFAbbreviationDeclaration.h --------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H 10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H 11 12 #include "DWARFAttribute.h" 13 #include "DWARFDefines.h" 14 #include "SymbolFileDWARF.h" 15 #include "llvm/Support/Error.h" 16 17 class DWARFAbbreviationDeclaration { 18 public: 19 enum { InvalidCode = 0 }; 20 DWARFAbbreviationDeclaration(); 21 22 // For hand crafting an abbreviation declaration 23 DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children); 24 Code()25 dw_uleb128_t Code() const { return m_code; } SetCode(dw_uleb128_t code)26 void SetCode(dw_uleb128_t code) { m_code = code; } Tag()27 dw_tag_t Tag() const { return m_tag; } HasChildren()28 bool HasChildren() const { return m_has_children; } NumAttributes()29 size_t NumAttributes() const { return m_attributes.size(); } GetFormByIndex(uint32_t idx)30 dw_form_t GetFormByIndex(uint32_t idx) const { 31 return m_attributes.size() > idx ? m_attributes[idx].get_form() : 0; 32 } 33 34 // idx is assumed to be valid when calling GetAttrAndFormByIndex() GetAttrAndFormValueByIndex(uint32_t idx,dw_attr_t & attr,DWARFFormValue & form_value)35 void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t &attr, 36 DWARFFormValue &form_value) const { 37 m_attributes[idx].get(attr, form_value.FormRef(), form_value.ValueRef()); 38 } GetFormByIndexUnchecked(uint32_t idx)39 dw_form_t GetFormByIndexUnchecked(uint32_t idx) const { 40 return m_attributes[idx].get_form(); 41 } 42 uint32_t FindAttributeIndex(dw_attr_t attr) const; 43 44 /// Extract one abbreviation declaration and all of its associated attributes. 45 /// Possible return values: 46 /// DWARFEnumState::Complete - the extraction completed successfully. This 47 /// was the last abbrev decl in a sequence, and the user should not call 48 /// this function again. 49 /// DWARFEnumState::MoreItems - the extraction completed successfully. The 50 /// user should call this function again to retrieve the next decl. 51 /// llvm::Error - A parsing error occurred. The debug info is malformed. 52 llvm::Expected<lldb_private::DWARFEnumState> 53 extract(const lldb_private::DWARFDataExtractor &data, 54 lldb::offset_t *offset_ptr); 55 bool IsValid(); 56 bool operator==(const DWARFAbbreviationDeclaration &rhs) const; 57 58 protected: 59 dw_uleb128_t m_code; 60 dw_tag_t m_tag; 61 uint8_t m_has_children; 62 DWARFAttribute::collection m_attributes; 63 }; 64 65 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H 66