Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
39645 views
//===-- DWARFDIE.h ----------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H1011#include "DWARFBaseDIE.h"12#include "llvm/ADT/SmallSet.h"13#include "llvm/ADT/iterator_range.h"1415namespace lldb_private::plugin {16namespace dwarf {17class DWARFDIE : public DWARFBaseDIE {18public:19class child_iterator;20using DWARFBaseDIE::DWARFBaseDIE;2122// Tests23bool IsStructUnionOrClass() const;2425bool IsMethod() const;2627// Accessors2829// Accessing information about a DIE30const char *GetMangledName() const;3132const char *GetPubname() const;3334using DWARFBaseDIE::GetName;35void GetName(Stream &s) const;3637void AppendTypeName(Stream &s) const;3839Type *ResolveType() const;4041// Resolve a type by UID using this DIE's DWARF file42Type *ResolveTypeUID(const DWARFDIE &die) const;4344// Functions for obtaining DIE relations and references4546DWARFDIE47GetParent() const;4849DWARFDIE50GetFirstChild() const;5152DWARFDIE53GetSibling() const;5455DWARFDIE56GetReferencedDIE(const dw_attr_t attr) const;5758// Get a another DIE from the same DWARF file as this DIE. This will59// check the current DIE's compile unit first to see if "die_offset" is60// in the same compile unit, and fall back to checking the DWARF file.61DWARFDIE62GetDIE(dw_offset_t die_offset) const;63using DWARFBaseDIE::GetDIE;6465DWARFDIE66LookupDeepestBlock(lldb::addr_t file_addr) const;6768DWARFDIE69GetParentDeclContextDIE() const;7071/// Return this DIE's decl context as it is needed to look up types72/// in Clang modules. This context will include any modules or functions that73/// the type is declared in so an exact module match can be efficiently made.74std::vector<CompilerContext> GetDeclContext() const;7576/// Get a context to a type so it can be looked up.77///78/// This function uses the current DIE to fill in a CompilerContext array79/// that is suitable for type lookup for comparison to a TypeQuery's compiler80/// context (TypeQuery::GetContextRef()). If this DIE represents a named type,81/// it should fill out the compiler context with the type itself as the last82/// entry. The declaration context should be above the type and stop at an83/// appropriate time, like either the translation unit or at a function84/// context. This is designed to allow users to efficiently look for types85/// using a full or partial CompilerContext array.86std::vector<CompilerContext> GetTypeLookupContext() const;8788DWARFDeclContext GetDWARFDeclContext() const;8990// Getting attribute values from the DIE.91//92// GetAttributeValueAsXXX() functions should only be used if you are93// looking for one or two attributes on a DIE. If you are trying to94// parse all attributes, use GetAttributes (...) instead95DWARFDIE96GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const;9798bool GetDIENamesAndRanges(99const char *&name, const char *&mangled, DWARFRangeList &ranges,100std::optional<int> &decl_file, std::optional<int> &decl_line,101std::optional<int> &decl_column, std::optional<int> &call_file,102std::optional<int> &call_line, std::optional<int> &call_column,103DWARFExpressionList *frame_base) const;104105/// The range of all the children of this DIE.106llvm::iterator_range<child_iterator> children() const;107};108109class DWARFDIE::child_iterator110: public llvm::iterator_facade_base<DWARFDIE::child_iterator,111std::forward_iterator_tag, DWARFDIE> {112/// The current child or an invalid DWARFDie.113DWARFDIE m_die;114115public:116child_iterator() = default;117child_iterator(const DWARFDIE &parent) : m_die(parent.GetFirstChild()) {}118bool operator==(const child_iterator &it) const {119// DWARFDIE's operator== differentiates between an invalid DWARFDIE that120// has a CU but no DIE and one that has neither CU nor DIE. The 'end'121// iterator could be default constructed, so explicitly allow122// (CU, (DIE)nullptr) == (nullptr, nullptr) -> true123if (!m_die.IsValid() && !it.m_die.IsValid())124return true;125return m_die == it.m_die;126}127const DWARFDIE &operator*() const {128assert(m_die.IsValid() && "Derefencing invalid iterator?");129return m_die;130}131DWARFDIE &operator*() {132assert(m_die.IsValid() && "Derefencing invalid iterator?");133return m_die;134}135child_iterator &operator++() {136assert(m_die.IsValid() && "Incrementing invalid iterator?");137m_die = m_die.GetSibling();138return *this;139}140};141} // namespace dwarf142} // namespace lldb_private::plugin143144#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H145146147