1 //===-- DWARFIndex.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" 10 #include "Plugins/Language/ObjC/ObjCLanguage.h" 11 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h" 12 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" 13 14 using namespace lldb_private; 15 using namespace lldb; 16 17 DWARFIndex::~DWARFIndex() = default; 18 19 void DWARFIndex::ProcessFunctionDIE(llvm::StringRef name, DIERef ref, 20 SymbolFileDWARF &dwarf, 21 const CompilerDeclContext &parent_decl_ctx, 22 uint32_t name_type_mask, 23 std::vector<DWARFDIE> &dies) { 24 DWARFDIE die = dwarf.GetDIE(ref); 25 if (!die) { 26 ReportInvalidDIERef(ref, name); 27 return; 28 } 29 30 // Exit early if we're searching exclusively for methods or selectors and 31 // we have a context specified (no methods in namespaces). 32 uint32_t looking_for_nonmethods = 33 name_type_mask & ~(eFunctionNameTypeMethod | eFunctionNameTypeSelector); 34 if (!looking_for_nonmethods && parent_decl_ctx.IsValid()) 35 return; 36 37 // Otherwise, we need to also check that the context matches. If it does not 38 // match, we do nothing. 39 if (!SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die)) 40 return; 41 42 // In case of a full match, we just insert everything we find. 43 if (name_type_mask & eFunctionNameTypeFull) { 44 dies.push_back(die); 45 return; 46 } 47 48 // If looking for ObjC selectors, we need to also check if the name is a 49 // possible selector. 50 if (name_type_mask & eFunctionNameTypeSelector && 51 ObjCLanguage::IsPossibleObjCMethodName(die.GetName())) { 52 dies.push_back(die); 53 return; 54 } 55 56 bool looking_for_methods = name_type_mask & lldb::eFunctionNameTypeMethod; 57 bool looking_for_functions = name_type_mask & lldb::eFunctionNameTypeBase; 58 if (looking_for_methods || looking_for_functions) { 59 // If we're looking for either methods or functions, we definitely want this 60 // die. Otherwise, only keep it if the die type matches what we are 61 // searching for. 62 if ((looking_for_methods && looking_for_functions) || 63 looking_for_methods == die.IsMethod()) 64 dies.push_back(die); 65 } 66 } 67