25#include "llvm/Support/ThreadPool.h"
32using namespace llvm::dwarf;
42 m_dwarf->SetDebugInfoIndexWasLoadedFromCache();
50 std::vector<DWARFUnit *> units_to_index;
57 for (
size_t U = 0; U < main_info.
GetNumUnits(); ++U) {
60 units_to_index.push_back(unit);
63 for (
size_t U = 0; U < dwp_info->
GetNumUnits(); ++U) {
67 units_to_index.push_back(tu);
72 if (units_to_index.empty())
83 const uint64_t total_progress = units_to_index.size() * 2 + indices.size();
85 total_progress,
nullptr,
94 const size_t num_tasks = std::min<size_t>(
100 const bool run_inline = num_tasks == 1;
104 auto for_each_unit = [&](
auto &&fn) {
106 for (
size_t i = 0; i < units_to_index.size(); ++i) {
107 fn(0, i, units_to_index[i]);
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) {
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]);
123 for (
size_t i = 0; i < num_tasks; ++i)
124 task_group.async(wrapper, i);
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) {
142 std::vector<IndexSet<NameToDIE>> sets(num_tasks);
144 [
this, dwp_dwarf, &sets](
size_t worker_id,
size_t,
DWARFUnit *unit) {
145 IndexUnit(*unit, dwp_dwarf, sets[worker_id]);
151 auto merge = [
this, &sets, index, &progress]() {
153 for (
auto &set : sets)
154 result.
Append(set.*index);
161 task_group.async(merge);
174 log,
"ManualDWARFIndex::IndexUnit for unit at .debug_info[{0:x16}]",
200 if (dwo_symbol_file == dwp) {
204 for (
size_t i = 0; i < dwo_info.
GetNumUnits(); ++i)
218 llvm::dwarf::DW_TAG_module)
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:
245 case DW_TAG_union_type:
246 case DW_TAG_unspecified_type:
247 case DW_TAG_variable:
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;
270 for (
size_t i = 0; i < attributes.
Size(); ++i) {
281 case DW_AT_declaration:
283 is_declaration = form_value.
Unsigned() != 0;
286 case DW_AT_MIPS_linkage_name:
287 case DW_AT_linkage_name:
303 case DW_AT_const_value:
304 has_location_or_const_value =
true;
305 is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable();
309 case DW_AT_specification:
311 specification_die_form = form_value;
318 case DW_TAG_inlined_subroutine:
319 case DW_TAG_subprogram:
322 bool is_objc_method =
false;
325 std::optional<const ObjCLanguage::ObjCMethodName> objc_method =
328 is_objc_method =
true;
330 objc_method->GetClassNameWithCategory());
331 ConstString objc_selector_name(objc_method->GetSelector());
333 objc_method->GetFullNameWithoutCategory());
334 ConstString class_name_no_category(objc_method->GetClassName());
336 if (class_name_with_category)
338 if (class_name_no_category &&
339 class_name_no_category != class_name_with_category)
341 if (objc_selector_name)
343 if (objc_fullname_no_category_name)
357 if (!is_method && !mangled_cstr && !is_objc_method)
365 if (name && name != mangled_cstr &&
366 ((mangled_cstr[0] ==
'_') ||
367 (::strcmp(name, mangled_cstr) != 0))) {
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:
383 case DW_TAG_union_type:
384 case DW_TAG_unspecified_type:
385 if (name && !is_declaration)
387 if (mangled_cstr && !is_declaration)
391 case DW_TAG_namespace:
392 case DW_TAG_imported_declaration:
397 case DW_TAG_member: {
402 bool parent_is_class_type =
false;
403 if (
auto parent = die.GetParent())
405 if (!parent_is_class_type || !is_declaration)
409 case DW_TAG_variable:
410 if (name && has_location_or_const_value && is_global_or_static_variable) {
421 if (mangled_cstr && name != mangled_cstr &&
422 ((mangled_cstr[0] ==
'_') || (::strcmp(name, mangled_cstr) != 0))) {
438 m_set.globals.Find(basename,
460 m_set.objc_class_selectors.Find(
465 ConstString class_name,
bool must_be_implementation,
468 m_set.types.Find(class_name,
483 auto name = context[0].name;
503 if (name_type_mask & eFunctionNameTypeFull) {
504 if (!
m_set.function_fullnames.Find(
510 return callback(die);
515 if (name_type_mask & eFunctionNameTypeBase) {
516 if (!
m_set.function_basenames.Find(
522 return callback(die);
528 if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.
IsValid()) {
529 if (!
m_set.function_methods.Find(
534 if (name_type_mask & eFunctionNameTypeSelector &&
536 if (!
m_set.function_selectors.Find(
547 if (!
m_set.function_basenames.Find(regex,
550 if (!
m_set.function_fullnames.Find(regex,
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);
572 m_set.types.Dump(&s);
573 s.
Printf(
"\nNamespaces:\n");
574 m_set.namespaces.Dump(&s);
580 if (!signature.
Decode(data, offset_ptr))
584 std::optional<IndexSet<NameToDIE>> set =
DecodeIndexSet(data, offset_ptr);
587 m_set = std::move(*set);
593 if (!signature.
Encode(encoder))
606 llvm::raw_string_ostream strm(key);
627 llvm::StringRef dwarf_index_suffix(
IsPartial() ?
"partial-" :
"full-");
629 strm << objfile->
GetModule()->GetCacheKey() <<
"-dwarf-index-"
630 << dwarf_index_suffix << llvm::format_hex(objfile->
GetCacheHash(), 10);
642 std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
647 mem_buffer_up->getBufferSize(),
651 const bool result =
Decode(data, &offset);
672 m_dwarf->SetDebugInfoIndexWasSavedToCache();
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
#define LLDB_SCOPED_TIMERF(...)
Represents a generic declaration context in a program.
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
An binary data encoding class.
llvm::ArrayRef< uint8_t > GetData() const
Get a access to the bytes that this references.
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.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A class that encapsulates name lookup information.
lldb::FunctionNameType GetNameTypeMask() const
ConstString GetLookupName() const
@ eLLDBIndexTypeDwarfIndex
static DataFileCache * GetIndexCache(LLDBIndexType type)
Get the global index file cache.
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.
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.
void Increment(uint64_t amount=1, std::optional< std::string > updated_detail={})
Increment the progress and send a notification to the installed callback.
static constexpr std::chrono::milliseconds kDefaultHighFrequencyReportTime
The default report time for high frequency progress reports.
llvm::StringRef GetText() const
Access the regular expression text.
const char * GetData() const
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Identifies a DWARF debug info entry within a given Module.
dw_attr_t AttributeAtIndex(uint32_t i) const
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
std::optional< DIERef > GetDIERef() const
DWARFDIE GetFirstChild() const
bool IsStructUnionOrClass() const
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
DWARFUnit * GetUnitAtIndex(size_t idx)
StatsDuration m_index_time
DIERefCallbackImpl DIERefCallback(llvm::function_ref< IterationAction(DWARFDIE die)> callback, llvm::StringRef name={}) const
bool IsSkeletonUnit() const
Note that this check only works for DWARF5+.
dw_offset_t GetFirstDIEOffset() const
dw_offset_t GetOffset() const
die_iterator_range dies()
ScopedExtractDIEs ExtractDIEsScoped()
DWARFUnit & GetNonSkeletonUnit()
DWARFDIE GetDIE(dw_offset_t die_offset)
SymbolFileDWARFDwo * GetDwoSymbolFile(bool load_all_debug_info=true)
uint16_t GetVersion() const override
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.
void Dump(Stream &s) override
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.
IndexSet< NameToDIE > m_set
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.
std::once_flag m_indexed_flag
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)
llvm::DenseSet< uint64_t > m_type_sigs_to_avoid
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)
static lldb::LanguageType GetLanguage(DWARFUnit &unit)
DWARFDebugInfo & DebugInfo()
static bool DIEInDeclContext(const CompilerDeclContext &parent_decl_ctx, const DWARFDIE &die, bool only_root_namespaces=false)
llvm::dwarf::Tag dw_tag_t
llvm::dwarf::Attribute dw_attr_t
lldb::ByteOrder InlHostByteOrder()
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.
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
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()