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