19#include "llvm/ADT/iterator.h"
20#include "llvm/BinaryFormat/Dwarf.h"
21#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
22#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h"
23#include "llvm/Support/raw_ostream.h"
35class ElaboratingDIEIterator
36 :
public llvm::iterator_facade_base<
37 ElaboratingDIEIterator, std::input_iterator_tag, DWARFDIE,
38 std::ptrdiff_t, DWARFDIE *, DWARFDIE *> {
46 llvm::SmallVector<DWARFDIE, 2> m_worklist;
47 llvm::SmallSet<DWARFDebugInfoEntry *, 3> m_seen;
50 assert(!m_worklist.empty() &&
"Incrementing end iterator?");
54 m_worklist.pop_back();
58 {DW_AT_specification, DW_AT_abstract_origin, DW_AT_signature}) {
60 if (m_seen.insert(die.
GetDIE()).second)
61 m_worklist.push_back(d);
67 explicit ElaboratingDIEIterator(
DWARFDIE d) : m_worklist(1, d) {}
70 ElaboratingDIEIterator() =
default;
73 ElaboratingDIEIterator &operator++() {
78 friend bool operator==(
const ElaboratingDIEIterator &a,
79 const ElaboratingDIEIterator &b) {
80 if (a.m_worklist.empty() || b.m_worklist.empty())
81 return a.m_worklist.empty() == b.m_worklist.empty();
82 return a.m_worklist.back() == b.m_worklist.back();
86llvm::iterator_range<ElaboratingDIEIterator>
87elaborating_dies(
const DWARFDIE &die) {
88 return llvm::make_range(ElaboratingDIEIterator(die),
89 ElaboratingDIEIterator());
137 const bool check_elaborating_dies =
true;
140 check_elaborating_dies))
152 bool check_children =
false;
153 bool match_addr_range =
false;
155 case DW_TAG_class_type:
156 case DW_TAG_namespace:
157 case DW_TAG_structure_type:
158 case DW_TAG_common_block:
159 check_children =
true;
161 case DW_TAG_compile_unit:
163 case DW_TAG_catch_block:
164 case DW_TAG_subprogram:
165 case DW_TAG_try_block:
166 case DW_TAG_partial_unit:
167 match_addr_range =
true;
169 case DW_TAG_lexical_block:
170 case DW_TAG_inlined_subroutine:
171 check_children =
true;
172 match_addr_range =
true;
178 if (match_addr_range) {
179 if (llvm::Expected<llvm::DWARFAddressRangesVector> ranges =
182 llvm::any_of(*ranges, [&](
const llvm::DWARFAddressRange &r) {
183 return r.LowPC <= address && address < r.HighPC;
190 case DW_TAG_inlined_subroutine:
191 case DW_TAG_lexical_block:
196 check_children = addr_in_range;
199 "DIE({1:x}): {0}",
GetID());
203 if (check_children) {
261 case DW_TAG_array_type:
264 case DW_TAG_base_type:
267 case DW_TAG_class_type:
270 case DW_TAG_const_type:
273 case DW_TAG_enumeration_type:
276 case DW_TAG_file_type:
279 case DW_TAG_interface_type:
282 case DW_TAG_packed_type:
285 case DW_TAG_pointer_type:
287 case DW_TAG_ptr_to_member_type:
289 case DW_TAG_reference_type:
291 case DW_TAG_restrict_type:
294 case DW_TAG_set_type:
297 case DW_TAG_shared_type:
300 case DW_TAG_string_type:
303 case DW_TAG_structure_type:
306 case DW_TAG_subrange_type:
309 case DW_TAG_subroutine_type:
312 case DW_TAG_thrown_type:
315 case DW_TAG_union_type:
318 case DW_TAG_unspecified_type:
321 case DW_TAG_volatile_type:
324 case DW_TAG_LLVM_ptrauth_type: {
327 DW_AT_LLVM_ptrauth_address_discriminated, 0);
328 unsigned extraDiscriminator =
333 DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
334 unsigned authenticationMode =
337 s.
Printf(
"__ptrauth(%d, %d, 0x0%x, %d, %d, %d)", key,
338 isAddressDiscriminated, extraDiscriminator, isaPointer,
339 authenticatesNullValues, authenticationMode);
348 next_die.AppendTypeName(s);
351 case DW_TAG_array_type:
354 case DW_TAG_pointer_type:
357 case DW_TAG_ptr_to_member_type:
360 case DW_TAG_reference_type:
377 return dwarf->ResolveTypeUID(die,
true);
382 bool derive_template_names) {
390 case DW_TAG_namespace:
392 case DW_TAG_enumeration_type:
394 case DW_TAG_subprogram:
396 case DW_TAG_variable:
400 case DW_TAG_base_type:
402 case DW_TAG_class_type:
403 case DW_TAG_structure_type:
404 case DW_TAG_union_type: {
408 llvm::StringRef name = die.
GetName();
409 if (!derive_template_names || name.contains(
'<'))
412 std::string name_storage = name.str();
413 llvm::raw_string_ostream os(name_storage);
414 llvm::DWARFTypePrinter<DWARFDIE>(os).appendAndTerminateTemplateParameters(
419 llvm_unreachable(
"Check tag type in the caller!");
424 llvm::SmallSet<lldb::user_id_t, 4> &seen,
425 std::vector<CompilerContext> &context) {
427 while (die && seen.insert(die.
GetID()).second) {
437 case DW_TAG_namespace:
438 case DW_TAG_class_type:
439 case DW_TAG_structure_type:
440 case DW_TAG_union_type:
441 case DW_TAG_enumeration_type:
442 case DW_TAG_subprogram:
443 case DW_TAG_variable:
455std::vector<CompilerContext>
457 llvm::SmallSet<lldb::user_id_t, 4> seen;
458 std::vector<CompilerContext> context;
460 std::reverse(context.begin(), context.end());
465 llvm::SmallSet<lldb::user_id_t, 4> &seen,
466 std::vector<CompilerContext> &context) {
468 while (die && seen.insert(die.
GetID()).second) {
471 case DW_TAG_namespace:
472 case DW_TAG_class_type:
473 case DW_TAG_structure_type:
474 case DW_TAG_union_type:
475 case DW_TAG_enumeration_type:
476 case DW_TAG_variable:
478 case DW_TAG_base_type:
488 case DW_TAG_compile_unit:
489 case DW_TAG_type_unit:
490 case DW_TAG_subprogram:
491 case DW_TAG_lexical_block:
492 case DW_TAG_inlined_subroutine:
502std::vector<CompilerContext>
504 llvm::SmallSet<lldb::user_id_t, 4> seen;
505 std::vector<CompilerContext> context;
507 std::reverse(context.begin(), context.end());
515 if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
519 if (parent_decl_ctx_die == die)
521 die = parent_decl_ctx_die;
523 return dwarf_decl_ctx;
536 if (die != orig_die) {
538 case DW_TAG_compile_unit:
539 case DW_TAG_partial_unit:
540 case DW_TAG_namespace:
541 case DW_TAG_structure_type:
542 case DW_TAG_union_type:
543 case DW_TAG_class_type:
573 return tag == DW_TAG_class_type || tag == DW_TAG_structure_type ||
574 tag == DW_TAG_union_type;
578 for (
DWARFDIE d : elaborating_dies(*
this))
579 if (d.GetParent().IsStructUnionOrClass())
585 const char *&name,
const char *&mangled,
586 llvm::DWARFAddressRangesVector &ranges, std::optional<int> &decl_file,
587 std::optional<int> &decl_line, std::optional<int> &decl_column,
588 std::optional<int> &call_file, std::optional<int> &call_line,
589 std::optional<int> &call_column,
593 GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column,
594 call_file, call_line, call_column, frame_base);
static DWARFDeclContext GetDWARFDeclContextImpl(DWARFDIE die)
static void GetDeclContextImpl(DWARFDIE die, bool derive_template_names, llvm::SmallSet< lldb::user_id_t, 4 > &seen, std::vector< CompilerContext > &context)
static void GetTypeLookupContextImpl(DWARFDIE die, bool derive_template_names, llvm::SmallSet< lldb::user_id_t, 4 > &seen, std::vector< CompilerContext > &context)
static DWARFDIE GetParentDeclContextDIEImpl(DWARFDIE die)
static CompilerContext GetContextEntry(DWARFDIE die, bool derive_template_names)
#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
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
std::vector< CompilerContext > GetDeclContext(bool derive_template_names=false) const
Return this DIE's decl context as it is needed to look up types in Clang modules.
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(bool derive_template_names=false) 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)
CompilerContext allows an array of these items to be passed to perform detailed lookups in SymbolVend...