LLDB  mainline
DWARFDIE.h
Go to the documentation of this file.
1 //===-- DWARFDIE.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_DWARFDIE_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H
11 
12 #include "DWARFBaseDIE.h"
13 #include "llvm/ADT/SmallSet.h"
14 #include "llvm/ADT/iterator_range.h"
15 
16 class DWARFDIE : public DWARFBaseDIE {
17 public:
18  class child_iterator;
20 
21  // Tests
22  bool IsStructUnionOrClass() const;
23 
24  bool IsMethod() const;
25 
26  // Accessors
27 
28  // Accessing information about a DIE
29  const char *GetMangledName() const;
30 
31  const char *GetPubname() const;
32 
34  void GetName(lldb_private::Stream &s) const;
35 
36  void AppendTypeName(lldb_private::Stream &s) const;
37 
39 
40  // Resolve a type by UID using this DIE's DWARF file
41  lldb_private::Type *ResolveTypeUID(const DWARFDIE &die) const;
42 
43  // Functions for obtaining DIE relations and references
44 
45  DWARFDIE
46  GetParent() const;
47 
48  DWARFDIE
49  GetFirstChild() const;
50 
51  DWARFDIE
52  GetSibling() const;
53 
54  DWARFDIE
55  GetReferencedDIE(const dw_attr_t attr) const;
56 
57  // Get a another DIE from the same DWARF file as this DIE. This will
58  // check the current DIE's compile unit first to see if "die_offset" is
59  // in the same compile unit, and fall back to checking the DWARF file.
60  DWARFDIE
61  GetDIE(dw_offset_t die_offset) const;
63 
64  DWARFDIE
65  LookupDeepestBlock(lldb::addr_t file_addr) const;
66 
67  DWARFDIE
69 
70  // DeclContext related functions
71  std::vector<DWARFDIE> GetDeclContextDIEs() const;
72 
73  /// Return this DIE's decl context as it is needed to look up types
74  /// in Clang's -gmodules debug info format.
75  void GetDeclContext(
77 
78  // Getting attribute values from the DIE.
79  //
80  // GetAttributeValueAsXXX() functions should only be used if you are
81  // looking for one or two attributes on a DIE. If you are trying to
82  // parse all attributes, use GetAttributes (...) instead
83  DWARFDIE
85 
86  bool
87  GetDIENamesAndRanges(const char *&name, const char *&mangled,
88  DWARFRangeList &ranges, int &decl_file, int &decl_line,
89  int &decl_column, int &call_file, int &call_line,
90  int &call_column,
91  lldb_private::DWARFExpressionList *frame_base) const;
92 
93  /// The range of all the children of this DIE.
94  llvm::iterator_range<child_iterator> children() const;
95 };
96 
98  : public llvm::iterator_facade_base<DWARFDIE::child_iterator,
99  std::forward_iterator_tag, DWARFDIE> {
100  /// The current child or an invalid DWARFDie.
102 
103 public:
104  child_iterator() = default;
105  child_iterator(const DWARFDIE &parent) : m_die(parent.GetFirstChild()) {}
106  bool operator==(const child_iterator &it) const {
107  // DWARFDIE's operator== differentiates between an invalid DWARFDIE that
108  // has a CU but no DIE and one that has neither CU nor DIE. The 'end'
109  // iterator could be default constructed, so explicitly allow
110  // (CU, (DIE)nullptr) == (nullptr, nullptr) -> true
111  if (!m_die.IsValid() && !it.m_die.IsValid())
112  return true;
113  return m_die == it.m_die;
114  }
115  const DWARFDIE &operator*() const {
116  assert(m_die.IsValid() && "Derefencing invalid iterator?");
117  return m_die;
118  }
120  assert(m_die.IsValid() && "Derefencing invalid iterator?");
121  return m_die;
122  }
124  assert(m_die.IsValid() && "Incrementing invalid iterator?");
125  m_die = m_die.GetSibling();
126  return *this;
127  }
128 };
129 
130 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H
DWARFDIE::child_iterator::child_iterator
child_iterator()=default
DWARFDIE::GetParent
DWARFDIE GetParent() const
Definition: DWARFDIE.cpp:86
DWARFDIE::child_iterator::child_iterator
child_iterator(const DWARFDIE &parent)
Definition: DWARFDIE.h:105
DWARFDIE::child_iterator::operator*
const DWARFDIE & operator*() const
Definition: DWARFDIE.h:115
DWARFDIE::GetDeclContextDIEs
std::vector< DWARFDIE > GetDeclContextDIEs() const
Definition: DWARFDIE.cpp:362
DWARFDIE::GetDeclContext
void GetDeclContext(llvm::SmallVectorImpl< lldb_private::CompilerContext > &context) const
Return this DIE's decl context as it is needed to look up types in Clang's -gmodules debug info forma...
Definition: DWARFDIE.cpp:376
DWARFDIE::AppendTypeName
void AppendTypeName(lldb_private::Stream &s) const
Definition: DWARFDIE.cpp:236
DWARFDIE::child_iterator::m_die
DWARFDIE m_die
The current child or an invalid DWARFDie.
Definition: DWARFDIE.h:101
lldb_private::Stream
Definition: Stream.h:28
DWARFDIE::child_iterator::operator*
DWARFDIE & operator*()
Definition: DWARFDIE.h:119
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
DWARFDIE::ResolveType
lldb_private::Type * ResolveType() const
Definition: DWARFDIE.cpp:349
DWARFDIE::ResolveTypeUID
lldb_private::Type * ResolveTypeUID(const DWARFDIE &die) const
Definition: DWARFDIE.cpp:356
DWARFDIE::GetAttributeValueAsReferenceDIE
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:126
DWARFDIE
Definition: DWARFDIE.h:16
DWARFDIE::child_iterator::operator++
child_iterator & operator++()
Definition: DWARFDIE.h:123
DWARFDIE::GetPubname
const char * GetPubname() const
Definition: DWARFDIE.cpp:206
DWARFBaseDIE::GetDIE
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:56
DWARFDIE::IsStructUnionOrClass
bool IsStructUnionOrClass() const
Definition: DWARFDIE.cpp:427
DWARFDIE::GetMangledName
const char * GetMangledName() const
Definition: DWARFDIE.cpp:199
DWARFDIE::child_iterator
Definition: DWARFDIE.h:97
DWARFDIE::GetReferencedDIE
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:110
DWARFDIE::GetFirstChild
DWARFDIE GetFirstChild() const
Definition: DWARFDIE.cpp:94
lldb_private::RangeVector
Definition: RangeMap.h:136
uint32_t
lldb_private::Type
Definition: Type.h:66
DWARFBaseDIE::GetName
const char * GetName() const
Definition: DWARFBaseDIE.cpp:77
uint16_t
DWARFDIE::GetParentDeclContextDIE
DWARFDIE GetParentDeclContextDIE() const
Definition: DWARFDIE.cpp:420
DWARFBaseDIE.h
DWARFDIE::children
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition: DWARFDIE.cpp:453
DWARFDIE::GetSibling
DWARFDIE GetSibling() const
Definition: DWARFDIE.cpp:102
lldb_private::DWARFExpressionList
Definition: DWARFExpressionList.h:24
DWARFDIE::LookupDeepestBlock
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
Definition: DWARFDIE.cpp:139
DWARFDIE::GetDIENamesAndRanges
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, DWARFRangeList &ranges, int &decl_file, int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, lldb_private::DWARFExpressionList *frame_base) const
Definition: DWARFDIE.cpp:440
llvm::SmallVectorImpl
Definition: Disassembler.h:42
DWARFDIE::IsMethod
bool IsMethod() const
Definition: DWARFDIE.cpp:433
DWARFDIE::child_iterator::operator==
bool operator==(const child_iterator &it) const
Definition: DWARFDIE.h:106
DWARFBaseDIE::DWARFBaseDIE
DWARFBaseDIE()=default
DWARFBaseDIE
Definition: DWARFBaseDIE.h:25
DWARFBaseDIE::IsValid
bool IsValid() const
Definition: DWARFBaseDIE.h:45