19#include "llvm/ADT/iterator.h"
20#include "llvm/BinaryFormat/Dwarf.h"
21#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
33class ElaboratingDIEIterator
34 :
public llvm::iterator_facade_base<
35 ElaboratingDIEIterator, std::input_iterator_tag, DWARFDIE,
36 std::ptrdiff_t, DWARFDIE *, DWARFDIE *> {
44 llvm::SmallVector<DWARFDIE, 2> m_worklist;
45 llvm::SmallSet<DWARFDebugInfoEntry *, 3> m_seen;
48 assert(!m_worklist.empty() &&
"Incrementing end iterator?");
52 m_worklist.pop_back();
56 {DW_AT_specification, DW_AT_abstract_origin, DW_AT_signature}) {
58 if (m_seen.insert(die.
GetDIE()).second)
59 m_worklist.push_back(d);
65 explicit ElaboratingDIEIterator(
DWARFDIE d) : m_worklist(1, d) {}
68 ElaboratingDIEIterator() =
default;
71 ElaboratingDIEIterator &operator++() {
76 friend bool operator==(
const ElaboratingDIEIterator &a,
77 const ElaboratingDIEIterator &b) {
78 if (a.m_worklist.empty() || b.m_worklist.empty())
79 return a.m_worklist.empty() == b.m_worklist.empty();
80 return a.m_worklist.back() == b.m_worklist.back();
84llvm::iterator_range<ElaboratingDIEIterator>
85elaborating_dies(
const DWARFDIE &die) {
86 return llvm::make_range(ElaboratingDIEIterator(die),
87 ElaboratingDIEIterator());
135 const bool check_elaborating_dies =
true;
138 check_elaborating_dies))
150 bool check_children =
false;
151 bool match_addr_range =
false;
153 case DW_TAG_class_type:
154 case DW_TAG_namespace:
155 case DW_TAG_structure_type:
156 case DW_TAG_common_block:
157 check_children =
true;
159 case DW_TAG_compile_unit:
161 case DW_TAG_catch_block:
162 case DW_TAG_subprogram:
163 case DW_TAG_try_block:
164 case DW_TAG_partial_unit:
165 match_addr_range =
true;
167 case DW_TAG_lexical_block:
168 case DW_TAG_inlined_subroutine:
169 check_children =
true;
170 match_addr_range =
true;
176 if (match_addr_range) {
177 if (llvm::Expected<llvm::DWARFAddressRangesVector> ranges =
180 llvm::any_of(*ranges, [&](
const llvm::DWARFAddressRange &r) {
181 return r.LowPC <= address && address < r.HighPC;
188 case DW_TAG_inlined_subroutine:
189 case DW_TAG_lexical_block:
194 check_children = addr_in_range;
197 "DIE({1:x}): {0}",
GetID());
201 if (check_children) {
259 case DW_TAG_array_type:
262 case DW_TAG_base_type:
265 case DW_TAG_class_type:
268 case DW_TAG_const_type:
271 case DW_TAG_enumeration_type:
274 case DW_TAG_file_type:
277 case DW_TAG_interface_type:
280 case DW_TAG_packed_type:
283 case DW_TAG_pointer_type:
285 case DW_TAG_ptr_to_member_type:
287 case DW_TAG_reference_type:
289 case DW_TAG_restrict_type:
292 case DW_TAG_set_type:
295 case DW_TAG_shared_type:
298 case DW_TAG_string_type:
301 case DW_TAG_structure_type:
304 case DW_TAG_subrange_type:
307 case DW_TAG_subroutine_type:
310 case DW_TAG_thrown_type:
313 case DW_TAG_union_type:
316 case DW_TAG_unspecified_type:
319 case DW_TAG_volatile_type:
322 case DW_TAG_LLVM_ptrauth_type: {
325 DW_AT_LLVM_ptrauth_address_discriminated, 0);
326 unsigned extraDiscriminator =
331 DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
332 unsigned authenticationMode =
335 s.
Printf(
"__ptrauth(%d, %d, 0x0%x, %d, %d, %d)", key,
336 isAddressDiscriminated, extraDiscriminator, isaPointer,
337 authenticatesNullValues, authenticationMode);
346 next_die.AppendTypeName(s);
349 case DW_TAG_array_type:
352 case DW_TAG_pointer_type:
355 case DW_TAG_ptr_to_member_type:
358 case DW_TAG_reference_type:
375 return dwarf->ResolveTypeUID(die,
true);
380 llvm::SmallSet<lldb::user_id_t, 4> &seen,
381 std::vector<CompilerContext> &context) {
383 while (die && seen.insert(die.
GetID()).second) {
398 case DW_TAG_namespace:
401 case DW_TAG_class_type:
402 case DW_TAG_structure_type:
405 case DW_TAG_union_type:
408 case DW_TAG_enumeration_type:
411 case DW_TAG_subprogram:
414 case DW_TAG_variable:
429 llvm::SmallSet<lldb::user_id_t, 4> seen;
430 std::vector<CompilerContext> context;
432 std::reverse(context.begin(), context.end());
437 llvm::SmallSet<lldb::user_id_t, 4> &seen,
438 std::vector<CompilerContext> &context) {
440 while (die && seen.insert(die.
GetID()).second) {
446 case DW_TAG_namespace:
449 case DW_TAG_class_type:
450 case DW_TAG_structure_type:
453 case DW_TAG_union_type:
456 case DW_TAG_enumeration_type:
459 case DW_TAG_variable:
465 case DW_TAG_base_type:
474 case DW_TAG_compile_unit:
475 case DW_TAG_type_unit:
476 case DW_TAG_subprogram:
477 case DW_TAG_lexical_block:
478 case DW_TAG_inlined_subroutine:
489 llvm::SmallSet<lldb::user_id_t, 4> seen;
490 std::vector<CompilerContext> context;
492 std::reverse(context.begin(), context.end());
500 if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
504 if (parent_decl_ctx_die == die)
506 die = parent_decl_ctx_die;
508 return dwarf_decl_ctx;
521 if (die != orig_die) {
523 case DW_TAG_compile_unit:
524 case DW_TAG_partial_unit:
525 case DW_TAG_namespace:
526 case DW_TAG_structure_type:
527 case DW_TAG_union_type:
528 case DW_TAG_class_type:
558 return tag == DW_TAG_class_type || tag == DW_TAG_structure_type ||
559 tag == DW_TAG_union_type;
563 for (
DWARFDIE d : elaborating_dies(*
this))
564 if (d.GetParent().IsStructUnionOrClass())
570 const char *&name,
const char *&mangled,
571 llvm::DWARFAddressRangesVector &ranges, std::optional<int> &decl_file,
572 std::optional<int> &decl_line, std::optional<int> &decl_column,
573 std::optional<int> &call_file, std::optional<int> &call_line,
574 std::optional<int> &call_column,
578 GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column,
579 call_file, call_line, call_column, frame_base);
static void GetTypeLookupContextImpl(DWARFDIE die, llvm::SmallSet< lldb::user_id_t, 4 > &seen, std::vector< CompilerContext > &context)
static DWARFDeclContext GetDWARFDeclContextImpl(DWARFDIE die)
static void GetDeclContextImpl(DWARFDIE die, llvm::SmallSet< lldb::user_id_t, 4 > &seen, std::vector< CompilerContext > &context)
static DWARFDIE GetParentDeclContextDIEImpl(DWARFDIE die)
#define LLDB_LOG_ERROR(log, error,...)
A uniqued constant string class.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
SymbolFileDWARF * GetDWARF() const
DWARFDebugInfoEntry * m_die
DWARFUnit * GetCU() const
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
lldb::user_id_t GetID() const
void GetName(Stream &s) const
const char * GetMangledName(bool substitute_name_allowed=true) const
DWARFDIE resolveTypeUnitReference() const
DWARFDIE GetFirstChild() const
DWARFDIE GetParent() const
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, llvm::DWARFAddressRangesVector &ranges, std::optional< int > &decl_file, std::optional< int > &decl_line, std::optional< int > &decl_column, std::optional< int > &call_file, std::optional< int > &call_line, std::optional< int > &call_column, DWARFExpressionList *frame_base) const
DWARFDIE resolveReferencedType(dw_attr_t attr) const
std::vector< CompilerContext > GetDeclContext() const
Return this DIE's decl context as it is needed to look up types in Clang modules.
DWARFDIE GetDIE(dw_offset_t die_offset) const
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
DWARFDIE GetParentDeclContextDIE() const
bool IsStructUnionOrClass() const
Type * ResolveTypeUID(const DWARFDIE &die) const
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
std::optional< DWARFFormValue > find(const dw_attr_t attr) const
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
DWARFDebugInfoEntry * GetDIE() const
DWARFDeclContext GetDWARFDeclContext() const
std::optional< uint64_t > getLanguage() const
void AppendTypeName(Stream &s) const
child_iterator begin() const
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Type * ResolveType() const
const char * GetName() const
std::vector< CompilerContext > GetTypeLookupContext() const
Get a context to a type so it can be looked up.
const char * GetPubname() const
DWARFDIE GetSibling() const
child_iterator end() const
llvm::Expected< llvm::DWARFAddressRangesVector > GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc, bool check_elaborating_dies=false) const
const char * GetMangledName(const DWARFUnit *cu, bool substitute_name_allowed=true) const
DWARFDebugInfoEntry * GetSibling()
DWARFDebugInfoEntry * GetParent()
DWARFDIE GetAttributeValueAsReference(const DWARFUnit *cu, const dw_attr_t attr, bool check_elaborating_dies=false) const
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_elaborating_dies=false) const
bool GetDIENamesAndRanges(DWARFUnit *cu, const char *&name, const char *&mangled, llvm::DWARFAddressRangesVector &rangeList, std::optional< int > &decl_file, std::optional< int > &decl_line, std::optional< int > &decl_column, std::optional< int > &call_file, std::optional< int > &call_line, std::optional< int > &call_column, DWARFExpressionList *frame_base=nullptr) const
const char * GetPubname(const DWARFUnit *cu) const
dw_offset_t GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr, DWARFFormValue &formValue, dw_offset_t *end_attr_offset_ptr=nullptr, bool check_elaborating_dies=false) const
DWARFDebugInfoEntry * GetFirstChild()
void AppendDeclContext(dw_tag_t tag, const char *name)
uint64_t GetDWARFLanguageType()
DWARFDIE GetDIE(dw_offset_t die_offset)
Type * ResolveType(const DWARFDIE &die, bool assert_not_being_parsed=true, bool resolve_function_context=false)
llvm::dwarf::Tag dw_tag_t
llvm::dwarf::Attribute dw_attr_t
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
const Scalar operator*(Scalar lhs, Scalar rhs)
bool operator==(const Address &lhs, const Address &rhs)