LLDB  mainline
DWARFIndex.cpp
Go to the documentation of this file.
1 //===-- DWARFIndex.cpp ----------------------------------------------------===//
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 
13 
14 #include "lldb/Core/Module.h"
15 
16 using namespace lldb_private;
17 using namespace lldb;
18 
19 DWARFIndex::~DWARFIndex() = default;
20 
22  llvm::StringRef name, DIERef ref, SymbolFileDWARF &dwarf,
23  const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask,
24  llvm::function_ref<bool(DWARFDIE die)> callback) {
25  DWARFDIE die = dwarf.GetDIE(ref);
26  if (!die) {
27  ReportInvalidDIERef(ref, name);
28  return true;
29  }
30 
31  // Exit early if we're searching exclusively for methods or selectors and
32  // we have a context specified (no methods in namespaces).
33  uint32_t looking_for_nonmethods =
34  name_type_mask & ~(eFunctionNameTypeMethod | eFunctionNameTypeSelector);
35  if (!looking_for_nonmethods && parent_decl_ctx.IsValid())
36  return true;
37 
38  // Otherwise, we need to also check that the context matches. If it does not
39  // match, we do nothing.
40  if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die))
41  return true;
42 
43  // In case of a full match, we just insert everything we find.
44  if (name_type_mask & eFunctionNameTypeFull && die.GetMangledName() == name)
45  return callback(die);
46 
47  // If looking for ObjC selectors, we need to also check if the name is a
48  // possible selector.
49  if (name_type_mask & eFunctionNameTypeSelector &&
51  return callback(die);
52 
53  bool looking_for_methods = name_type_mask & lldb::eFunctionNameTypeMethod;
54  bool looking_for_functions = name_type_mask & lldb::eFunctionNameTypeBase;
55  if (looking_for_methods || looking_for_functions) {
56  // If we're looking for either methods or functions, we definitely want this
57  // die. Otherwise, only keep it if the die type matches what we are
58  // searching for.
59  if ((looking_for_methods && looking_for_functions) ||
60  looking_for_methods == die.IsMethod())
61  return callback(die);
62  }
63 
64  return true;
65 }
66 
68  const DWARFIndex &index, llvm::function_ref<bool(DWARFDIE die)> callback,
69  llvm::StringRef name)
70  : m_index(index),
71  m_dwarf(*llvm::cast<SymbolFileDWARF>(index.m_module.GetSymbolFile())),
72  m_callback(callback), m_name(name) {}
73 
75  if (DWARFDIE die = m_dwarf.GetDIE(ref))
76  return m_callback(die);
77  m_index.ReportInvalidDIERef(ref, m_name);
78  return true;
79 }
80 
81 void DWARFIndex::ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const {
83  "the DWARF debug information has been modified (accelerator table had "
84  "bad die 0x%8.8x for '%s')\n",
85  ref.die_offset(), name.str().c_str());
86 }
DIERef
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:26
llvm
Definition: Debugger.h:49
DWARFDIE.h
Module.h
SymbolFileDWARF
Definition: SymbolFileDWARF.h:58
SymbolFileDWARF.h
lldb_private::DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl
DIERefCallbackImpl(const DWARFIndex &index, llvm::function_ref< bool(DWARFDIE die)> callback, llvm::StringRef name)
Definition: DWARFIndex.cpp:67
DIERef::die_offset
dw_offset_t die_offset() const
Definition: DIERef.h:45
lldb_private::Module::ReportErrorIfModifyDetected
void void void void void ReportErrorIfModifyDetected(const char *format,...) __attribute__((format(printf
Definition: Module.cpp:1132
DWARFDIE
Definition: DWARFDIE.h:16
lldb_private::DWARFIndex
Definition: DWARFIndex.h:20
lldb_private::CompilerDeclContext::IsValid
bool IsValid() const
Definition: CompilerDeclContext.h:55
dwarf
Definition: ABISysV_arc.cpp:61
DWARFDIE::GetName
void GetName(lldb_private::Stream &s) const
Definition: DWARFDIE.cpp:229
DWARFDIE::GetMangledName
const char * GetMangledName() const
Definition: DWARFDIE.cpp:203
ObjCLanguage.h
SymbolFileDWARF::DIEInDeclContext
static bool DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx, const DWARFDIE &die)
Definition: SymbolFileDWARF.cpp:2251
lldb_private::DWARFIndex::~DWARFIndex
virtual ~DWARFIndex()
lldb_private::DWARFIndex::DIERefCallbackImpl::operator()
bool operator()(DIERef ref) const
Definition: DWARFIndex.cpp:74
lldb_private::DWARFIndex::ReportInvalidDIERef
void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const
Definition: DWARFIndex.cpp:81
lldb_private::DWARFIndex::ProcessFunctionDIE
bool ProcessFunctionDIE(llvm::StringRef name, DIERef ref, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, llvm::function_ref< bool(DWARFDIE die)> callback)
Helper function implementing common logic for processing function dies.
Definition: DWARFIndex.cpp:21
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
uint32_t
lldb_private::DWARFIndex::m_module
Module & m_module
Definition: DWARFIndex.h:66
DWARFDIE::GetDIE
DWARFDIE GetDIE(dw_offset_t die_offset) const
Definition: DWARFDIE.cpp:122
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ObjCLanguage::IsPossibleObjCMethodName
static bool IsPossibleObjCMethodName(const char *name)
Definition: ObjCLanguage.h:138
DWARFDIE::IsMethod
bool IsMethod() const
Definition: DWARFDIE.cpp:432
lldb
Definition: SBAddress.h:15
DWARFIndex.h