LLDB  mainline
ManualDWARFIndex.cpp
Go to the documentation of this file.
1 //===-- ManualDWARFIndex.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 
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/Progress.h"
19 #include "lldb/Symbol/ObjectFile.h"
22 #include "lldb/Utility/Stream.h"
23 #include "lldb/Utility/Timer.h"
24 #include "llvm/Support/FormatVariadic.h"
25 #include "llvm/Support/ThreadPool.h"
26 
27 using namespace lldb_private;
28 using namespace lldb;
29 using namespace lldb_private::dwarf;
30 
32  if (m_indexed)
33  return;
34  m_indexed = true;
35 
36  ElapsedTime elapsed(m_index_time);
37  LLDB_SCOPED_TIMERF("%p", static_cast<void *>(m_dwarf));
38  if (LoadFromCache()) {
39  m_dwarf->SetDebugInfoIndexWasLoadedFromCache();
40  return;
41  }
42 
43  DWARFDebugInfo &main_info = m_dwarf->DebugInfo();
44  SymbolFileDWARFDwo *dwp_dwarf = m_dwarf->GetDwpSymbolFile().get();
45  DWARFDebugInfo *dwp_info = dwp_dwarf ? &dwp_dwarf->DebugInfo() : nullptr;
46 
47  std::vector<DWARFUnit *> units_to_index;
48  units_to_index.reserve(main_info.GetNumUnits() +
49  (dwp_info ? dwp_info->GetNumUnits() : 0));
50 
51  // Process all units in the main file, as well as any type units in the dwp
52  // file. Type units in dwo files are handled when we reach the dwo file in
53  // IndexUnit.
54  for (size_t U = 0; U < main_info.GetNumUnits(); ++U) {
55  DWARFUnit *unit = main_info.GetUnitAtIndex(U);
56  if (unit && m_units_to_avoid.count(unit->GetOffset()) == 0)
57  units_to_index.push_back(unit);
58  }
59  if (dwp_info && dwp_info->ContainsTypeUnits()) {
60  for (size_t U = 0; U < dwp_info->GetNumUnits(); ++U) {
61  if (auto *tu = llvm::dyn_cast<DWARFTypeUnit>(dwp_info->GetUnitAtIndex(U)))
62  units_to_index.push_back(tu);
63  }
64  }
65 
66  if (units_to_index.empty())
67  return;
68 
69  StreamString module_desc;
70  m_module.GetDescription(module_desc.AsRawOstream(),
72 
73  // Include 2 passes per unit to index for extracting DIEs from the unit and
74  // indexing the unit, and then 8 extra entries for finalizing each index set.
75  const uint64_t total_progress = units_to_index.size() * 2 + 8;
76  Progress progress(
77  llvm::formatv("Manually indexing DWARF for {0}", module_desc.GetData()),
78  total_progress);
79 
80  std::vector<IndexSet> sets(units_to_index.size());
81 
82  // Keep memory down by clearing DIEs for any units if indexing
83  // caused us to load the unit's DIEs.
84  std::vector<llvm::Optional<DWARFUnit::ScopedExtractDIEs>> clear_cu_dies(
85  units_to_index.size());
86  auto parser_fn = [&](size_t cu_idx) {
87  IndexUnit(*units_to_index[cu_idx], dwp_dwarf, sets[cu_idx]);
88  progress.Increment();
89  };
90 
91  auto extract_fn = [&](size_t cu_idx) {
92  clear_cu_dies[cu_idx] = units_to_index[cu_idx]->ExtractDIEsScoped();
93  progress.Increment();
94  };
95 
96  // Share one thread pool across operations to avoid the overhead of
97  // recreating the threads.
98  llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
99 
100  // Create a task runner that extracts dies for each DWARF unit in a
101  // separate thread.
102  // First figure out which units didn't have their DIEs already
103  // parsed and remember this. If no DIEs were parsed prior to this index
104  // function call, we are going to want to clear the CU dies after we are
105  // done indexing to make sure we don't pull in all DWARF dies, but we need
106  // to wait until all units have been indexed in case a DIE in one
107  // unit refers to another and the indexes accesses those DIEs.
108  for (size_t i = 0; i < units_to_index.size(); ++i)
109  task_group.async(extract_fn, i);
110  task_group.wait();
111 
112  // Now create a task runner that can index each DWARF unit in a
113  // separate thread so we can index quickly.
114  for (size_t i = 0; i < units_to_index.size(); ++i)
115  task_group.async(parser_fn, i);
116  task_group.wait();
117 
118  auto finalize_fn = [this, &sets, &progress](NameToDIE(IndexSet::*index)) {
119  NameToDIE &result = m_set.*index;
120  for (auto &set : sets)
121  result.Append(set.*index);
122  result.Finalize();
123  progress.Increment();
124  };
125 
126  task_group.async(finalize_fn, &IndexSet::function_basenames);
127  task_group.async(finalize_fn, &IndexSet::function_fullnames);
128  task_group.async(finalize_fn, &IndexSet::function_methods);
129  task_group.async(finalize_fn, &IndexSet::function_selectors);
130  task_group.async(finalize_fn, &IndexSet::objc_class_selectors);
131  task_group.async(finalize_fn, &IndexSet::globals);
132  task_group.async(finalize_fn, &IndexSet::types);
133  task_group.async(finalize_fn, &IndexSet::namespaces);
134  task_group.wait();
135 
136  SaveToCache();
137 }
138 
140  IndexSet &set) {
141  Log *log = GetLog(DWARFLog::Lookups);
142 
143  if (log) {
144  m_module.LogMessage(
145  log, "ManualDWARFIndex::IndexUnit for unit at .debug_info[0x%8.8x]",
146  unit.GetOffset());
147  }
148 
149  const LanguageType cu_language = SymbolFileDWARF::GetLanguage(unit);
150 
151  // First check if the unit has a DWO ID. If it does then we only want to index
152  // the .dwo file or nothing at all. If we have a compile unit where we can't
153  // locate the .dwo/.dwp file we don't want to index anything from the skeleton
154  // compile unit because it is usally has no children unless
155  // -fsplit-dwarf-inlining was used at compile time. This option will add a
156  // copy of all DW_TAG_subprogram and any contained DW_TAG_inline_subroutine
157  // DIEs so that symbolication will still work in the absence of the .dwo/.dwp
158  // file, but the functions have no return types and all arguments and locals
159  // have been removed. So we don't want to index any of these hacked up
160  // function types. Types can still exist in the skeleton compile unit DWARF
161  // though as some functions have template parameter types and other things
162  // that cause extra copies of types to be included, but we should find these
163  // types in the .dwo file only as methods could have return types removed and
164  // we don't have to index incomplete types from the skeletone compile unit.
165  if (unit.GetDWOId()) {
166  if (SymbolFileDWARFDwo *dwo_symbol_file = unit.GetDwoSymbolFile()) {
167  // Type units in a dwp file are indexed separately, so we just need to
168  // process the split unit here. However, if the split unit is in a dwo file,
169  // then we need to process type units here.
170  if (dwo_symbol_file == dwp) {
171  IndexUnitImpl(unit.GetNonSkeletonUnit(), cu_language, set);
172  } else {
173  DWARFDebugInfo &dwo_info = dwo_symbol_file->DebugInfo();
174  for (size_t i = 0; i < dwo_info.GetNumUnits(); ++i)
175  IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), cu_language, set);
176  }
177  }
178  } else {
179  // We either have a normal compile unit which we want to index.
180  IndexUnitImpl(unit, cu_language, set);
181  }
182 }
183 
185  const LanguageType cu_language,
186  IndexSet &set) {
187  for (const DWARFDebugInfoEntry &die : unit.dies()) {
188  const dw_tag_t tag = die.Tag();
189 
190  switch (tag) {
191  case DW_TAG_array_type:
192  case DW_TAG_base_type:
193  case DW_TAG_class_type:
194  case DW_TAG_constant:
195  case DW_TAG_enumeration_type:
196  case DW_TAG_inlined_subroutine:
197  case DW_TAG_namespace:
198  case DW_TAG_string_type:
199  case DW_TAG_structure_type:
200  case DW_TAG_subprogram:
201  case DW_TAG_subroutine_type:
202  case DW_TAG_typedef:
203  case DW_TAG_union_type:
204  case DW_TAG_unspecified_type:
205  case DW_TAG_variable:
206  break;
207 
208  default:
209  continue;
210  }
211 
212  DWARFAttributes attributes;
213  const char *name = nullptr;
214  const char *mangled_cstr = nullptr;
215  bool is_declaration = false;
216  // bool is_artificial = false;
217  bool has_address = false;
218  bool has_location_or_const_value = false;
219  bool is_global_or_static_variable = false;
220 
221  DWARFFormValue specification_die_form;
222  const size_t num_attributes = die.GetAttributes(&unit, attributes);
223  if (num_attributes > 0) {
224  for (uint32_t i = 0; i < num_attributes; ++i) {
225  dw_attr_t attr = attributes.AttributeAtIndex(i);
226  DWARFFormValue form_value;
227  switch (attr) {
228  case DW_AT_name:
229  if (attributes.ExtractFormValueAtIndex(i, form_value))
230  name = form_value.AsCString();
231  break;
232 
233  case DW_AT_declaration:
234  if (attributes.ExtractFormValueAtIndex(i, form_value))
235  is_declaration = form_value.Unsigned() != 0;
236  break;
237 
238  case DW_AT_MIPS_linkage_name:
239  case DW_AT_linkage_name:
240  if (attributes.ExtractFormValueAtIndex(i, form_value))
241  mangled_cstr = form_value.AsCString();
242  break;
243 
244  case DW_AT_low_pc:
245  case DW_AT_high_pc:
246  case DW_AT_ranges:
247  has_address = true;
248  break;
249 
250  case DW_AT_entry_pc:
251  has_address = true;
252  break;
253 
254  case DW_AT_location:
255  case DW_AT_const_value:
256  has_location_or_const_value = true;
257  is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable();
258 
259  break;
260 
261  case DW_AT_specification:
262  if (attributes.ExtractFormValueAtIndex(i, form_value))
263  specification_die_form = form_value;
264  break;
265  }
266  }
267  }
268 
269  DIERef ref = *DWARFDIE(&unit, &die).GetDIERef();
270  switch (tag) {
271  case DW_TAG_inlined_subroutine:
272  case DW_TAG_subprogram:
273  if (has_address) {
274  if (name) {
275  bool is_objc_method = false;
276  if (cu_language == eLanguageTypeObjC ||
277  cu_language == eLanguageTypeObjC_plus_plus) {
278  ObjCLanguage::MethodName objc_method(name, true);
279  if (objc_method.IsValid(true)) {
280  is_objc_method = true;
281  ConstString class_name_with_category(
282  objc_method.GetClassNameWithCategory());
283  ConstString objc_selector_name(objc_method.GetSelector());
284  ConstString objc_fullname_no_category_name(
285  objc_method.GetFullNameWithoutCategory(true));
286  ConstString class_name_no_category(objc_method.GetClassName());
287  set.function_fullnames.Insert(ConstString(name), ref);
288  if (class_name_with_category)
289  set.objc_class_selectors.Insert(class_name_with_category, ref);
290  if (class_name_no_category &&
291  class_name_no_category != class_name_with_category)
292  set.objc_class_selectors.Insert(class_name_no_category, ref);
293  if (objc_selector_name)
294  set.function_selectors.Insert(objc_selector_name, ref);
295  if (objc_fullname_no_category_name)
296  set.function_fullnames.Insert(objc_fullname_no_category_name,
297  ref);
298  }
299  }
300  // If we have a mangled name, then the DW_AT_name attribute is
301  // usually the method name without the class or any parameters
302  bool is_method = DWARFDIE(&unit, &die).IsMethod();
303 
304  if (is_method)
305  set.function_methods.Insert(ConstString(name), ref);
306  else
307  set.function_basenames.Insert(ConstString(name), ref);
308 
309  if (!is_method && !mangled_cstr && !is_objc_method)
310  set.function_fullnames.Insert(ConstString(name), ref);
311  }
312  if (mangled_cstr) {
313  // Make sure our mangled name isn't the same string table entry as
314  // our name. If it starts with '_', then it is ok, else compare the
315  // string to make sure it isn't the same and we don't end up with
316  // duplicate entries
317  if (name && name != mangled_cstr &&
318  ((mangled_cstr[0] == '_') ||
319  (::strcmp(name, mangled_cstr) != 0))) {
320  set.function_fullnames.Insert(ConstString(mangled_cstr), ref);
321  }
322  }
323  }
324  break;
325 
326  case DW_TAG_array_type:
327  case DW_TAG_base_type:
328  case DW_TAG_class_type:
329  case DW_TAG_constant:
330  case DW_TAG_enumeration_type:
331  case DW_TAG_string_type:
332  case DW_TAG_structure_type:
333  case DW_TAG_subroutine_type:
334  case DW_TAG_typedef:
335  case DW_TAG_union_type:
336  case DW_TAG_unspecified_type:
337  if (name && !is_declaration)
338  set.types.Insert(ConstString(name), ref);
339  if (mangled_cstr && !is_declaration)
340  set.types.Insert(ConstString(mangled_cstr), ref);
341  break;
342 
343  case DW_TAG_namespace:
344  if (name)
345  set.namespaces.Insert(ConstString(name), ref);
346  break;
347 
348  case DW_TAG_variable:
349  if (name && has_location_or_const_value && is_global_or_static_variable) {
350  set.globals.Insert(ConstString(name), ref);
351  // Be sure to include variables by their mangled and demangled names if
352  // they have any since a variable can have a basename "i", a mangled
353  // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name
354  // "(anonymous namespace)::i"...
355 
356  // Make sure our mangled name isn't the same string table entry as our
357  // name. If it starts with '_', then it is ok, else compare the string
358  // to make sure it isn't the same and we don't end up with duplicate
359  // entries
360  if (mangled_cstr && name != mangled_cstr &&
361  ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) {
362  set.globals.Insert(ConstString(mangled_cstr), ref);
363  }
364  }
365  break;
366 
367  default:
368  continue;
369  }
370  }
371 }
372 
374  ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) {
375  Index();
376  m_set.globals.Find(basename,
377  DIERefCallback(callback, basename.GetStringRef()));
378 }
379 
381  const RegularExpression &regex,
382  llvm::function_ref<bool(DWARFDIE die)> callback) {
383  Index();
384  m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText()));
385 }
386 
388  DWARFUnit &unit, llvm::function_ref<bool(DWARFDIE die)> callback) {
390  Index();
391  m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback));
392 }
393 
395  ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
396  Index();
397  m_set.objc_class_selectors.Find(
398  class_name, DIERefCallback(callback, class_name.GetStringRef()));
399 }
400 
402  ConstString class_name, bool must_be_implementation,
403  llvm::function_ref<bool(DWARFDIE die)> callback) {
404  Index();
405  m_set.types.Find(class_name,
406  DIERefCallback(callback, class_name.GetStringRef()));
407 }
408 
410  ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
411  Index();
412  m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef()));
413 }
414 
416  const DWARFDeclContext &context,
417  llvm::function_ref<bool(DWARFDIE die)> callback) {
418  Index();
419  auto name = context[0].name;
420  m_set.types.Find(ConstString(name),
421  DIERefCallback(callback, llvm::StringRef(name)));
422 }
423 
425  ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) {
426  Index();
427  m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef()));
428 }
429 
431  const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
432  const CompilerDeclContext &parent_decl_ctx,
433  llvm::function_ref<bool(DWARFDIE die)> callback) {
434  Index();
435  ConstString name = lookup_info.GetLookupName();
436  FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
437 
438  if (name_type_mask & eFunctionNameTypeFull) {
439  if (!m_set.function_fullnames.Find(
440  name, DIERefCallback(
441  [&](DWARFDIE die) {
442  if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
443  die))
444  return true;
445  return callback(die);
446  },
447  name.GetStringRef())))
448  return;
449  }
450  if (name_type_mask & eFunctionNameTypeBase) {
451  if (!m_set.function_basenames.Find(
452  name, DIERefCallback(
453  [&](DWARFDIE die) {
454  if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
455  die))
456  return true;
457  return callback(die);
458  },
459  name.GetStringRef())))
460  return;
461  }
462 
463  if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) {
464  if (!m_set.function_methods.Find(
465  name, DIERefCallback(callback, name.GetStringRef())))
466  return;
467  }
468 
469  if (name_type_mask & eFunctionNameTypeSelector &&
470  !parent_decl_ctx.IsValid()) {
471  if (!m_set.function_selectors.Find(
472  name, DIERefCallback(callback, name.GetStringRef())))
473  return;
474  }
475 }
476 
478  const RegularExpression &regex,
479  llvm::function_ref<bool(DWARFDIE die)> callback) {
480  Index();
481 
482  if (!m_set.function_basenames.Find(regex,
483  DIERefCallback(callback, regex.GetText())))
484  return;
485  if (!m_set.function_fullnames.Find(regex,
486  DIERefCallback(callback, regex.GetText())))
487  return;
488 }
489 
491  s.Format("Manual DWARF index for ({0}) '{1:F}':",
492  m_module.GetArchitecture().GetArchitectureName(),
493  m_module.GetObjectFile()->GetFileSpec());
494  s.Printf("\nFunction basenames:\n");
495  m_set.function_basenames.Dump(&s);
496  s.Printf("\nFunction fullnames:\n");
497  m_set.function_fullnames.Dump(&s);
498  s.Printf("\nFunction methods:\n");
499  m_set.function_methods.Dump(&s);
500  s.Printf("\nFunction selectors:\n");
501  m_set.function_selectors.Dump(&s);
502  s.Printf("\nObjective-C class selectors:\n");
503  m_set.objc_class_selectors.Dump(&s);
504  s.Printf("\nGlobals and statics:\n");
505  m_set.globals.Dump(&s);
506  s.Printf("\nTypes:\n");
507  m_set.types.Dump(&s);
508  s.Printf("\nNamespaces:\n");
509  m_set.namespaces.Dump(&s);
510 }
511 
512 constexpr llvm::StringLiteral kIdentifierManualDWARFIndex("DIDX");
513 // Define IDs for the different tables when encoding and decoding the
514 // ManualDWARFIndex NameToDIE objects so we can avoid saving any empty maps.
515 enum DataID {
524  kDataIDEnd = 255u,
525 
526 };
528 
530  lldb::offset_t *offset_ptr) {
531  StringTableReader strtab;
532  // We now decode the string table for all strings in the data cache file.
533  if (!strtab.Decode(data, offset_ptr))
534  return false;
535 
536  llvm::StringRef identifier((const char *)data.GetData(offset_ptr, 4), 4);
537  if (identifier != kIdentifierManualDWARFIndex)
538  return false;
539  const uint32_t version = data.GetU32(offset_ptr);
540  if (version != CURRENT_CACHE_VERSION)
541  return false;
542 
543  bool done = false;
544  while (!done) {
545  switch (data.GetU8(offset_ptr)) {
546  default:
547  // If we got here, this is not expected, we expect the data IDs to match
548  // one of the values from the DataID enumeration.
549  return false;
551  if (!function_basenames.Decode(data, offset_ptr, strtab))
552  return false;
553  break;
555  if (!function_fullnames.Decode(data, offset_ptr, strtab))
556  return false;
557  break;
559  if (!function_methods.Decode(data, offset_ptr, strtab))
560  return false;
561  break;
563  if (!function_selectors.Decode(data, offset_ptr, strtab))
564  return false;
565  break;
567  if (!objc_class_selectors.Decode(data, offset_ptr, strtab))
568  return false;
569  break;
570  case kDataIDGlobals:
571  if (!globals.Decode(data, offset_ptr, strtab))
572  return false;
573  break;
574  case kDataIDTypes:
575  if (!types.Decode(data, offset_ptr, strtab))
576  return false;
577  break;
578  case kDataIDNamespaces:
579  if (!namespaces.Decode(data, offset_ptr, strtab))
580  return false;
581  break;
582  case kDataIDEnd:
583  // We got to the end of our NameToDIE encodings.
584  done = true;
585  break;
586  }
587  }
588  // Success!
589  return true;
590 }
591 
592 void ManualDWARFIndex::IndexSet::Encode(DataEncoder &encoder) const {
593  ConstStringTable strtab;
594 
595  // Encoder the DWARF index into a separate encoder first. This allows us
596  // gather all of the strings we willl need in "strtab" as we will need to
597  // write the string table out before the symbol table.
598  DataEncoder index_encoder(encoder.GetByteOrder(),
599  encoder.GetAddressByteSize());
600 
601  index_encoder.AppendData(kIdentifierManualDWARFIndex);
602  // Encode the data version.
603  index_encoder.AppendU32(CURRENT_CACHE_VERSION);
604 
605  if (!function_basenames.IsEmpty()) {
606  index_encoder.AppendU8(kDataIDFunctionBasenames);
607  function_basenames.Encode(index_encoder, strtab);
608  }
609  if (!function_fullnames.IsEmpty()) {
610  index_encoder.AppendU8(kDataIDFunctionFullnames);
611  function_fullnames.Encode(index_encoder, strtab);
612  }
613  if (!function_methods.IsEmpty()) {
614  index_encoder.AppendU8(kDataIDFunctionMethods);
615  function_methods.Encode(index_encoder, strtab);
616  }
617  if (!function_selectors.IsEmpty()) {
618  index_encoder.AppendU8(kDataIDFunctionSelectors);
619  function_selectors.Encode(index_encoder, strtab);
620  }
621  if (!objc_class_selectors.IsEmpty()) {
622  index_encoder.AppendU8(kDataIDFunctionObjcClassSelectors);
623  objc_class_selectors.Encode(index_encoder, strtab);
624  }
625  if (!globals.IsEmpty()) {
626  index_encoder.AppendU8(kDataIDGlobals);
627  globals.Encode(index_encoder, strtab);
628  }
629  if (!types.IsEmpty()) {
630  index_encoder.AppendU8(kDataIDTypes);
631  types.Encode(index_encoder, strtab);
632  }
633  if (!namespaces.IsEmpty()) {
634  index_encoder.AppendU8(kDataIDNamespaces);
635  namespaces.Encode(index_encoder, strtab);
636  }
637  index_encoder.AppendU8(kDataIDEnd);
638 
639  // Now that all strings have been gathered, we will emit the string table.
640  strtab.Encode(encoder);
641  // Followed the the symbol table data.
642  encoder.AppendData(index_encoder.GetData());
643 }
644 
646  lldb::offset_t *offset_ptr,
647  bool &signature_mismatch) {
648  signature_mismatch = false;
649  CacheSignature signature;
650  if (!signature.Decode(data, offset_ptr))
651  return false;
652  if (CacheSignature(m_dwarf->GetObjectFile()) != signature) {
653  signature_mismatch = true;
654  return false;
655  }
656  IndexSet set;
657  if (!set.Decode(data, offset_ptr))
658  return false;
659  m_set = std::move(set);
660  return true;
661 }
662 
663 bool ManualDWARFIndex::Encode(DataEncoder &encoder) const {
664  CacheSignature signature(m_dwarf->GetObjectFile());
665  if (!signature.Encode(encoder))
666  return false;
667  m_set.Encode(encoder);
668  return true;
669 }
670 
672  std::string key;
673  llvm::raw_string_ostream strm(key);
674  // DWARF Index can come from different object files for the same module. A
675  // module can have one object file as the main executable and might have
676  // another object file in a separate symbol file, or we might have a .dwo file
677  // that claims its module is the main executable.
678  ObjectFile *objfile = m_dwarf->GetObjectFile();
679  strm << objfile->GetModule()->GetCacheKey() << "-dwarf-index-"
680  << llvm::format_hex(objfile->GetCacheHash(), 10);
681  return strm.str();
682 }
683 
686  if (!cache)
687  return false;
688  ObjectFile *objfile = m_dwarf->GetObjectFile();
689  if (!objfile)
690  return false;
691  std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
692  cache->GetCachedData(GetCacheKey());
693  if (!mem_buffer_up)
694  return false;
695  DataExtractor data(mem_buffer_up->getBufferStart(),
696  mem_buffer_up->getBufferSize(),
698  objfile->GetAddressByteSize());
699  bool signature_mismatch = false;
700  lldb::offset_t offset = 0;
701  const bool result = Decode(data, &offset, signature_mismatch);
702  if (signature_mismatch)
703  cache->RemoveCacheFile(GetCacheKey());
704  return result;
705 }
706 
709  if (!cache)
710  return; // Caching is not enabled.
711  ObjectFile *objfile = m_dwarf->GetObjectFile();
712  if (!objfile)
713  return;
714  DataEncoder file(endian::InlHostByteOrder(), objfile->GetAddressByteSize());
715  // Encode will return false if the object file doesn't have anything to make
716  // a signature from.
717  if (Encode(file)) {
718  if (cache->SetCachedData(GetCacheKey(), file.GetData()))
719  m_dwarf->SetDebugInfoIndexWasSavedToCache();
720  }
721 }
DWARFDebugInfo::ContainsTypeUnits
bool ContainsTypeUnits()
Definition: DWARFDebugInfo.cpp:171
lldb_private::Stream::Format
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
lldb_private::ConstStringTable::Encode
bool Encode(DataEncoder &encoder)
Definition: DataFileCache.cpp:278
kDataIDEnd
@ kDataIDEnd
Definition: ManualDWARFIndex.cpp:524
DIERef
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:26
LLDB_SCOPED_TIMERF
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:86
lldb_private::ManualDWARFIndex::Encode
bool Encode(DataEncoder &encoder) const
Encode this object into a data encoder object.
Definition: ManualDWARFIndex.cpp:663
lldb_private::RegularExpression
Definition: RegularExpression.h:18
lldb_private::StringTableReader
Many cache files require string tables to store data efficiently.
Definition: DataFileCache.h:212
DWARFBaseDIE::GetDIERef
llvm::Optional< DIERef > GetDIERef() const
Definition: DWARFBaseDIE.cpp:21
kDataIDTypes
@ kDataIDTypes
Definition: ManualDWARFIndex.cpp:522
lldb_private::DataFileCache::GetCachedData
std::unique_ptr< llvm::MemoryBuffer > GetCachedData(llvm::StringRef key)
Get cached data from the cache directory for the specified key.
Definition: DataFileCache.cpp:73
lldb_private::ManualDWARFIndex::Decode
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr, bool &signature_mismatch)
Decode a serialized version of this object from data.
Definition: ManualDWARFIndex.cpp:645
lldb_private::Module::GetIndexCache
static DataFileCache * GetIndexCache()
Get the global index file cache.
Definition: Module.cpp:1714
dw_tag_t
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:28
lldb_private::ManualDWARFIndex::Index
void Index()
Definition: ManualDWARFIndex.cpp:31
lldb_private::ConstStringTable
Many cache files require string tables to store data efficiently.
Definition: DataFileCache.h:180
lldb_private::Debugger::GetThreadPool
static llvm::ThreadPool & GetThreadPool()
Shared thread poll. Use only with ThreadPoolTaskGroup.
Definition: Debugger.cpp:1990
lldb_private::ManualDWARFIndex::GetCompleteObjCClass
void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, llvm::function_ref< bool(DWARFDIE die)> callback) override
Definition: ManualDWARFIndex.cpp:401
DWARFDebugInfo
Definition: DWARFDebugInfo.h:26
DWARFDebugInfo::GetNumUnits
size_t GetNumUnits()
Definition: DWARFDebugInfo.cpp:105
kDataIDNamespaces
@ kDataIDNamespaces
Definition: ManualDWARFIndex.cpp:523
lldb_private::ElapsedTime
A class that measures elapsed time in an exception safe way.
Definition: Statistics.h:66
kDataIDFunctionObjcClassSelectors
@ kDataIDFunctionObjcClassSelectors
Definition: ManualDWARFIndex.cpp:520
DWARFUnit::GetDwoSymbolFile
SymbolFileDWARFDwo * GetDwoSymbolFile()
Definition: DWARFUnit.cpp:842
Module.h
SymbolFileDWARF
Definition: SymbolFileDWARF.h:60
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::Progress::Increment
void Increment(uint64_t amount=1)
Increment the progress and send a notification to the intalled callback.
Definition: Progress.cpp:39
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
kDataIDFunctionSelectors
@ kDataIDFunctionSelectors
Definition: ManualDWARFIndex.cpp:519
lldb_private::ManualDWARFIndex::IndexUnit
void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp, IndexSet &set)
Definition: ManualDWARFIndex.cpp:139
ManualDWARFIndex.h
lldb_private::Stream
Definition: Stream.h:28
kIdentifierManualDWARFIndex
constexpr llvm::StringLiteral kIdentifierManualDWARFIndex("DIDX")
DWARFDebugInfoEntry
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
Definition: DWARFDebugInfoEntry.h:31
kDataIDFunctionFullnames
@ kDataIDFunctionFullnames
Definition: ManualDWARFIndex.cpp:517
lldb_private::ManualDWARFIndex::IndexSet::Encode
void Encode(DataEncoder &encoder) const
Definition: ManualDWARFIndex.cpp:592
Debugger.h
lldb_private::ObjCLanguage::MethodName::GetClassName
ConstString GetClassName()
Definition: ObjCLanguage.cpp:110
lldb_private::ObjCLanguage::MethodName::GetFullNameWithoutCategory
ConstString GetFullNameWithoutCategory(bool empty_if_no_category)
Definition: ObjCLanguage.cpp:193
DWARFAttributes
Definition: DWARFAttribute.h:44
DWARFDeclContext.h
DWARFDIE
Definition: DWARFDIE.h:16
DataFileCache.h
lldb_private::CacheSignature::Decode
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
Definition: DataFileCache.cpp:231
lldb_private::ManualDWARFIndex::IndexSet
Definition: ManualDWARFIndex.h:59
lldb_private::CacheSignature::Encode
bool Encode(DataEncoder &encoder) const
Encode this object into a data encoder object.
Definition: DataFileCache.cpp:209
lldb_private::DataFileCache::SetCachedData
bool SetCachedData(llvm::StringRef key, llvm::ArrayRef< uint8_t > data)
Set cached data for the specified key.
Definition: DataFileCache.cpp:107
lldb_private::Module::LookupInfo
Definition: Module.h:931
lldb_private::ManualDWARFIndex::LoadFromCache
bool LoadFromCache()
Load the symbol table from the index cache.
Definition: ManualDWARFIndex.cpp:684
SymbolFileDWARFDwo.h
elapsed
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
Definition: Statistics.cpp:36
lldb_private::DataFileCache::RemoveCacheFile
Status RemoveCacheFile(llvm::StringRef key)
Remove the cache file associated with the key.
Definition: DataFileCache.cpp:157
lldb_private::CompilerDeclContext::IsValid
bool IsValid() const
Definition: CompilerDeclContext.h:55
lldb_private::ManualDWARFIndex::GetCacheKey
std::string GetCacheKey()
Get the cache key string for this symbol table.
Definition: ManualDWARFIndex.cpp:671
DWARFUnit
Definition: DWARFUnit.h:83
dwarf
Definition: ABISysV_arc.cpp:61
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:201
lldb_private::StringTableReader::Decode
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Definition: DataFileCache.cpp:300
DWARFDebugInfo::GetUnitAtIndex
DWARFUnit * GetUnitAtIndex(size_t idx)
Definition: DWARFDebugInfo.cpp:110
Progress.h
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
DWARFUnit::GetDWOId
llvm::Optional< uint64_t > GetDWOId()
Definition: DWARFUnit.cpp:361
lldb_private::ConstString
Definition: ConstString.h:39
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::ManualDWARFIndex::GetNamespaces
void GetNamespaces(ConstString name, llvm::function_ref< bool(DWARFDIE die)> callback) override
Definition: ManualDWARFIndex.cpp:424
lldb_private::DataExtractor::GetU8
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:316
Timer.h
lldb_private::ManualDWARFIndex::GetGlobalVariables
void GetGlobalVariables(ConstString basename, llvm::function_ref< bool(DWARFDIE die)> callback) override
Finds global variables with the given base name.
Definition: ManualDWARFIndex.cpp:373
lldb_private::CacheSignature
A signature for a given file on disk.
Definition: DataFileCache.h:108
DataID
DataID
Definition: ManualDWARFIndex.cpp:515
ObjCLanguage.h
DataEncoder.h
lldb_private::Progress
A Progress indicator helper class.
Definition: Progress.h:55
DWARFFormValue
Definition: DWARFFormValue.h:20
SymbolFileDWARF::GetDwpSymbolFile
const std::shared_ptr< SymbolFileDWARFDwo > & GetDwpSymbolFile()
Definition: SymbolFileDWARF.cpp:4044
SymbolFileDWARF::DIEInDeclContext
static bool DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx, const DWARFDIE &die)
Definition: SymbolFileDWARF.cpp:2333
LogChannelDWARF.h
lldb_private::ObjCLanguage::MethodName::GetClassNameWithCategory
ConstString GetClassNameWithCategory()
Definition: ObjCLanguage.cpp:136
kDataIDFunctionMethods
@ kDataIDFunctionMethods
Definition: ManualDWARFIndex.cpp:518
set
set(option_framework FRAMEWORK) endif() if(LLDB_ENABLE_PYTHON) get_target_property(python_bindings_dir swig_wrapper_python BINARY_DIR) set(lldb_python_wrapper $
Definition: API/CMakeLists.txt:5
lldb::eLanguageTypeObjC
@ eLanguageTypeObjC
Objective-C.
Definition: lldb-enumerations.h:453
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
DWARFDebugInfo.h
lldb::eLanguageTypeObjC_plus_plus
@ eLanguageTypeObjC_plus_plus
Objective-C++.
Definition: lldb-enumerations.h:454
DWARFAttributes::ExtractFormValueAtIndex
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
Definition: DWARFAttribute.cpp:38
lldb_private::ObjCLanguage::MethodName
Definition: ObjCLanguage.h:26
DWARFFormValue::Unsigned
uint64_t Unsigned() const
Definition: DWARFFormValue.h:64
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
DWARFUnit::dies
die_iterator_range dies()
Definition: DWARFUnit.h:216
ObjectFile.h
DWARFUnit::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFUnit.h:133
lldb_private::ObjCLanguage::MethodName::GetSelector
ConstString GetSelector()
Definition: ObjCLanguage.cpp:159
kDataIDFunctionBasenames
@ kDataIDFunctionBasenames
Definition: ManualDWARFIndex.cpp:516
lldb_private::ManualDWARFIndex::IndexSet::Decode
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Definition: ManualDWARFIndex.cpp:529
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
lldb_private::ManualDWARFIndex::SaveToCache
void SaveToCache()
Save the symbol table data out into a cache.
Definition: ManualDWARFIndex.cpp:707
lldb_private::Module::LookupInfo::GetLookupName
ConstString GetLookupName() const
Definition: Module.h:942
SymbolFileDWARF::GetLanguage
static lldb::LanguageType GetLanguage(DWARFUnit &unit)
Definition: SymbolFileDWARF.cpp:4125
uint32_t
lldb_private::Module::LookupInfo::GetNameTypeMask
lldb::FunctionNameType GetNameTypeMask() const
Definition: Module.h:946
lldb_private::endian::InlHostByteOrder
lldb::ByteOrder InlHostByteOrder()
Definition: Endian.h:25
kDataIDGlobals
@ kDataIDGlobals
Definition: ManualDWARFIndex.cpp:521
lldb_private::ManualDWARFIndex::Dump
void Dump(Stream &s) override
Definition: ManualDWARFIndex.cpp:490
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
SymbolFileDWARFDwo
Definition: SymbolFileDWARFDwo.h:14
NameToDIE::Append
void Append(const NameToDIE &other)
Definition: NameToDIE.cpp:86
DWARFUnit::GetNonSkeletonUnit
DWARFUnit & GetNonSkeletonUnit()
Definition: DWARFUnit.cpp:654
lldb_private::ManualDWARFIndex::GetTypes
void GetTypes(ConstString name, llvm::function_ref< bool(DWARFDIE die)> callback) override
Definition: ManualDWARFIndex.cpp:409
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
lldb_private::DWARFLog::Lookups
@ Lookups
uint16_t
lldb_private::DataExtractor::GetU32
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
Definition: DataExtractor.cpp:425
SymbolFileDWARF::DebugInfo
DWARFDebugInfo & DebugInfo()
Definition: SymbolFileDWARF.cpp:636
lldb_private::ObjectFile::GetCacheHash
uint32_t GetCacheHash()
Get a hash that can be used for caching object file releated information.
Definition: ObjectFile.cpp:756
DWARFFormValue::AsCString
const char * AsCString() const
Definition: DWARFFormValue.cpp:459
DataExtractor.h
DWARFAttributes::AttributeAtIndex
dw_attr_t AttributeAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:55
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::ManualDWARFIndex::GetFunctions
void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< bool(DWARFDIE die)> callback) override
Definition: ManualDWARFIndex.cpp:430
lldb_private::DataFileCache
This class enables data to be cached into a directory using the llvm caching code.
Definition: DataFileCache.h:44
lldb_private::ManualDWARFIndex::IndexUnitImpl
static void IndexUnitImpl(DWARFUnit &unit, const lldb::LanguageType cu_language, IndexSet &set)
Definition: ManualDWARFIndex.cpp:184
DWARFDeclContext
Definition: DWARFDeclContext.h:23
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ObjectFile::GetAddressByteSize
virtual uint32_t GetAddressByteSize() const =0
Gets the address size in bytes for the current object file.
lldb_private::ObjCLanguage::MethodName::IsValid
bool IsValid(bool strict) const
Definition: ObjCLanguage.h:45
SymbolFileDWARF::GetDwoNum
virtual llvm::Optional< uint32_t > GetDwoNum()
Definition: SymbolFileDWARF.h:281
lldb_private::DataExtractor::GetData
const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
Definition: DataExtractor.h:337
Stream.h
lldb_private::Log
Definition: Log.h:115
DWARFUnit::GetSymbolFileDWARF
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:199
lldb_private::ManualDWARFIndex::GetObjCMethods
void GetObjCMethods(ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback) override
Definition: ManualDWARFIndex.cpp:394
lldb_private::RegularExpression::GetText
llvm::StringRef GetText() const
Access the regular expression text.
Definition: RegularExpression.cpp:33
NameToDIE::Finalize
void Finalize()
Definition: NameToDIE.cpp:23
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
DWARFDIE::IsMethod
bool IsMethod() const
Definition: DWARFDIE.cpp:440
lldb
Definition: SBAddress.h:15
NameToDIE
Definition: NameToDIE.h:21
CURRENT_CACHE_VERSION
constexpr uint32_t CURRENT_CACHE_VERSION
Definition: ManualDWARFIndex.cpp:527
lldb_private::dwarf
Definition: dwarf.h:19
lldb_private::ObjectFile
Definition: ObjectFile.h:60
lldb::eDescriptionLevelBrief
@ eDescriptionLevelBrief
Definition: lldb-enumerations.h:208