LLDB mainline
DWARFBaseDIE.h
Go to the documentation of this file.
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 LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H
11
12#include "lldb/Core/dwarf.h"
13#include "lldb/lldb-types.h"
14
15#include "llvm/Support/Error.h"
16#include <optional>
17
18namespace lldb_private::plugin {
19namespace dwarf {
20class DIERef;
21class DWARFASTParser;
22class DWARFAttributes;
23class DWARFUnit;
24class DWARFDebugInfoEntry;
25class DWARFDeclContext;
26class SymbolFileDWARF;
27class DWARFFormValue;
28
30public:
32 DWARFBaseDIE() = default;
33
35 : m_cu(cu), m_die(die) {}
36
38 : m_cu(const_cast<DWARFUnit *>(cu)), m_die(die) {}
39
41 : m_cu(cu), m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
42
44 : m_cu(const_cast<DWARFUnit *>(cu)),
45 m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
46
47 // Tests
48 explicit operator bool() const { return IsValid(); }
49
50 bool IsValid() const { return m_cu && m_die; }
51
52 bool HasChildren() const;
53
55
56 // Accessors
58
59 DWARFUnit *GetCU() const { return m_cu; }
60
61 DWARFDebugInfoEntry *GetDIE() const { return m_die; }
62
63 std::optional<DIERef> GetDIERef() const;
64
66 if (cu && die) {
67 m_cu = cu;
68 m_die = die;
69 } else {
70 Clear();
71 }
72 }
73
74 void Clear() {
75 m_cu = nullptr;
76 m_die = nullptr;
77 }
78
79 // Get the data that contains the attribute values for this DIE. Support
80 // for .debug_types means that any DIE can have its data either in the
81 // .debug_info or the .debug_types section; this method will return the
82 // correct section data.
83 //
84 // Clients must validate that this object is valid before calling this.
85 const DWARFDataExtractor &GetData() const;
86
87 // Accessing information about a DIE
88 dw_tag_t Tag() const;
89
90 dw_offset_t GetOffset() const;
91
92 // Get the LLDB user ID for this DIE. This is often just the DIE offset,
93 // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if
94 // we are doing Darwin DWARF in .o file, or DWARF stand alone debug
95 // info.
96 lldb::user_id_t GetID() const;
97
98 const char *GetName() const;
99
101
102 // Getting attribute values from the DIE.
103 //
104 // GetAttributeValueAsXXX() functions should only be used if you are
105 // looking for one or two attributes on a DIE. If you are trying to
106 // parse all attributes, use GetAttributes (...) instead
107 const char *GetAttributeValueAsString(const dw_attr_t attr,
108 const char *fail_value) const;
109
110 uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr,
111 uint64_t fail_value) const;
112
113 std::optional<uint64_t>
115
116 uint64_t GetAttributeValueAsAddress(const dw_attr_t attr,
117 uint64_t fail_value) const;
118
119 enum class Recurse : bool { no, yes };
121
122 // The following methods use LLVM naming convension in order to be are used by
123 // LLVM libraries.
124 dw_tag_t getTag() const { return Tag(); }
125
126 const char *getShortName() const { return GetName(); }
127
128protected:
129 DWARFUnit *m_cu = nullptr;
131};
132
133bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
134bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
135} // namespace dwarf
136} // namespace lldb_private::plugin
137
138#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
DWARFBaseDIE(const DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:37
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const
void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:65
DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:34
const DWARFDataExtractor & GetData() const
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
std::optional< DIERef > GetDIERef() const
DWARFBaseDIE(DWARFUnit *cu, const DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:40
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:61
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
DWARFBaseDIE(const DWARFUnit *cu, const DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:43
uint64_t GetAttributeValueAsAddress(const dw_attr_t attr, uint64_t fail_value) const
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
uint64_t dw_offset_t
Definition: dwarf.h:30
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:25
llvm::dwarf::Attribute dw_attr_t
Definition: dwarf.h:23
bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs)
bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs)
uint64_t user_id_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373