Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
39645 views
//===-- DWARFIndex.cpp ----------------------------------------------------===//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#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"9#include "DWARFDebugInfoEntry.h"10#include "DWARFDeclContext.h"11#include "Plugins/Language/ObjC/ObjCLanguage.h"12#include "Plugins/SymbolFile/DWARF/DWARFDIE.h"13#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"1415#include "lldb/Core/Mangled.h"16#include "lldb/Core/Module.h"17#include "lldb/Target/Language.h"1819using namespace lldb_private;20using namespace lldb;21using namespace lldb_private::plugin::dwarf;2223DWARFIndex::~DWARFIndex() = default;2425bool DWARFIndex::ProcessFunctionDIE(26const Module::LookupInfo &lookup_info, DWARFDIE die,27const CompilerDeclContext &parent_decl_ctx,28llvm::function_ref<bool(DWARFDIE die)> callback) {29llvm::StringRef name = lookup_info.GetLookupName().GetStringRef();30FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();3132if (!(name_type_mask & eFunctionNameTypeFull)) {33ConstString name_to_match_against;34if (const char *mangled_die_name = die.GetMangledName()) {35name_to_match_against = ConstString(mangled_die_name);36} else {37SymbolFileDWARF *symbols = die.GetDWARF();38if (ConstString demangled_die_name =39symbols->ConstructFunctionDemangledName(die))40name_to_match_against = demangled_die_name;41}4243if (!lookup_info.NameMatchesLookupInfo(name_to_match_against,44lookup_info.GetLanguageType()))45return true;46}4748// Exit early if we're searching exclusively for methods or selectors and49// we have a context specified (no methods in namespaces).50uint32_t looking_for_nonmethods =51name_type_mask & ~(eFunctionNameTypeMethod | eFunctionNameTypeSelector);52if (!looking_for_nonmethods && parent_decl_ctx.IsValid())53return true;5455// Otherwise, we need to also check that the context matches. If it does not56// match, we do nothing.57if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))58return true;5960// In case of a full match, we just insert everything we find.61if (name_type_mask & eFunctionNameTypeFull && die.GetMangledName() == name)62return callback(die);6364// If looking for ObjC selectors, we need to also check if the name is a65// possible selector.66if (name_type_mask & eFunctionNameTypeSelector &&67ObjCLanguage::IsPossibleObjCMethodName(die.GetName()))68return callback(die);6970bool looking_for_methods = name_type_mask & lldb::eFunctionNameTypeMethod;71bool looking_for_functions = name_type_mask & lldb::eFunctionNameTypeBase;72if (looking_for_methods || looking_for_functions) {73// If we're looking for either methods or functions, we definitely want this74// die. Otherwise, only keep it if the die type matches what we are75// searching for.76if ((looking_for_methods && looking_for_functions) ||77looking_for_methods == die.IsMethod())78return callback(die);79}8081return true;82}8384DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(85const DWARFIndex &index, llvm::function_ref<bool(DWARFDIE die)> callback,86llvm::StringRef name)87: m_index(index),88m_dwarf(*llvm::cast<SymbolFileDWARF>(89index.m_module.GetSymbolFile()->GetBackingSymbolFile())),90m_callback(callback), m_name(name) {}9192bool DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const {93if (DWARFDIE die = m_dwarf.GetDIE(ref))94return m_callback(die);95m_index.ReportInvalidDIERef(ref, m_name);96return true;97}9899bool DWARFIndex::DIERefCallbackImpl::operator()(100const llvm::AppleAcceleratorTable::Entry &entry) const {101return this->operator()(DIERef(std::nullopt, DIERef::Section::DebugInfo,102*entry.getDIESectionOffset()));103}104105void DWARFIndex::ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const {106m_module.ReportErrorIfModifyDetected(107"the DWARF debug information has been modified (accelerator table had "108"bad die {0:x16} for '{1}')\n",109ref.die_offset(), name.str().c_str());110}111112void DWARFIndex::GetFullyQualifiedType(113const DWARFDeclContext &context,114llvm::function_ref<bool(DWARFDIE die)> callback) {115GetTypes(context, [&](DWARFDIE die) {116return GetFullyQualifiedTypeImpl(context, die, callback);117});118}119120bool DWARFIndex::GetFullyQualifiedTypeImpl(121const DWARFDeclContext &context, DWARFDIE die,122llvm::function_ref<bool(DWARFDIE die)> callback) {123DWARFDeclContext dwarf_decl_ctx = die.GetDWARFDeclContext();124if (dwarf_decl_ctx == context)125return callback(die);126return true;127}128129130