18#include "llvm/ADT/iterator.h"
19#include "llvm/BinaryFormat/Dwarf.h"
31class ElaboratingDIEIterator
32 :
public llvm::iterator_facade_base<
33 ElaboratingDIEIterator, std::input_iterator_tag, DWARFDIE,
34 std::ptrdiff_t, DWARFDIE *, DWARFDIE *> {
42 llvm::SmallVector<DWARFDIE, 2> m_worklist;
43 llvm::SmallSet<DWARFDebugInfoEntry *, 3> m_seen;
46 assert(!m_worklist.empty() &&
"Incrementing end iterator?");
50 m_worklist.pop_back();
53 for (
dw_attr_t attr : {DW_AT_specification, DW_AT_abstract_origin}) {
55 if (m_seen.insert(die.
GetDIE()).second)
56 m_worklist.push_back(d);
62 explicit ElaboratingDIEIterator(
DWARFDIE d) : m_worklist(1, d) {}
65 ElaboratingDIEIterator() =
default;
68 ElaboratingDIEIterator &operator++() {
73 friend bool operator==(
const ElaboratingDIEIterator &a,
74 const ElaboratingDIEIterator &b) {
75 if (a.m_worklist.empty() || b.m_worklist.empty())
76 return a.m_worklist.empty() == b.m_worklist.empty();
77 return a.m_worklist.back() == b.m_worklist.back();
81llvm::iterator_range<ElaboratingDIEIterator>
82elaborating_dies(
const DWARFDIE &die) {
83 return llvm::make_range(ElaboratingDIEIterator(die),
84 ElaboratingDIEIterator());
132 const bool check_specification_or_abstract_origin =
true;
135 check_specification_or_abstract_origin))
147 bool check_children =
false;
148 bool match_addr_range =
false;
150 case DW_TAG_class_type:
151 case DW_TAG_namespace:
152 case DW_TAG_structure_type:
153 case DW_TAG_common_block:
154 check_children =
true;
156 case DW_TAG_compile_unit:
158 case DW_TAG_catch_block:
159 case DW_TAG_subprogram:
160 case DW_TAG_try_block:
161 case DW_TAG_partial_unit:
162 match_addr_range =
true;
164 case DW_TAG_lexical_block:
165 case DW_TAG_inlined_subroutine:
166 check_children =
true;
167 match_addr_range =
true;
173 if (match_addr_range) {
177 check_children =
true;
182 case DW_TAG_inlined_subroutine:
183 case DW_TAG_lexical_block:
188 check_children =
false;
192 if (check_children) {
250 case DW_TAG_array_type:
253 case DW_TAG_base_type:
256 case DW_TAG_class_type:
259 case DW_TAG_const_type:
262 case DW_TAG_enumeration_type:
265 case DW_TAG_file_type:
268 case DW_TAG_interface_type:
271 case DW_TAG_packed_type:
274 case DW_TAG_pointer_type:
276 case DW_TAG_ptr_to_member_type:
278 case DW_TAG_reference_type:
280 case DW_TAG_restrict_type:
283 case DW_TAG_set_type:
286 case DW_TAG_shared_type:
289 case DW_TAG_string_type:
292 case DW_TAG_structure_type:
295 case DW_TAG_subrange_type:
298 case DW_TAG_subroutine_type:
301 case DW_TAG_thrown_type:
304 case DW_TAG_union_type:
307 case DW_TAG_unspecified_type:
310 case DW_TAG_volatile_type:
313 case DW_TAG_LLVM_ptrauth_type: {
316 DW_AT_LLVM_ptrauth_address_discriminated, 0);
317 unsigned extraDiscriminator =
322 DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
323 unsigned authenticationMode =
326 s.
Printf(
"__ptrauth(%d, %d, 0x0%x, %d, %d, %d)", key,
327 isAddressDiscriminated, extraDiscriminator, isaPointer,
328 authenticatesNullValues, authenticationMode);
337 next_die.AppendTypeName(s);
340 case DW_TAG_array_type:
343 case DW_TAG_pointer_type:
346 case DW_TAG_ptr_to_member_type:
349 case DW_TAG_reference_type:
366 return dwarf->ResolveTypeUID(die,
true);
371 llvm::SmallSet<lldb::user_id_t, 4> &seen,
372 std::vector<CompilerContext> &context) {
374 while (die && seen.insert(die.
GetID()).second) {
394 case DW_TAG_namespace:
397 case DW_TAG_class_type:
398 case DW_TAG_structure_type:
401 case DW_TAG_union_type:
404 case DW_TAG_enumeration_type:
407 case DW_TAG_subprogram:
410 case DW_TAG_variable:
425 llvm::SmallSet<lldb::user_id_t, 4> seen;
426 std::vector<CompilerContext> context;
428 std::reverse(context.begin(), context.end());
433 llvm::SmallSet<lldb::user_id_t, 4> &seen,
434 std::vector<CompilerContext> &context) {
436 while (die && seen.insert(die.
GetID()).second) {
445 const char *name = die.
GetName();
446 if (!name || !name[0])
454 case DW_TAG_namespace:
457 case DW_TAG_class_type:
458 case DW_TAG_structure_type:
461 case DW_TAG_union_type:
464 case DW_TAG_enumeration_type:
467 case DW_TAG_variable:
473 case DW_TAG_base_type:
482 case DW_TAG_compile_unit:
483 case DW_TAG_type_unit:
484 case DW_TAG_subprogram:
485 case DW_TAG_lexical_block:
486 case DW_TAG_inlined_subroutine:
497 llvm::SmallSet<lldb::user_id_t, 4> seen;
498 std::vector<CompilerContext> context;
500 std::reverse(context.begin(), context.end());
508 if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
512 if (parent_decl_ctx_die == die)
514 die = parent_decl_ctx_die;
516 return dwarf_decl_ctx;
529 if (die != orig_die) {
531 case DW_TAG_compile_unit:
532 case DW_TAG_partial_unit:
533 case DW_TAG_namespace:
534 case DW_TAG_structure_type:
535 case DW_TAG_union_type:
536 case DW_TAG_class_type:
566 return tag == DW_TAG_class_type || tag == DW_TAG_structure_type ||
567 tag == DW_TAG_union_type;
571 for (
DWARFDIE d : elaborating_dies(*
this))
572 if (d.GetParent().IsStructUnionOrClass())
579 std::optional<int> &decl_file, std::optional<int> &decl_line,
580 std::optional<int> &decl_column, std::optional<int> &call_file,
581 std::optional<int> &call_line, std::optional<int> &call_column,
585 GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column,
586 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)
A uniqued constant string class.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
const Entry * FindEntryThatContains(B addr) const
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
DWARFDIE GetFirstChild() const
DWARFDIE GetParent() const
const char * GetMangledName() 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.
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, DWARFRangeList &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 GetParentDeclContextDIE() const
bool IsStructUnionOrClass() const
Type * ResolveTypeUID(const DWARFDIE &die) const
DWARFDIE LookupDeepestBlock(lldb::addr_t file_addr) const
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
DWARFDebugInfoEntry * GetDIE() const
DWARFDeclContext GetDWARFDeclContext() const
void AppendTypeName(Stream &s) 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
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) 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_specification_or_abstract_origin=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_specification_or_abstract_origin=false) const
const char * GetPubname(const DWARFUnit *cu) const
bool GetDIENamesAndRanges(DWARFUnit *cu, const char *&name, const char *&mangled, DWARFRangeList &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
DWARFDebugInfoEntry * GetFirstChild()
DWARFRangeList GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
void AppendDeclContext(dw_tag_t tag, const char *name)
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.
const Scalar operator*(Scalar lhs, Scalar rhs)
bool operator==(const Address &lhs, const Address &rhs)