24#include "llvm/Support/FormatVariadic.h"
25#include "llvm/Support/ThreadPool.h"
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())
81 const uint64_t total_progress = units_to_index.size() * 2 + 8;
83 total_progress,
nullptr,
84 std::chrono::milliseconds(20));
94 auto for_each_unit = [&](
auto &&fn) {
95 std::atomic<size_t> next_cu_idx = 0;
96 auto wrapper = [&fn, &next_cu_idx, &units_to_index,
97 &progress](
size_t worker_id) {
99 while ((cu_idx = next_cu_idx.fetch_add(1, std::memory_order_relaxed)) <
100 units_to_index.size()) {
101 fn(worker_id, cu_idx, units_to_index[cu_idx]);
106 for (
size_t i = 0; i < num_threads; ++i)
107 task_group.async(wrapper, i);
118 std::vector<std::optional<DWARFUnit::ScopedExtractDIEs>> clear_cu_dies(
119 units_to_index.size());
120 for_each_unit([&clear_cu_dies](
size_t,
size_t idx,
DWARFUnit *unit) {
125 std::vector<IndexSet> sets(num_threads);
127 [
this, dwp_dwarf, &sets](
size_t worker_id,
size_t,
DWARFUnit *unit) {
128 IndexUnit(*unit, dwp_dwarf, sets[worker_id]);
135 for (
auto &set : sets)
136 result.
Append(set.*index);
160 log,
"ManualDWARFIndex::IndexUnit for unit at .debug_info[{0:x16}]",
186 if (dwo_symbol_file == dwp) {
190 for (
size_t i = 0; i < dwo_info.
GetNumUnits(); ++i)
204 llvm::dwarf::DW_TAG_module)
218 case DW_TAG_array_type:
219 case DW_TAG_base_type:
220 case DW_TAG_class_type:
221 case DW_TAG_constant:
222 case DW_TAG_enumeration_type:
223 case DW_TAG_inlined_subroutine:
224 case DW_TAG_namespace:
225 case DW_TAG_imported_declaration:
226 case DW_TAG_string_type:
227 case DW_TAG_structure_type:
228 case DW_TAG_subprogram:
229 case DW_TAG_subroutine_type:
231 case DW_TAG_union_type:
232 case DW_TAG_unspecified_type:
233 case DW_TAG_variable:
247 const char *name =
nullptr;
248 const char *mangled_cstr =
nullptr;
249 bool is_declaration =
false;
250 bool has_address =
false;
251 bool has_location_or_const_value =
false;
252 bool is_global_or_static_variable =
false;
256 for (
size_t i = 0; i < attributes.
Size(); ++i) {
267 case DW_AT_declaration:
269 is_declaration = form_value.
Unsigned() != 0;
272 case DW_AT_MIPS_linkage_name:
273 case DW_AT_linkage_name:
289 case DW_AT_const_value:
290 has_location_or_const_value =
true;
291 is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable();
295 case DW_AT_specification:
297 specification_die_form = form_value;
304 case DW_TAG_inlined_subroutine:
305 case DW_TAG_subprogram:
308 bool is_objc_method =
false;
311 std::optional<const ObjCLanguage::MethodName> objc_method =
314 is_objc_method =
true;
316 objc_method->GetClassNameWithCategory());
317 ConstString objc_selector_name(objc_method->GetSelector());
319 objc_method->GetFullNameWithoutCategory().c_str());
320 ConstString class_name_no_category(objc_method->GetClassName());
322 if (class_name_with_category)
324 if (class_name_no_category &&
325 class_name_no_category != class_name_with_category)
327 if (objc_selector_name)
329 if (objc_fullname_no_category_name)
343 if (!is_method && !mangled_cstr && !is_objc_method)
351 if (name && name != mangled_cstr &&
352 ((mangled_cstr[0] ==
'_') ||
353 (::strcmp(name, mangled_cstr) != 0))) {
360 case DW_TAG_array_type:
361 case DW_TAG_base_type:
362 case DW_TAG_class_type:
363 case DW_TAG_constant:
364 case DW_TAG_enumeration_type:
365 case DW_TAG_string_type:
366 case DW_TAG_structure_type:
367 case DW_TAG_subroutine_type:
369 case DW_TAG_union_type:
370 case DW_TAG_unspecified_type:
371 if (name && !is_declaration)
373 if (mangled_cstr && !is_declaration)
377 case DW_TAG_namespace:
378 case DW_TAG_imported_declaration:
383 case DW_TAG_member: {
388 bool parent_is_class_type =
false;
389 if (
auto parent = die.GetParent())
391 if (!parent_is_class_type || !is_declaration)
395 case DW_TAG_variable:
396 if (name && has_location_or_const_value && is_global_or_static_variable) {
407 if (mangled_cstr && name != mangled_cstr &&
408 ((mangled_cstr[0] ==
'_') || (::strcmp(name, mangled_cstr) != 0))) {
429 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
448 ConstString class_name,
bool must_be_implementation,
449 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
463 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
465 auto name = context[0].name;
479 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
484 if (name_type_mask & eFunctionNameTypeFull) {
491 return callback(die);
496 if (name_type_mask & eFunctionNameTypeBase) {
503 return callback(die);
509 if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.
IsValid()) {
515 if (name_type_mask & eFunctionNameTypeSelector &&
525 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
537 s.
Format(
"Manual DWARF index for ({0}) '{1:F}':",
540 s.
Printf(
"\nFunction basenames:\n");
542 s.
Printf(
"\nFunction fullnames:\n");
544 s.
Printf(
"\nFunction methods:\n");
546 s.
Printf(
"\nFunction selectors:\n");
548 s.
Printf(
"\nObjective-C class selectors:\n");
550 s.
Printf(
"\nGlobals and statics:\n");
554 s.
Printf(
"\nNamespaces:\n");
582 if (!strtab.
Decode(data, offset_ptr))
585 llvm::StringRef identifier((
const char *)data.
GetData(offset_ptr, 4), 4);
588 const uint32_t version = data.
GetU32(offset_ptr);
594 switch (data.
GetU8(offset_ptr)) {
654 if (!function_basenames.IsEmpty()) {
656 function_basenames.Encode(index_encoder, strtab);
658 if (!function_fullnames.IsEmpty()) {
660 function_fullnames.Encode(index_encoder, strtab);
662 if (!function_methods.IsEmpty()) {
664 function_methods.Encode(index_encoder, strtab);
666 if (!function_selectors.IsEmpty()) {
668 function_selectors.Encode(index_encoder, strtab);
670 if (!objc_class_selectors.IsEmpty()) {
672 objc_class_selectors.Encode(index_encoder, strtab);
674 if (!globals.IsEmpty()) {
676 globals.Encode(index_encoder, strtab);
678 if (!types.IsEmpty()) {
680 types.Encode(index_encoder, strtab);
682 if (!namespaces.IsEmpty()) {
684 namespaces.Encode(index_encoder, strtab);
696 bool &signature_mismatch) {
697 signature_mismatch =
false;
699 if (!signature.
Decode(data, offset_ptr))
702 signature_mismatch =
true;
706 if (!set.
Decode(data, offset_ptr))
708 m_set = std::move(set);
714 if (!signature.
Encode(encoder))
727 llvm::raw_string_ostream strm(key);
748 llvm::StringRef dwarf_index_suffix(
IsPartial() ?
"partial-" :
"full-");
750 strm << objfile->
GetModule()->GetCacheKey() <<
"-dwarf-index-"
751 << dwarf_index_suffix << llvm::format_hex(objfile->
GetCacheHash(), 10);
762 std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
767 mem_buffer_up->getBufferSize(),
770 bool signature_mismatch =
false;
772 const bool result =
Decode(data, &offset, signature_mismatch);
773 if (signature_mismatch)
constexpr uint32_t CURRENT_CACHE_VERSION
constexpr llvm::StringLiteral kIdentifierManualDWARFIndex("DIDX")
@ kDataIDFunctionObjcClassSelectors
@ kDataIDFunctionFullnames
@ kDataIDFunctionSelectors
@ kDataIDFunctionBasenames
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
#define LLDB_SCOPED_TIMERF(...)
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
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.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
An binary data encoding class.
lldb::ByteOrder GetByteOrder() const
llvm::ArrayRef< uint8_t > GetData() const
Get a access to the bytes that this references.
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.
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
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
static DataFileCache * GetIndexCache()
Get the global index file cache.
void LogMessage(Log *log, const char *format, Args &&...args)
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
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.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
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.
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.
Many cache files require string tables to store data efficiently.
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
void SetDebugInfoIndexWasLoadedFromCache() override
ObjectFile * GetObjectFile() override
void SetDebugInfoIndexWasSavedToCache() override
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< bool(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
uint16_t GetVersion() const
die_iterator_range dies()
ScopedExtractDIEs ExtractDIEsScoped()
DWARFUnit & GetNonSkeletonUnit()
DWARFDIE GetDIE(dw_offset_t die_offset)
SymbolFileDWARFDwo * GetDwoSymbolFile(bool load_all_debug_info=true)
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 &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
bool IsPartial() const
Return true if this manual DWARF index is covering only part of the DWARF.
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
llvm::DenseSet< uint64_t > m_type_sigs_to_avoid
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)
void FindAllEntriesForUnit(DWARFUnit &unit, llvm::function_ref< bool(DIERef ref)> callback) const
unit must be the skeleton unit if possible, not GetNonSkeletonUnit().
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr, const StringTableReader &strtab)
Decode a serialized version of this object from data.
bool Find(ConstString name, llvm::function_ref< bool(DIERef ref)> callback) const
void Insert(ConstString name, const DIERef &die_ref)
const std::shared_ptr< SymbolFileDWARFDwo > & GetDwpSymbolFile()
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()
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.
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.
NameToDIE function_basenames
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
NameToDIE function_selectors
void Encode(DataEncoder &encoder) const
NameToDIE function_fullnames
NameToDIE function_methods
NameToDIE objc_class_selectors