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