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"
22#include "lldb/Utility/Stream.h"
23#include "lldb/Utility/Timer.h"
25#include "llvm/Support/ThreadPool.h"
26#include <atomic>
27#include <optional>
28
29using namespace lldb_private;
30using namespace lldb;
31using namespace lldb_private::plugin::dwarf;
32using namespace llvm::dwarf;
33
35 std::call_once(m_indexed_flag, [this]() { IndexImpl(); });
36}
37
40 LLDB_SCOPED_TIMERF("%p", static_cast<void *>(m_dwarf));
41 if (LoadFromCache()) {
42 m_dwarf->SetDebugInfoIndexWasLoadedFromCache();
43 return;
44 }
45
46 DWARFDebugInfo &main_info = m_dwarf->DebugInfo();
47 SymbolFileDWARFDwo *dwp_dwarf = m_dwarf->GetDwpSymbolFile().get();
48 DWARFDebugInfo *dwp_info = dwp_dwarf ? &dwp_dwarf->DebugInfo() : nullptr;
49
50 std::vector<DWARFUnit *> units_to_index;
51 units_to_index.reserve(main_info.GetNumUnits() +
52 (dwp_info ? dwp_info->GetNumUnits() : 0));
53
54 // Process all units in the main file, as well as any type units in the dwp
55 // file. Type units in dwo files are handled when we reach the dwo file in
56 // IndexUnit.
57 for (size_t U = 0; U < main_info.GetNumUnits(); ++U) {
58 DWARFUnit *unit = main_info.GetUnitAtIndex(U);
59 if (unit && m_units_to_avoid.count(unit->GetOffset()) == 0)
60 units_to_index.push_back(unit);
61 }
62 if (dwp_info && dwp_info->ContainsTypeUnits()) {
63 for (size_t U = 0; U < dwp_info->GetNumUnits(); ++U) {
64 if (auto *tu =
65 llvm::dyn_cast<DWARFTypeUnit>(dwp_info->GetUnitAtIndex(U))) {
66 if (!m_type_sigs_to_avoid.contains(tu->GetTypeHash()))
67 units_to_index.push_back(tu);
68 }
69 }
70 }
71
72 if (units_to_index.empty())
73 return;
74
75 StreamString module_desc;
76 m_module.GetDescription(module_desc.AsRawOstream(),
78
79 // Include 2 passes per unit to index for extracting DIEs from the unit and
80 // indexing the unit, and then extra entries for finalizing each index in the
81 // set.
82 const auto indices = IndexSet<NameToDIE>::Indices();
83 const uint64_t total_progress = units_to_index.size() * 2 + indices.size();
84 Progress progress("Manually indexing DWARF", module_desc.GetData(),
85 total_progress, /*debugger=*/nullptr,
87
88 // Share one thread pool across operations to avoid the overhead of
89 // recreating the threads.
90 llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
91 // No more tasks than units: a module with a few compile units (e.g. a GPU
92 // code object) would otherwise queue a task per pool thread, each with its
93 // own IndexSet to allocate and merge, for every for_each_unit call.
94 const size_t num_tasks = std::min<size_t>(
95 Debugger::GetThreadPool().getMaxConcurrency(), units_to_index.size());
96
97 // With a single task (one unit, e.g. a GPU code object, or a one-thread
98 // pool) nothing runs in parallel, so do the work on this thread instead of
99 // going through the pool.
100 const bool run_inline = num_tasks == 1;
101
102 // Run a function for each compile unit in parallel using num_tasks tasks.
103 // This is significantly faster than submiting a new task for each unit.
104 auto for_each_unit = [&](auto &&fn) {
105 if (run_inline) {
106 for (size_t i = 0; i < units_to_index.size(); ++i) {
107 fn(0, i, units_to_index[i]);
108 progress.Increment();
109 }
110 return;
111 }
112 std::atomic<size_t> next_cu_idx = 0;
113 auto wrapper = [&fn, &next_cu_idx, &units_to_index,
114 &progress](size_t worker_id) {
115 size_t cu_idx;
116 while ((cu_idx = next_cu_idx.fetch_add(1, std::memory_order_relaxed)) <
117 units_to_index.size()) {
118 fn(worker_id, cu_idx, units_to_index[cu_idx]);
119 progress.Increment();
120 }
121 };
122
123 for (size_t i = 0; i < num_tasks; ++i)
124 task_group.async(wrapper, i);
125
126 task_group.wait();
127 };
128
129 // Extract dies for all DWARFs unit in parallel. Figure out which units
130 // didn't have their DIEs already parsed and remember this. If no DIEs were
131 // parsed prior to this index function call, we are going to want to clear the
132 // CU dies after we are done indexing to make sure we don't pull in all DWARF
133 // dies, but we need to wait until all units have been indexed in case a DIE
134 // in one unit refers to another and the indexes accesses those DIEs.
135 std::vector<std::optional<DWARFUnit::ScopedExtractDIEs>> clear_cu_dies(
136 units_to_index.size());
137 for_each_unit([&clear_cu_dies](size_t, size_t idx, DWARFUnit *unit) {
138 clear_cu_dies[idx] = unit->ExtractDIEsScoped();
139 });
140
141 // Now index all DWARF unit in parallel.
142 std::vector<IndexSet<NameToDIE>> sets(num_tasks);
143 for_each_unit(
144 [this, dwp_dwarf, &sets](size_t worker_id, size_t, DWARFUnit *unit) {
145 IndexUnit(*unit, dwp_dwarf, sets[worker_id]);
146 });
147
148 // Merge partial indexes into a single index. Process each index in a set in
149 // parallel.
150 for (NameToDIE IndexSet<NameToDIE>::*index : indices) {
151 auto merge = [this, &sets, index, &progress]() {
152 NameToDIE &result = m_set.*index;
153 for (auto &set : sets)
154 result.Append(set.*index);
155 result.Finalize();
156 progress.Increment();
157 };
158 if (run_inline)
159 merge();
160 else
161 task_group.async(merge);
162 }
163 task_group.wait();
164
165 SaveToCache();
166}
167
169 IndexSet<NameToDIE> &set) {
171
172 if (log) {
173 m_module.LogMessage(
174 log, "ManualDWARFIndex::IndexUnit for unit at .debug_info[{0:x16}]",
175 unit.GetOffset());
176 }
177
178 const LanguageType cu_language = SymbolFileDWARF::GetLanguage(unit);
179
180 // First check if the unit has a DWO ID. If it does then we only want to index
181 // the .dwo file or nothing at all. If we have a compile unit where we can't
182 // locate the .dwo/.dwp file we don't want to index anything from the skeleton
183 // compile unit because it is usally has no children unless
184 // -fsplit-dwarf-inlining was used at compile time. This option will add a
185 // copy of all DW_TAG_subprogram and any contained DW_TAG_inline_subroutine
186 // DIEs so that symbolication will still work in the absence of the .dwo/.dwp
187 // file, but the functions have no return types and all arguments and locals
188 // have been removed. So we don't want to index any of these hacked up
189 // function types. Types can still exist in the skeleton compile unit DWARF
190 // though as some functions have template parameter types and other things
191 // that cause extra copies of types to be included, but we should find these
192 // types in the .dwo file only as methods could have return types removed and
193 // we don't have to index incomplete types from the skeleton compile unit.
194 if (unit.GetDWOId()) {
195 // Index the .dwo or dwp instead of the skeleton unit.
196 if (SymbolFileDWARFDwo *dwo_symbol_file = unit.GetDwoSymbolFile()) {
197 // Type units in a dwp file are indexed separately, so we just need to
198 // process the split unit here. However, if the split unit is in a dwo
199 // file, then we need to process type units here.
200 if (dwo_symbol_file == dwp) {
201 IndexUnitImpl(unit.GetNonSkeletonUnit(), cu_language, set);
202 } else {
203 DWARFDebugInfo &dwo_info = dwo_symbol_file->DebugInfo();
204 for (size_t i = 0; i < dwo_info.GetNumUnits(); ++i)
205 IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), cu_language, set);
206 }
207 return;
208 }
209 // This was a DWARF5 skeleton CU and the .dwo file couldn't be located.
210 if (unit.GetVersion() >= 5 && unit.IsSkeletonUnit())
211 return;
212
213 // Either this is a DWARF 4 + fission CU with the .dwo file
214 // missing, or it's a -gmodules pch or pcm. Try to detect the
215 // latter by checking whether the first DIE is a DW_TAG_module.
216 // If it's a pch/pcm, continue indexing it.
217 if (unit.GetDIE(unit.GetFirstDIEOffset()).GetFirstChild().Tag() !=
218 llvm::dwarf::DW_TAG_module)
219 return;
220 }
221 // We have a normal compile unit which we want to index.
222 IndexUnitImpl(unit, cu_language, set);
223}
224
226 const LanguageType cu_language,
227 IndexSet<NameToDIE> &set) {
228 for (const DWARFDebugInfoEntry &die : unit.dies()) {
229 const dw_tag_t tag = die.Tag();
230
231 switch (tag) {
232 case DW_TAG_array_type:
233 case DW_TAG_base_type:
234 case DW_TAG_class_type:
235 case DW_TAG_constant:
236 case DW_TAG_enumeration_type:
237 case DW_TAG_inlined_subroutine:
238 case DW_TAG_namespace:
239 case DW_TAG_imported_declaration:
240 case DW_TAG_string_type:
241 case DW_TAG_structure_type:
242 case DW_TAG_subprogram:
243 case DW_TAG_subroutine_type:
244 case DW_TAG_typedef:
245 case DW_TAG_union_type:
246 case DW_TAG_unspecified_type:
247 case DW_TAG_variable:
248 break;
249
250 case DW_TAG_member:
251 // Only in DWARF 4 and earlier `static const` members of a struct, a class
252 // or a union have an entry tag `DW_TAG_member`
253 if (unit.GetVersion() >= 5)
254 continue;
255 break;
256
257 default:
258 continue;
259 }
260
261 const char *name = nullptr;
262 const char *mangled_cstr = nullptr;
263 bool is_declaration = false;
264 bool has_address = false;
265 bool has_location_or_const_value = false;
266 bool is_global_or_static_variable = false;
267
268 DWARFFormValue specification_die_form;
269 DWARFAttributes attributes = die.GetAttributes(&unit);
270 for (size_t i = 0; i < attributes.Size(); ++i) {
271 dw_attr_t attr = attributes.AttributeAtIndex(i);
272 DWARFFormValue form_value;
273 switch (attr) {
274 default:
275 break;
276 case DW_AT_name:
277 if (attributes.ExtractFormValueAtIndex(i, form_value))
278 name = form_value.AsCString();
279 break;
280
281 case DW_AT_declaration:
282 if (attributes.ExtractFormValueAtIndex(i, form_value))
283 is_declaration = form_value.Unsigned() != 0;
284 break;
285
286 case DW_AT_MIPS_linkage_name:
287 case DW_AT_linkage_name:
288 if (attributes.ExtractFormValueAtIndex(i, form_value))
289 mangled_cstr = form_value.AsCString();
290 break;
291
292 case DW_AT_low_pc:
293 case DW_AT_high_pc:
294 case DW_AT_ranges:
295 has_address = true;
296 break;
297
298 case DW_AT_entry_pc:
299 has_address = true;
300 break;
301
302 case DW_AT_location:
303 case DW_AT_const_value:
304 has_location_or_const_value = true;
305 is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable();
306
307 break;
308
309 case DW_AT_specification:
310 if (attributes.ExtractFormValueAtIndex(i, form_value))
311 specification_die_form = form_value;
312 break;
313 }
314 }
315
316 DIERef ref = *DWARFDIE(&unit, &die).GetDIERef();
317 switch (tag) {
318 case DW_TAG_inlined_subroutine:
319 case DW_TAG_subprogram:
320 if (has_address) {
321 if (name) {
322 bool is_objc_method = false;
323 if (cu_language == eLanguageTypeObjC ||
324 cu_language == eLanguageTypeObjC_plus_plus) {
325 std::optional<const ObjCLanguage::ObjCMethodName> objc_method =
327 if (objc_method) {
328 is_objc_method = true;
329 ConstString class_name_with_category(
330 objc_method->GetClassNameWithCategory());
331 ConstString objc_selector_name(objc_method->GetSelector());
332 ConstString objc_fullname_no_category_name(
333 objc_method->GetFullNameWithoutCategory());
334 ConstString class_name_no_category(objc_method->GetClassName());
335 set.function_fullnames.Insert(ConstString(name), ref);
336 if (class_name_with_category)
337 set.objc_class_selectors.Insert(class_name_with_category, ref);
338 if (class_name_no_category &&
339 class_name_no_category != class_name_with_category)
340 set.objc_class_selectors.Insert(class_name_no_category, ref);
341 if (objc_selector_name)
342 set.function_selectors.Insert(objc_selector_name, ref);
343 if (objc_fullname_no_category_name)
344 set.function_fullnames.Insert(objc_fullname_no_category_name,
345 ref);
346 }
347 }
348 // If we have a mangled name, then the DW_AT_name attribute is
349 // usually the method name without the class or any parameters
350 bool is_method = DWARFDIE(&unit, &die).IsMethod();
351
352 if (is_method)
353 set.function_methods.Insert(ConstString(name), ref);
354 else
355 set.function_basenames.Insert(ConstString(name), ref);
356
357 if (!is_method && !mangled_cstr && !is_objc_method)
358 set.function_fullnames.Insert(ConstString(name), ref);
359 }
360 if (mangled_cstr) {
361 // Make sure our mangled name isn't the same string table entry as
362 // our name. If it starts with '_', then it is ok, else compare the
363 // string to make sure it isn't the same and we don't end up with
364 // duplicate entries
365 if (name && name != mangled_cstr &&
366 ((mangled_cstr[0] == '_') ||
367 (::strcmp(name, mangled_cstr) != 0))) {
368 set.function_fullnames.Insert(ConstString(mangled_cstr), ref);
369 }
370 }
371 }
372 break;
373
374 case DW_TAG_array_type:
375 case DW_TAG_base_type:
376 case DW_TAG_class_type:
377 case DW_TAG_constant:
378 case DW_TAG_enumeration_type:
379 case DW_TAG_string_type:
380 case DW_TAG_structure_type:
381 case DW_TAG_subroutine_type:
382 case DW_TAG_typedef:
383 case DW_TAG_union_type:
384 case DW_TAG_unspecified_type:
385 if (name && !is_declaration)
386 set.types.Insert(ConstString(name), ref);
387 if (mangled_cstr && !is_declaration)
388 set.types.Insert(ConstString(mangled_cstr), ref);
389 break;
390
391 case DW_TAG_namespace:
392 case DW_TAG_imported_declaration:
393 if (name)
394 set.namespaces.Insert(ConstString(name), ref);
395 break;
396
397 case DW_TAG_member: {
398 // In DWARF 4 and earlier `static const` members of a struct, a class or a
399 // union have an entry tag `DW_TAG_member`, and are also tagged as
400 // `DW_AT_declaration`, but otherwise follow the same rules as
401 // `DW_TAG_variable`.
402 bool parent_is_class_type = false;
403 if (auto parent = die.GetParent())
404 parent_is_class_type = DWARFDIE(&unit, parent).IsStructUnionOrClass();
405 if (!parent_is_class_type || !is_declaration)
406 break;
407 [[fallthrough]];
408 }
409 case DW_TAG_variable:
410 if (name && has_location_or_const_value && is_global_or_static_variable) {
411 set.globals.Insert(ConstString(name), ref);
412 // Be sure to include variables by their mangled and demangled names if
413 // they have any since a variable can have a basename "i", a mangled
414 // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name
415 // "(anonymous namespace)::i"...
416
417 // Make sure our mangled name isn't the same string table entry as our
418 // name. If it starts with '_', then it is ok, else compare the string
419 // to make sure it isn't the same and we don't end up with duplicate
420 // entries
421 if (mangled_cstr && name != mangled_cstr &&
422 ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) {
423 set.globals.Insert(ConstString(mangled_cstr), ref);
424 }
425 }
426 break;
427
428 default:
429 continue;
430 }
431 }
432}
433
435 ConstString basename,
436 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
437 Index();
438 m_set.globals.Find(basename,
439 DIERefCallback(callback, basename.GetStringRef()));
440}
441
443 const RegularExpression &regex,
444 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
445 Index();
446 m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText()));
447}
448
450 DWARFUnit &unit,
451 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
452 Index();
453 m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback));
454}
455
457 ConstString class_name,
458 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
459 Index();
460 m_set.objc_class_selectors.Find(
461 class_name, DIERefCallback(callback, class_name.GetStringRef()));
462}
463
465 ConstString class_name, bool must_be_implementation,
466 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
467 Index();
468 m_set.types.Find(class_name,
469 DIERefCallback(callback, class_name.GetStringRef()));
470}
471
473 ConstString name,
474 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
475 Index();
476 m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef()));
477}
478
480 const DWARFDeclContext &context,
481 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
482 Index();
483 auto name = context[0].name;
484 m_set.types.Find(ConstString(name),
485 DIERefCallback(callback, llvm::StringRef(name)));
486}
487
489 ConstString name,
490 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
491 Index();
492 m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef()));
493}
494
496 const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
497 const CompilerDeclContext &parent_decl_ctx,
498 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
499 Index();
500 ConstString name = lookup_info.GetLookupName();
501 FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
502
503 if (name_type_mask & eFunctionNameTypeFull) {
504 if (!m_set.function_fullnames.Find(
505 name, DIERefCallback(
506 [&](DWARFDIE die) {
507 if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
508 die))
510 return callback(die);
511 },
512 name.GetStringRef())))
513 return;
514 }
515 if (name_type_mask & eFunctionNameTypeBase) {
516 if (!m_set.function_basenames.Find(
517 name, DIERefCallback(
518 [&](DWARFDIE die) {
519 if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
520 die))
522 return callback(die);
523 },
524 name.GetStringRef())))
525 return;
526 }
527
528 if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) {
529 if (!m_set.function_methods.Find(
530 name, DIERefCallback(callback, name.GetStringRef())))
531 return;
532 }
533
534 if (name_type_mask & eFunctionNameTypeSelector &&
535 !parent_decl_ctx.IsValid()) {
536 if (!m_set.function_selectors.Find(
537 name, DIERefCallback(callback, name.GetStringRef())))
538 return;
539 }
540}
541
543 const RegularExpression &regex,
544 llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
545 Index();
546
547 if (!m_set.function_basenames.Find(regex,
548 DIERefCallback(callback, regex.GetText())))
549 return;
550 if (!m_set.function_fullnames.Find(regex,
551 DIERefCallback(callback, regex.GetText())))
552 return;
553}
554
556 s.Format("Manual DWARF index for ({0}) '{1:F}':",
557 m_module.GetArchitecture().GetArchitectureName(),
558 m_module.GetObjectFile()->GetFileSpec());
559 s.Printf("\nFunction basenames:\n");
560 m_set.function_basenames.Dump(&s);
561 s.Printf("\nFunction fullnames:\n");
562 m_set.function_fullnames.Dump(&s);
563 s.Printf("\nFunction methods:\n");
564 m_set.function_methods.Dump(&s);
565 s.Printf("\nFunction selectors:\n");
566 m_set.function_selectors.Dump(&s);
567 s.Printf("\nObjective-C class selectors:\n");
568 m_set.objc_class_selectors.Dump(&s);
569 s.Printf("\nGlobals and statics:\n");
570 m_set.globals.Dump(&s);
571 s.Printf("\nTypes:\n");
572 m_set.types.Dump(&s);
573 s.Printf("\nNamespaces:\n");
574 m_set.namespaces.Dump(&s);
575}
576
578 lldb::offset_t *offset_ptr) {
579 CacheSignature signature;
580 if (!signature.Decode(data, offset_ptr))
581 return false;
582 if (CacheSignature(m_dwarf->GetObjectFile()) != signature)
583 return false;
584 std::optional<IndexSet<NameToDIE>> set = DecodeIndexSet(data, offset_ptr);
585 if (!set)
586 return false;
587 m_set = std::move(*set);
588 return true;
589}
590
592 CacheSignature signature(m_dwarf->GetObjectFile());
593 if (!signature.Encode(encoder))
594 return false;
595 EncodeIndexSet(m_set, encoder);
596 return true;
597}
598
600 // If we have units or type units to skip, then this index is partial.
601 return !m_units_to_avoid.empty() || !m_type_sigs_to_avoid.empty();
602}
603
605 std::string key;
606 llvm::raw_string_ostream strm(key);
607 // DWARF Index can come from different object files for the same module. A
608 // module can have one object file as the main executable and might have
609 // another object file in a separate symbol file, or we might have a .dwo file
610 // that claims its module is the main executable.
611
612 // This class can be used to index all of the DWARF, or part of the DWARF
613 // when there is a .debug_names index where some compile or type units were
614 // built without .debug_names. So we need to know when we have a full manual
615 // DWARF index or a partial manual DWARF index and save them to different
616 // cache files. Before this fix we might end up debugging a binary with
617 // .debug_names where some of the compile or type units weren't indexed, and
618 // find an issue with the .debug_names tables (bugs or being incomplete), and
619 // then we disable loading the .debug_names by setting a setting in LLDB by
620 // running "settings set plugin.symbol-file.dwarf.ignore-file-indexes 0" in
621 // another LLDB instance. The problem arose when there was an index cache from
622 // a previous run where .debug_names was enabled and it had saved a cache file
623 // that only covered the missing compile and type units from the .debug_names,
624 // and with the setting that disables the loading of the cache files we would
625 // load partial cache index cache. So we need to pick a unique cache suffix
626 // name that indicates if the cache is partial or full to avoid this problem.
627 llvm::StringRef dwarf_index_suffix(IsPartial() ? "partial-" : "full-");
628 ObjectFile *objfile = m_dwarf->GetObjectFile();
629 strm << objfile->GetModule()->GetCacheKey() << "-dwarf-index-"
630 << dwarf_index_suffix << llvm::format_hex(objfile->GetCacheHash(), 10);
631 return key;
632}
633
635 ObjectFile *objfile = m_dwarf->GetObjectFile();
636 if (!objfile)
637 return false;
640 if (!cache)
641 return false;
642 std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
643 cache->GetCachedData(GetCacheKey());
644 if (!mem_buffer_up)
645 return false;
646 DataExtractor data(mem_buffer_up->getBufferStart(),
647 mem_buffer_up->getBufferSize(),
649 objfile->GetAddressByteSize());
650 lldb::offset_t offset = 0;
651 const bool result = Decode(data, &offset);
652 // SaveToCache won't overwrite an existing cache file, so remove any file
653 // that can't be used or it will stop this index from being cached.
654 if (!result)
656 return result;
657}
658
660 ObjectFile *objfile = m_dwarf->GetObjectFile();
661 if (!objfile)
662 return;
665 if (!cache)
666 return; // Caching is not enabled.
668 // Encode will return false if the object file doesn't have anything to make
669 // a signature from.
670 if (Encode(file)) {
671 if (cache->SetCachedData(GetCacheKey(), file.GetData()))
672 m_dwarf->SetDebugInfoIndexWasSavedToCache();
673 }
674}
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:91
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
An binary data encoding class.
Definition DataEncoder.h:42
llvm::ArrayRef< uint8_t > GetData() const
Get a access to the bytes that this references.
An data extractor class.
This class enables data to be cached into a directory using the llvm caching code.
std::unique_ptr< llvm::MemoryBuffer > GetCachedData(llvm::StringRef key)
Get cached data from the cache directory for the specified key.
bool SetCachedData(llvm::StringRef key, llvm::ArrayRef< uint8_t > data)
Set cached data for the specified key.
Status RemoveCacheFile(llvm::StringRef key)
Remove the cache file associated with the key.
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
A class that measures elapsed time in an exception safe way.
Definition Statistics.h:76
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A class that encapsulates name lookup information.
Definition Module.h:973
lldb::FunctionNameType GetNameTypeMask() const
Definition Module.h:1015
ConstString GetLookupName() const
Definition Module.h:1013
static DataFileCache * GetIndexCache(LLDBIndexType type)
Get the global index file cache.
Definition Module.cpp:1736
static std::optional< const ObjCMethodName > Create(llvm::StringRef name, bool strict)
The static factory method for creating a ObjCMethodName.
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:47
virtual uint32_t GetAddressByteSize() const =0
Gets the address size in bytes for the current object file.
uint32_t GetCacheHash()
Get a hash that can be used for caching object file related information.
A Progress indicator helper class.
Definition Progress.h:60
void Increment(uint64_t amount=1, std::optional< std::string > updated_detail={})
Increment the progress and send a notification to the installed callback.
Definition Progress.cpp:63
static constexpr std::chrono::milliseconds kDefaultHighFrequencyReportTime
The default report time for high frequency progress reports.
Definition Progress.h:119
llvm::StringRef GetText() const
Access the regular expression text.
const char * GetData() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:370
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
Identifies a DWARF debug info entry within a given Module.
Definition DIERef.h:31
dw_attr_t AttributeAtIndex(uint32_t i) const
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
std::optional< DIERef > GetDIERef() const
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
DIERefCallbackImpl DIERefCallback(llvm::function_ref< IterationAction(DWARFDIE die)> callback, llvm::StringRef name={}) const
Definition DWARFIndex.h:135
bool IsSkeletonUnit() const
Note that this check only works for DWARF5+.
Definition DWARFUnit.h:228
dw_offset_t GetFirstDIEOffset() const
Definition DWARFUnit.h:113
DWARFDIE GetDIE(dw_offset_t die_offset)
SymbolFileDWARFDwo * GetDwoSymbolFile(bool load_all_debug_info=true)
uint16_t GetVersion() const override
Definition DWARFUnit.h:121
std::optional< uint64_t > GetDWOId()
Get the DWO ID from the DWARFUnitHeader for DWARF5, or from the unit DIE's DW_AT_dwo_id or DW_AT_GNU_...
void IndexImpl()
Call ManualDWARFIndex::Index() instead.
SymbolFileDWARF * m_dwarf
The DWARF file which we are indexing.
void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp, IndexSet< NameToDIE > &set)
bool IsPartial() const
Return true if this manual DWARF index is covering only part of the DWARF.
bool Encode(DataEncoder &encoder) const
Encode this object into a data encoder object.
void GetGlobalVariables(ConstString basename, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
Finds global variables with the given base name.
void Index()
Reads the DWARF debug info to build the index once.
void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
llvm::DenseSet< dw_offset_t > m_units_to_avoid
Which dwarf units should we skip while building the index.
std::string GetCacheKey()
Get the cache key string for this symbol table.
bool LoadFromCache()
Load the symbol table from the index cache.
void GetObjCMethods(ConstString class_name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
static void IndexUnitImpl(DWARFUnit &unit, const lldb::LanguageType cu_language, IndexSet< NameToDIE > &set)
void SaveToCache()
Save the symbol table data out into a cache.
void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void GetTypes(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
void GetNamespaces(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void Append(const NameToDIE &other)
Definition NameToDIE.cpp:91
static lldb::LanguageType GetLanguage(DWARFUnit &unit)
static bool DIEInDeclContext(const CompilerDeclContext &parent_decl_ctx, const DWARFDIE &die, bool only_root_namespaces=false)
llvm::dwarf::Tag dw_tag_t
Definition dwarf.h:19
llvm::dwarf::Attribute dw_attr_t
Definition dwarf.h:17
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
std::optional< IndexSet< NameToDIE > > DecodeIndexSet(const DataExtractor &data, lldb::offset_t *offset_ptr)
void EncodeIndexSet(const IndexSet< NameToDIE > &set, DataEncoder &encoder)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
@ eDescriptionLevelBrief
uint64_t offset_t
Definition lldb-types.h:86
LanguageType
Programming language type.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeObjC
Objective-C.
A signature for a given file on disk.
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
bool Encode(DataEncoder &encoder) const
Encode this object into a data encoder object.
static std::array< T(IndexSet::*), 8 > Indices()