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;
27
29public:
30 DWARFBaseDIE() = default;
31
33 : m_cu(cu), m_die(die) {}
34
36 : m_cu(const_cast<DWARFUnit *>(cu)), m_die(die) {}
37
39 : m_cu(cu), m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
40
42 : m_cu(const_cast<DWARFUnit *>(cu)),
43 m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
44
45 // Tests
46 explicit operator bool() const { return IsValid(); }
47
48 bool IsValid() const { return m_cu && m_die; }
49
50 bool HasChildren() const;
51
53
54 // Accessors
56
57 DWARFUnit *GetCU() const { return m_cu; }
58
59 DWARFDebugInfoEntry *GetDIE() const { return m_die; }
60
61 std::optional<DIERef> GetDIERef() const;
62
64 if (cu && die) {
65 m_cu = cu;
66 m_die = die;
67 } else {
68 Clear();
69 }
70 }
71
72 void Clear() {
73 m_cu = nullptr;
74 m_die = nullptr;
75 }
76
77 // Get the data that contains the attribute values for this DIE. Support
78 // for .debug_types means that any DIE can have its data either in the
79 // .debug_info or the .debug_types section; this method will return the
80 // correct section data.
81 //
82 // Clients must validate that this object is valid before calling this.
83 const DWARFDataExtractor &GetData() const;
84
85 // Accessing information about a DIE
86 dw_tag_t Tag() const;
87
88 dw_offset_t GetOffset() const;
89
90 // Get the LLDB user ID for this DIE. This is often just the DIE offset,
91 // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if
92 // we are doing Darwin DWARF in .o file, or DWARF stand alone debug
93 // info.
94 lldb::user_id_t GetID() const;
95
96 const char *GetName() const;
97
99
100 // Getting attribute values from the DIE.
101 //
102 // GetAttributeValueAsXXX() functions should only be used if you are
103 // looking for one or two attributes on a DIE. If you are trying to
104 // parse all attributes, use GetAttributes (...) instead
105 const char *GetAttributeValueAsString(const dw_attr_t attr,
106 const char *fail_value) const;
107
108 uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr,
109 uint64_t fail_value) const;
110
111 std::optional<uint64_t>
113
114 uint64_t GetAttributeValueAsAddress(const dw_attr_t attr,
115 uint64_t fail_value) const;
116
117 enum class Recurse : bool { no, yes };
119
120protected:
121 DWARFUnit *m_cu = nullptr;
123};
124
125bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
126bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
127} // namespace dwarf
128} // namespace lldb_private::plugin
129
130#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
DWARFBaseDIE(const DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:35
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const
void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:63
DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:32
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:38
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:59
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
DWARFBaseDIE(const DWARFUnit *cu, const DWARFDebugInfoEntry *die)
Definition: DWARFBaseDIE.h:41
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:31
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:26
llvm::dwarf::Attribute dw_attr_t
Definition: dwarf.h:24
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:365