25#include "llvm/Support/FormatVariadic.h"
26#include "llvm/Support/ThreadPool.h"
33using namespace llvm::dwarf;
43 m_dwarf->SetDebugInfoIndexWasLoadedFromCache();
51 std::vector<DWARFUnit *> units_to_index;
58 for (
size_t U = 0; U < main_info.
GetNumUnits(); ++U) {
61 units_to_index.push_back(unit);
64 for (
size_t U = 0; U < dwp_info->
GetNumUnits(); ++U) {
68 units_to_index.push_back(tu);
73 if (units_to_index.empty())
84 const uint64_t total_progress = units_to_index.size() * 2 + indices.size();
86 total_progress,
nullptr,
97 auto for_each_unit = [&](
auto &&fn) {
98 std::atomic<size_t> next_cu_idx = 0;
99 auto wrapper = [&fn, &next_cu_idx, &units_to_index,
100 &progress](
size_t worker_id) {
102 while ((cu_idx = next_cu_idx.fetch_add(1, std::memory_order_relaxed)) <
103 units_to_index.size()) {
104 fn(worker_id, cu_idx, units_to_index[cu_idx]);
109 for (
size_t i = 0; i < num_threads; ++i)
110 task_group.async(wrapper, i);
121 std::vector<std::optional<DWARFUnit::ScopedExtractDIEs>> clear_cu_dies(
122 units_to_index.size());
123 for_each_unit([&clear_cu_dies](
size_t,
size_t idx,
DWARFUnit *unit) {
128 std::vector<IndexSet<NameToDIE>> sets(num_threads);
130 [
this, dwp_dwarf, &sets](
size_t worker_id,
size_t,
DWARFUnit *unit) {
131 IndexUnit(*unit, dwp_dwarf, sets[worker_id]);
137 task_group.async([
this, &sets, index, &progress]() {
139 for (
auto &set : sets)
140 result.
Append(set.*index);
156 log,
"ManualDWARFIndex::IndexUnit for unit at .debug_info[{0:x16}]",
182 if (dwo_symbol_file == dwp) {
186 for (
size_t i = 0; i < dwo_info.
GetNumUnits(); ++i)
200 llvm::dwarf::DW_TAG_module)
214 case DW_TAG_array_type:
215 case DW_TAG_base_type:
216 case DW_TAG_class_type:
217 case DW_TAG_constant:
218 case DW_TAG_enumeration_type:
219 case DW_TAG_inlined_subroutine:
220 case DW_TAG_namespace:
221 case DW_TAG_imported_declaration:
222 case DW_TAG_string_type:
223 case DW_TAG_structure_type:
224 case DW_TAG_subprogram:
225 case DW_TAG_subroutine_type:
227 case DW_TAG_union_type:
228 case DW_TAG_unspecified_type:
229 case DW_TAG_variable:
243 const char *name =
nullptr;
244 const char *mangled_cstr =
nullptr;
245 bool is_declaration =
false;
246 bool has_address =
false;
247 bool has_location_or_const_value =
false;
248 bool is_global_or_static_variable =
false;
252 for (
size_t i = 0; i < attributes.
Size(); ++i) {
263 case DW_AT_declaration:
265 is_declaration = form_value.
Unsigned() != 0;
268 case DW_AT_MIPS_linkage_name:
269 case DW_AT_linkage_name:
285 case DW_AT_const_value:
286 has_location_or_const_value =
true;
287 is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable();
291 case DW_AT_specification:
293 specification_die_form = form_value;
300 case DW_TAG_inlined_subroutine:
301 case DW_TAG_subprogram:
304 bool is_objc_method =
false;
307 std::optional<const ObjCLanguage::ObjCMethodName> objc_method =
310 is_objc_method =
true;
312 objc_method->GetClassNameWithCategory());
313 ConstString objc_selector_name(objc_method->GetSelector());
315 objc_method->GetFullNameWithoutCategory().c_str());
316 ConstString class_name_no_category(objc_method->GetClassName());
318 if (class_name_with_category)
320 if (class_name_no_category &&
321 class_name_no_category != class_name_with_category)
323 if (objc_selector_name)
325 if (objc_fullname_no_category_name)
339 if (!is_method && !mangled_cstr && !is_objc_method)
347 if (name && name != mangled_cstr &&
348 ((mangled_cstr[0] ==
'_') ||
349 (::strcmp(name, mangled_cstr) != 0))) {
356 case DW_TAG_array_type:
357 case DW_TAG_base_type:
358 case DW_TAG_class_type:
359 case DW_TAG_constant:
360 case DW_TAG_enumeration_type:
361 case DW_TAG_string_type:
362 case DW_TAG_structure_type:
363 case DW_TAG_subroutine_type:
365 case DW_TAG_union_type:
366 case DW_TAG_unspecified_type:
367 if (name && !is_declaration)
369 if (mangled_cstr && !is_declaration)
373 case DW_TAG_namespace:
374 case DW_TAG_imported_declaration:
379 case DW_TAG_member: {
384 bool parent_is_class_type =
false;
385 if (
auto parent = die.GetParent())
387 if (!parent_is_class_type || !is_declaration)
391 case DW_TAG_variable:
392 if (name && has_location_or_const_value && is_global_or_static_variable) {
403 if (mangled_cstr && name != mangled_cstr &&
404 ((mangled_cstr[0] ==
'_') || (::strcmp(name, mangled_cstr) != 0))) {
420 m_set.globals.Find(basename,
442 m_set.objc_class_selectors.Find(
447 ConstString class_name,
bool must_be_implementation,
450 m_set.types.Find(class_name,
465 auto name = context[0].name;
485 if (name_type_mask & eFunctionNameTypeFull) {
486 if (!
m_set.function_fullnames.Find(
492 return callback(die);
497 if (name_type_mask & eFunctionNameTypeBase) {
498 if (!
m_set.function_basenames.Find(
504 return callback(die);
510 if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.
IsValid()) {
511 if (!
m_set.function_methods.Find(
516 if (name_type_mask & eFunctionNameTypeSelector &&
518 if (!
m_set.function_selectors.Find(
529 if (!
m_set.function_basenames.Find(regex,
532 if (!
m_set.function_fullnames.Find(regex,
538 s.
Format(
"Manual DWARF index for ({0}) '{1:F}':",
539 m_module.GetArchitecture().GetArchitectureName(),
540 m_module.GetObjectFile()->GetFileSpec());
541 s.
Printf(
"\nFunction basenames:\n");
542 m_set.function_basenames.Dump(&s);
543 s.
Printf(
"\nFunction fullnames:\n");
544 m_set.function_fullnames.Dump(&s);
545 s.
Printf(
"\nFunction methods:\n");
546 m_set.function_methods.Dump(&s);
547 s.
Printf(
"\nFunction selectors:\n");
548 m_set.function_selectors.Dump(&s);
549 s.
Printf(
"\nObjective-C class selectors:\n");
550 m_set.objc_class_selectors.Dump(&s);
551 s.
Printf(
"\nGlobals and statics:\n");
552 m_set.globals.Dump(&s);
554 m_set.types.Dump(&s);
555 s.
Printf(
"\nNamespaces:\n");
556 m_set.namespaces.Dump(&s);
561 bool &signature_mismatch) {
562 signature_mismatch =
false;
564 if (!signature.
Decode(data, offset_ptr))
567 signature_mismatch =
true;
570 std::optional<IndexSet<NameToDIE>> set =
DecodeIndexSet(data, offset_ptr);
573 m_set = std::move(*set);
579 if (!signature.
Encode(encoder))
592 llvm::raw_string_ostream strm(key);
613 llvm::StringRef dwarf_index_suffix(
IsPartial() ?
"partial-" :
"full-");
615 strm << objfile->
GetModule()->GetCacheKey() <<
"-dwarf-index-"
616 << dwarf_index_suffix << llvm::format_hex(objfile->
GetCacheHash(), 10);
627 std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
632 mem_buffer_up->getBufferSize(),
635 bool signature_mismatch =
false;
637 const bool result =
Decode(data, &offset, signature_mismatch);
638 if (signature_mismatch)
655 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
static DataFileCache * GetIndexCache()
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 releated 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)
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 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 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 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< 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
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()