1 //===-- DWARFAbbreviationDeclaration.h --------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_DWARFAbbreviationDeclaration_h_
10 #define liblldb_DWARFAbbreviationDeclaration_h_
12 #include "DWARFAttribute.h"
13 #include "DWARFDefines.h"
14 #include "SymbolFileDWARF.h"
15 #include "llvm/Support/Error.h"
17 class DWARFAbbreviationDeclaration {
19 enum { InvalidCode = 0 };
20 DWARFAbbreviationDeclaration();
22 // For hand crafting an abbreviation declaration
23 DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children);
25 dw_uleb128_t Code() const { return m_code; }
26 void SetCode(dw_uleb128_t code) { m_code = code; }
27 dw_tag_t Tag() const { return m_tag; }
28 bool HasChildren() const { return m_has_children; }
29 size_t NumAttributes() const { return m_attributes.size(); }
30 dw_form_t GetFormByIndex(uint32_t idx) const {
31 return m_attributes.size() > idx ? m_attributes[idx].get_form() : 0;
34 // idx is assumed to be valid when calling GetAttrAndFormByIndex()
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());
39 dw_form_t GetFormByIndexUnchecked(uint32_t idx) const {
40 return m_attributes[idx].get_form();
42 uint32_t FindAttributeIndex(dw_attr_t attr) const;
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);
56 bool operator==(const DWARFAbbreviationDeclaration &rhs) const;
61 uint8_t m_has_children;
62 DWARFAttribute::collection m_attributes;
65 #endif // liblldb_DWARFAbbreviationDeclaration_h_