LLDB  mainline
AppleDWARFIndex.cpp
Go to the documentation of this file.
1 //===-- AppleDWARFIndex.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 
14 
15 #include "lldb/Core/Module.h"
16 #include "lldb/Symbol/Function.h"
17 
18 using namespace lldb_private;
19 using namespace lldb;
20 
21 std::unique_ptr<AppleDWARFIndex> AppleDWARFIndex::Create(
22  Module &module, DWARFDataExtractor apple_names,
23  DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types,
24  DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str) {
25  auto apple_names_table_up = llvm::make_unique<DWARFMappedHash::MemoryTable>(
26  apple_names, debug_str, ".apple_names");
27  if (!apple_names_table_up->IsValid())
28  apple_names_table_up.reset();
29 
30  auto apple_namespaces_table_up =
31  llvm::make_unique<DWARFMappedHash::MemoryTable>(
32  apple_namespaces, debug_str, ".apple_namespaces");
33  if (!apple_namespaces_table_up->IsValid())
34  apple_namespaces_table_up.reset();
35 
36  auto apple_types_table_up = llvm::make_unique<DWARFMappedHash::MemoryTable>(
37  apple_types, debug_str, ".apple_types");
38  if (!apple_types_table_up->IsValid())
39  apple_types_table_up.reset();
40 
41  auto apple_objc_table_up = llvm::make_unique<DWARFMappedHash::MemoryTable>(
42  apple_objc, debug_str, ".apple_objc");
43  if (!apple_objc_table_up->IsValid())
44  apple_objc_table_up.reset();
45 
46  if (apple_names_table_up || apple_names_table_up || apple_types_table_up ||
47  apple_objc_table_up)
48  return llvm::make_unique<AppleDWARFIndex>(
49  module, std::move(apple_names_table_up),
50  std::move(apple_namespaces_table_up), std::move(apple_types_table_up),
51  std::move(apple_objc_table_up));
52 
53  return nullptr;
54 }
55 
57  if (m_apple_names_up)
58  m_apple_names_up->FindByName(basename.GetStringRef(), offsets);
59 }
60 
62  DIEArray &offsets) {
63  if (!m_apple_names_up)
64  return;
65 
67  if (m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data))
68  DWARFMappedHash::ExtractDIEArray(hash_data, offsets);
69 }
70 
72  DIEArray &offsets) {
73  if (!m_apple_names_up)
74  return;
75 
77  if (m_apple_names_up->AppendAllDIEsInRange(
78  cu.GetOffset(), cu.GetNextCompileUnitOffset(), hash_data))
79  DWARFMappedHash::ExtractDIEArray(hash_data, offsets);
80 }
81 
83  DIEArray &offsets) {
84  if (m_apple_objc_up)
85  m_apple_objc_up->FindByName(class_name.GetStringRef(), offsets);
86 }
87 
89  bool must_be_implementation,
90  DIEArray &offsets) {
91  if (m_apple_types_up) {
92  m_apple_types_up->FindCompleteObjCClassByName(
93  class_name.GetStringRef(), offsets, must_be_implementation);
94  }
95 }
96 
98  if (m_apple_types_up)
99  m_apple_types_up->FindByName(name.GetStringRef(), offsets);
100 }
101 
103  DIEArray &offsets) {
104  if (!m_apple_types_up)
105  return;
106 
109  const bool has_tag = m_apple_types_up->GetHeader().header_data.ContainsAtom(
111  const bool has_qualified_name_hash =
112  m_apple_types_up->GetHeader().header_data.ContainsAtom(
114  const ConstString type_name(context[0].name);
115  const dw_tag_t tag = context[0].tag;
116  if (has_tag && has_qualified_name_hash) {
117  const char *qualified_name = context.GetQualifiedName();
118  const uint32_t qualified_name_hash = llvm::djbHash(qualified_name);
119  if (log)
120  m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()");
121  m_apple_types_up->FindByNameAndTagAndQualifiedNameHash(
122  type_name.GetStringRef(), tag, qualified_name_hash, offsets);
123  } else if (has_tag) {
124  if (log)
125  m_module.LogMessage(log, "FindByNameAndTag()");
126  m_apple_types_up->FindByNameAndTag(type_name.GetStringRef(), tag, offsets);
127  } else
128  m_apple_types_up->FindByName(type_name.GetStringRef(), offsets);
129 }
130 
132  if (m_apple_namespaces_up)
133  m_apple_namespaces_up->FindByName(name.GetStringRef(), offsets);
134 }
135 
137  const CompilerDeclContext &parent_decl_ctx,
138  uint32_t name_type_mask,
139  std::vector<DWARFDIE> &dies) {
140  DIEArray offsets;
141  m_apple_names_up->FindByName(name.GetStringRef(), offsets);
142  for (const DIERef &die_ref : offsets) {
143  ProcessFunctionDIE(name.GetStringRef(), die_ref, info, parent_decl_ctx,
144  name_type_mask, dies);
145  }
146 }
147 
149  DIEArray &offsets) {
150  if (!m_apple_names_up)
151  return;
152 
154  if (m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data))
155  DWARFMappedHash::ExtractDIEArray(hash_data, offsets);
156 }
157 
159  llvm::StringRef name) {
160  m_module.ReportErrorIfModifyDetected(
161  "the DWARF debug information has been modified (accelerator table had "
162  "bad die 0x%8.8x for '%s')\n",
163  offset, name.str().c_str());
164 }
165 
167  if (m_apple_names_up)
168  s.PutCString(".apple_names index present\n");
169  if (m_apple_namespaces_up)
170  s.PutCString(".apple_namespaces index present\n");
171  if (m_apple_types_up)
172  s.PutCString(".apple_types index present\n");
173  if (m_apple_objc_up)
174  s.PutCString(".apple_objc index present\n");
175  // TODO: Dump index contents
176 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
const char * GetQualifiedName() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
static void ExtractDIEArray(const DIEInfoArray &die_info_array, DIEArray &die_offsets)
void Dump(Stream &s) override
void GetTypes(ConstString name, DIEArray &offsets) override
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
Definition: DIERef.h:18
void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, DIEArray &offsets) override
std::vector< DIERef > DIEArray
Definition: DIERef.h:51
void GetNamespaces(ConstString name, DIEArray &offsets) override
void ReportInvalidDIEOffset(dw_offset_t offset, llvm::StringRef name) override
static Log * GetLogIfAny(uint32_t mask)
#define DWARF_LOG_LOOKUPS
dw_offset_t GetNextCompileUnitOffset() const
Definition: DWARFUnit.cpp:369
void GetGlobalVariables(ConstString basename, DIEArray &offsets) override
Finds global variables with the given base name.
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:109
static std::unique_ptr< AppleDWARFIndex > Create(Module &module, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str)
void GetFunctions(ConstString name, DWARFDebugInfo &info, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector< DWARFDIE > &dies) override
std::vector< DIEInfo > DIEInfoArray
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:233
#define DWARF_LOG_TYPE_COMPLETION
void GetObjCMethods(ConstString class_name, DIEArray &offsets) override
dw_offset_t GetOffset() const
Definition: DWARFUnit.h:76
A uniqued constant string class.
Definition: ConstString.h:38
char * basename(char *path)
Definition: SBAddress.h:15