Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
39645 views
//===-- DWARFDebugInfoEntry.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_DWARFDEBUGINFOENTRY_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H1011#include "SymbolFileDWARF.h"12#include "llvm/ADT/SmallVector.h"1314#include "DWARFAttribute.h"15#include "DWARFBaseDIE.h"16#include "DWARFDebugRanges.h"17#include <map>18#include <optional>19#include <set>20#include <vector>2122#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"2324namespace lldb_private::plugin {25namespace dwarf {26class DWARFDeclContext;2728#define DIE_SIBLING_IDX_BITSIZE 312930/// DWARFDebugInfoEntry objects assume that they are living in one big31/// vector and do pointer arithmetic on their this pointers. Don't32/// pass them by value. Due to the way they are constructed in a33/// std::vector, we cannot delete the copy constructor.34class DWARFDebugInfoEntry {35public:36typedef std::vector<DWARFDebugInfoEntry> collection;37typedef collection::iterator iterator;38typedef collection::const_iterator const_iterator;3940DWARFDebugInfoEntry()41: m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0),42m_has_children(false) {}4344explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }45bool operator==(const DWARFDebugInfoEntry &rhs) const;46bool operator!=(const DWARFDebugInfoEntry &rhs) const;4748void BuildFunctionAddressRangeTable(DWARFUnit *cu,49DWARFDebugAranges *debug_aranges) const;5051bool Extract(const DWARFDataExtractor &data, const DWARFUnit &cu,52lldb::offset_t *offset_ptr);5354using Recurse = DWARFBaseDIE::Recurse;55DWARFAttributes GetAttributes(DWARFUnit *cu,56Recurse recurse = Recurse::yes) const {57DWARFAttributes attrs;58GetAttributes(cu, attrs, recurse, 0 /* curr_depth */);59return attrs;60}6162dw_offset_t63GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr,64DWARFFormValue &formValue,65dw_offset_t *end_attr_offset_ptr = nullptr,66bool check_specification_or_abstract_origin = false) const;6768const char *GetAttributeValueAsString(69const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value,70bool check_specification_or_abstract_origin = false) const;7172uint64_t GetAttributeValueAsUnsigned(73const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,74bool check_specification_or_abstract_origin = false) const;7576std::optional<uint64_t> GetAttributeValueAsOptionalUnsigned(77const DWARFUnit *cu, const dw_attr_t attr,78bool check_specification_or_abstract_origin = false) const;7980DWARFDIE GetAttributeValueAsReference(81const DWARFUnit *cu, const dw_attr_t attr,82bool check_specification_or_abstract_origin = false) const;8384uint64_t GetAttributeValueAsAddress(85const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,86bool check_specification_or_abstract_origin = false) const;8788dw_addr_t89GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value,90bool check_specification_or_abstract_origin = false) const;9192bool GetAttributeAddressRange(93const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc,94uint64_t fail_value,95bool check_specification_or_abstract_origin = false) const;9697DWARFRangeList GetAttributeAddressRanges(98DWARFUnit *cu, bool check_hi_lo_pc,99bool check_specification_or_abstract_origin = false) const;100101const char *GetName(const DWARFUnit *cu) const;102103const char *GetMangledName(const DWARFUnit *cu,104bool substitute_name_allowed = true) const;105106const char *GetPubname(const DWARFUnit *cu) const;107108bool GetDIENamesAndRanges(DWARFUnit *cu, const char *&name,109const char *&mangled, DWARFRangeList &rangeList,110std::optional<int> &decl_file,111std::optional<int> &decl_line,112std::optional<int> &decl_column,113std::optional<int> &call_file,114std::optional<int> &call_line,115std::optional<int> &call_column,116DWARFExpressionList *frame_base = nullptr) const;117118const llvm::DWARFAbbreviationDeclaration *119GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const;120121lldb::offset_t GetFirstAttributeOffset() const;122123dw_tag_t Tag() const { return m_tag; }124125bool IsNULL() const { return m_abbr_idx == 0; }126127dw_offset_t GetOffset() const { return m_offset; }128129bool HasChildren() const { return m_has_children; }130131void SetHasChildren(bool b) { m_has_children = b; }132133// We know we are kept in a vector of contiguous entries, so we know134// our parent will be some index behind "this".135DWARFDebugInfoEntry *GetParent() {136return m_parent_idx > 0 ? this - m_parent_idx : nullptr;137}138const DWARFDebugInfoEntry *GetParent() const {139return m_parent_idx > 0 ? this - m_parent_idx : nullptr;140}141// We know we are kept in a vector of contiguous entries, so we know142// our sibling will be some index after "this".143DWARFDebugInfoEntry *GetSibling() {144return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;145}146const DWARFDebugInfoEntry *GetSibling() const {147return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;148}149// We know we are kept in a vector of contiguous entries, so we know150// we don't need to store our child pointer, if we have a child it will151// be the next entry in the list...152DWARFDebugInfoEntry *GetFirstChild() {153return HasChildren() ? this + 1 : nullptr;154}155const DWARFDebugInfoEntry *GetFirstChild() const {156return HasChildren() ? this + 1 : nullptr;157}158159void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }160void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }161162// This function returns true if the variable scope is either163// global or (file-static). It will return false for static variables164// that are local to a function, as they have local scope.165bool IsGlobalOrStaticScopeVariable() const;166167protected:168// Up to 2TB offset within the .debug_info/.debug_types169dw_offset_t m_offset : DW_DIE_OFFSET_MAX_BITSIZE;170// How many to subtract from "this" to get the parent. If zero this die has no171// parent172dw_offset_t m_parent_idx : 64 - DW_DIE_OFFSET_MAX_BITSIZE;173// How many to add to "this" to get the sibling.174// If it is zero, then the DIE doesn't have children,175// or the DWARF claimed it had children but the DIE176// only contained a single NULL terminating child.177uint32_t m_sibling_idx : 31, m_has_children : 1;178uint16_t m_abbr_idx = 0;179/// A copy of the DW_TAG value so we don't have to go through the compile180/// unit abbrev table181dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;182183private:184void GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse,185uint32_t curr_depth) const;186};187} // namespace dwarf188} // namespace lldb_private::plugin189190#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H191192193