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 
33  const char *GetQualifiedName(std::string &storage) const;
34 
36  void GetName(lldb_private::Stream &s) const;
37 
38  void AppendTypeName(lldb_private::Stream &s) const;
39 
41 
42  // Resolve a type by UID using this DIE's DWARF file
43  lldb_private::Type *ResolveTypeUID(const DWARFDIE &die) const;
44 
45  // Functions for obtaining DIE relations and references
46 
47  DWARFDIE
48  GetParent() const;
49 
50  DWARFDIE
51  GetFirstChild() const;
52 
53  DWARFDIE
54  GetSibling() const;
55 
56  DWARFDIE
57  GetReferencedDIE(const dw_attr_t attr) const;
58 
59  // Get a another DIE from the same DWARF file as this DIE. This will
60  // check the current DIE's compile unit first to see if "die_offset" is
61  // in the same compile unit, and fall back to checking the DWARF file.
62  DWARFDIE
63  GetDIE(dw_offset_t die_offset) const;
65 
66  DWARFDIE
67  LookupDeepestBlock(lldb::addr_t file_addr) const;
68 
69  DWARFDIE
71 
72  // DeclContext related functions
73  std::vector<DWARFDIE> GetDeclContextDIEs() const;
74 
75  /// Return this DIE's decl context as it is needed to look up types
76  /// in Clang's -gmodules debug info format.
77  void GetDeclContext(
79 
80  // Getting attribute values from the DIE.
81  //
82  // GetAttributeValueAsXXX() functions should only be used if you are
83  // looking for one or two attributes on a DIE. If you are trying to
84  // parse all attributes, use GetAttributes (...) instead
85  DWARFDIE
87 
88  bool GetDIENamesAndRanges(const char *&name, const char *&mangled,
89  DWARFRangeList &ranges, int &decl_file,
90  int &decl_line, int &decl_column, int &call_file,
91  int &call_line, int &call_column,
92  lldb_private::DWARFExpression *frame_base) const;
93 
94  /// The range of all the children of this DIE.
95  llvm::iterator_range<child_iterator> children() const;
96 };
97 
99  : public llvm::iterator_facade_base<DWARFDIE::child_iterator,
100  std::forward_iterator_tag, DWARFDIE> {
101  /// The current child or an invalid DWARFDie.
103 
104 public:
105  child_iterator() = default;
106  child_iterator(const DWARFDIE &parent) : m_die(parent.GetFirstChild()) {}
107  bool operator==(const child_iterator &it) const {
108  // DWARFDIE's operator== differentiates between an invalid DWARFDIE that
109  // has a CU but no DIE and one that has neither CU nor DIE. The 'end'
110  // iterator could be default constructed, so explicitly allow
111  // (CU, (DIE)nullptr) == (nullptr, nullptr) -> true
112  if (!m_die.IsValid() && !it.m_die.IsValid())
113  return true;
114  return m_die == it.m_die;
115  }
116  const DWARFDIE &operator*() const {
117  assert(m_die.IsValid() && "Derefencing invalid iterator?");
118  return m_die;
119  }
121  assert(m_die.IsValid() && "Derefencing invalid iterator?");
122  return m_die;
123  }
125  assert(m_die.IsValid() && "Incrementing invalid iterator?");
126  m_die = m_die.GetSibling();
127  return *this;
128  }
129 };
130 
131 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H
DWARFDIE::child_iterator::child_iterator
child_iterator()=default
DWARFDIE::GetParent
DWARFDIE GetParent() const
Definition: DWARFDIE.cpp:90
DWARFDIE::child_iterator::child_iterator
child_iterator(const DWARFDIE &parent)
Definition: DWARFDIE.h:106
DWARFDIE::child_iterator::operator*
const DWARFDIE & operator*() const
Definition: DWARFDIE.h:116
DWARFDIE::GetDeclContextDIEs
std::vector< DWARFDIE > GetDeclContextDIEs() const
Definition: DWARFDIE.cpp:361
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:375
DWARFDIE::AppendTypeName
void AppendTypeName(lldb_private::Stream &s) const
Definition: DWARFDIE.cpp:247
DWARFDIE::child_iterator::m_die
DWARFDIE m_die
The current child or an invalid DWARFDie.
Definition: DWARFDIE.h:102
lldb_private::Stream
Definition: Stream.h:28
DWARFDIE::child_iterator::operator*
DWARFDIE & operator*()
Definition: DWARFDIE.h:120
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
DWARFDIE::ResolveType
lldb_private::Type * ResolveType() const
Definition: DWARFDIE.cpp:348
DWARFDIE::ResolveTypeUID
lldb_private::Type * ResolveTypeUID(const DWARFDIE &die) const
Definition: DWARFDIE.cpp:355
DWARFDIE::GetAttributeValueAsReferenceDIE
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:130
DWARFDIE
Definition: DWARFDIE.h:16
DWARFDIE::child_iterator::operator++
child_iterator & operator++()
Definition: DWARFDIE.h:124
DWARFDIE::GetPubname
const char * GetPubname() const
Definition: DWARFDIE.cpp:210
DWARFDIE::GetQualifiedName
const char * GetQualifiedName(std::string &storage) const
Definition: DWARFDIE.cpp:217
DWARFBaseDIE::GetDIE
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:56
DWARFDIE::IsStructUnionOrClass
bool IsStructUnionOrClass() const
Definition: DWARFDIE.cpp:426
lldb_private::DWARFExpression
Definition: DWARFExpression.h:35
DWARFDIE::GetMangledName
const char * GetMangledName() const
Definition: DWARFDIE.cpp:203
DWARFDIE::child_iterator
Definition: DWARFDIE.h:98
DWARFDIE::GetReferencedDIE
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:114
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
DWARFDIE::GetFirstChild
DWARFDIE GetFirstChild() const
Definition: DWARFDIE.cpp:98
lldb_private::RangeVector
Definition: RangeMap.h:125
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::DWARFExpression *frame_base) const
Definition: DWARFDIE.cpp:439
uint32_t
lldb_private::Type
Definition: Type.h:66
DWARFBaseDIE::GetName
const char * GetName() const
Definition: DWARFBaseDIE.cpp:70
uint16_t
DWARFDIE::GetParentDeclContextDIE
DWARFDIE GetParentDeclContextDIE() const
Definition: DWARFDIE.cpp:419
DWARFBaseDIE.h
DWARFDIE::children
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition: DWARFDIE.cpp:452
DWARFDIE::GetSibling
DWARFDIE GetSibling() const
Definition: DWARFDIE.cpp:106
DWARFDIE::LookupDeepestBlock
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
Definition: DWARFDIE.cpp:143
llvm::SmallVectorImpl
Definition: Disassembler.h:42
DWARFDIE::IsMethod
bool IsMethod() const
Definition: DWARFDIE.cpp:432
DWARFDIE::child_iterator::operator==
bool operator==(const child_iterator &it) const
Definition: DWARFDIE.h:107
DWARFBaseDIE::DWARFBaseDIE
DWARFBaseDIE()=default
DWARFBaseDIE
Definition: DWARFBaseDIE.h:25
DWARFBaseDIE::IsValid
bool IsValid() const
Definition: DWARFBaseDIE.h:45