xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1061da546Spatrick //===-- DWARFAbbreviationDeclaration.h --------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
10dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
11061da546Spatrick 
12061da546Spatrick #include "DWARFAttribute.h"
13061da546Spatrick #include "DWARFDefines.h"
14061da546Spatrick #include "SymbolFileDWARF.h"
15061da546Spatrick #include "llvm/Support/Error.h"
16061da546Spatrick 
17061da546Spatrick class DWARFAbbreviationDeclaration {
18061da546Spatrick public:
19061da546Spatrick   enum { InvalidCode = 0 };
20061da546Spatrick   DWARFAbbreviationDeclaration();
21061da546Spatrick 
22061da546Spatrick   // For hand crafting an abbreviation declaration
23061da546Spatrick   DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children);
24061da546Spatrick 
Code()25061da546Spatrick   dw_uleb128_t Code() const { return m_code; }
SetCode(dw_uleb128_t code)26061da546Spatrick   void SetCode(dw_uleb128_t code) { m_code = code; }
Tag()27061da546Spatrick   dw_tag_t Tag() const { return m_tag; }
HasChildren()28061da546Spatrick   bool HasChildren() const { return m_has_children; }
NumAttributes()29061da546Spatrick   size_t NumAttributes() const { return m_attributes.size(); }
GetFormByIndex(uint32_t idx)30061da546Spatrick   dw_form_t GetFormByIndex(uint32_t idx) const {
31061da546Spatrick     return m_attributes.size() > idx ? m_attributes[idx].get_form() : 0;
32061da546Spatrick   }
33061da546Spatrick 
34061da546Spatrick   // idx is assumed to be valid when calling GetAttrAndFormByIndex()
GetAttrAndFormValueByIndex(uint32_t idx,dw_attr_t & attr,DWARFFormValue & form_value)35061da546Spatrick   void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t &attr,
36061da546Spatrick                                   DWARFFormValue &form_value) const {
37061da546Spatrick     m_attributes[idx].get(attr, form_value.FormRef(), form_value.ValueRef());
38061da546Spatrick   }
GetFormByIndexUnchecked(uint32_t idx)39061da546Spatrick   dw_form_t GetFormByIndexUnchecked(uint32_t idx) const {
40061da546Spatrick     return m_attributes[idx].get_form();
41061da546Spatrick   }
42061da546Spatrick   uint32_t FindAttributeIndex(dw_attr_t attr) const;
43061da546Spatrick 
44061da546Spatrick   /// Extract one abbreviation declaration and all of its associated attributes.
45061da546Spatrick   /// Possible return values:
46061da546Spatrick   ///   DWARFEnumState::Complete - the extraction completed successfully.  This
47061da546Spatrick   ///       was the last abbrev decl in a sequence, and the user should not call
48061da546Spatrick   ///       this function again.
49061da546Spatrick   ///   DWARFEnumState::MoreItems - the extraction completed successfully.  The
50061da546Spatrick   ///       user should call this function again to retrieve the next decl.
51061da546Spatrick   ///   llvm::Error - A parsing error occurred.  The debug info is malformed.
52061da546Spatrick   llvm::Expected<lldb_private::DWARFEnumState>
53061da546Spatrick   extract(const lldb_private::DWARFDataExtractor &data,
54061da546Spatrick           lldb::offset_t *offset_ptr);
55061da546Spatrick   bool IsValid();
56061da546Spatrick 
57061da546Spatrick protected:
58*be691f3bSpatrick   dw_uleb128_t m_code = InvalidCode;
59*be691f3bSpatrick   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
60*be691f3bSpatrick   uint8_t m_has_children = 0;
61061da546Spatrick   DWARFAttribute::collection m_attributes;
62061da546Spatrick };
63061da546Spatrick 
64dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
65