xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h (revision a7dea1671b87c07d2d266f836bfa8b58efc7c134)
1 //===-- DWARFBaseDIE.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 SymbolFileDWARF_DWARFBaseDIE_h_
10 #define SymbolFileDWARF_DWARFBaseDIE_h_
11 
12 #include "lldb/Core/dwarf.h"
13 #include "lldb/lldb-types.h"
14 
15 class DIERef;
16 class DWARFASTParser;
17 class DWARFAttributes;
18 class DWARFUnit;
19 class DWARFDebugInfoEntry;
20 class DWARFDeclContext;
21 class SymbolFileDWARF;
22 
23 class DWARFBaseDIE {
24 public:
25   DWARFBaseDIE() : m_cu(nullptr), m_die(nullptr) {}
26 
27   DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
28       : m_cu(cu), m_die(die) {}
29 
30   DWARFBaseDIE(const DWARFUnit *cu, DWARFDebugInfoEntry *die)
31       : m_cu(const_cast<DWARFUnit *>(cu)), m_die(die) {}
32 
33   DWARFBaseDIE(DWARFUnit *cu, const DWARFDebugInfoEntry *die)
34       : m_cu(cu), m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
35 
36   DWARFBaseDIE(const DWARFUnit *cu, const DWARFDebugInfoEntry *die)
37       : m_cu(const_cast<DWARFUnit *>(cu)),
38         m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
39 
40   // Tests
41   explicit operator bool() const { return IsValid(); }
42 
43   bool IsValid() const { return m_cu && m_die; }
44 
45   bool HasChildren() const;
46 
47   bool Supports_DW_AT_APPLE_objc_complete_type() const;
48 
49   // Accessors
50   SymbolFileDWARF *GetDWARF() const;
51 
52   DWARFUnit *GetCU() const { return m_cu; }
53 
54   DWARFDebugInfoEntry *GetDIE() const { return m_die; }
55 
56   llvm::Optional<DIERef> GetDIERef() const;
57 
58   lldb_private::TypeSystem *GetTypeSystem() const;
59 
60   DWARFASTParser *GetDWARFParser() const;
61 
62   void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die) {
63     if (cu && die) {
64       m_cu = cu;
65       m_die = die;
66     } else {
67       Clear();
68     }
69   }
70 
71   void Clear() {
72     m_cu = nullptr;
73     m_die = nullptr;
74   }
75 
76   // Get the data that contains the attribute values for this DIE. Support
77   // for .debug_types means that any DIE can have its data either in the
78   // .debug_info or the .debug_types section; this method will return the
79   // correct section data.
80   //
81   // Clients must validate that this object is valid before calling this.
82   const lldb_private::DWARFDataExtractor &GetData() const;
83 
84   // Accessing information about a DIE
85   dw_tag_t Tag() const;
86 
87   const char *GetTagAsCString() const;
88 
89   dw_offset_t GetOffset() const;
90 
91   // Get the LLDB user ID for this DIE. This is often just the DIE offset,
92   // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if
93   // we are doing Darwin DWARF in .o file, or DWARF stand alone debug
94   // info.
95   lldb::user_id_t GetID() const;
96 
97   const char *GetName() const;
98 
99   lldb::LanguageType GetLanguage() const;
100 
101   lldb::ModuleSP GetModule() const;
102 
103   // Getting attribute values from the DIE.
104   //
105   // GetAttributeValueAsXXX() functions should only be used if you are
106   // looking for one or two attributes on a DIE. If you are trying to
107   // parse all attributes, use GetAttributes (...) instead
108   const char *GetAttributeValueAsString(const dw_attr_t attr,
109                                         const char *fail_value) const;
110 
111   uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr,
112                                        uint64_t fail_value) const;
113 
114   uint64_t GetAttributeValueAsAddress(const dw_attr_t attr,
115                                       uint64_t fail_value) const;
116 
117   size_t GetAttributes(DWARFAttributes &attributes, uint32_t depth = 0) const;
118 
119 protected:
120   DWARFUnit *m_cu;
121   DWARFDebugInfoEntry *m_die;
122 };
123 
124 bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
125 bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
126 
127 #endif // SymbolFileDWARF_DWARFBaseDIE_h_
128