24#include "llvm/Support/FormatVariadic.h"
25#include "llvm/Support/ThreadPool.h"
48 std::vector<DWARFUnit *> units_to_index;
55 for (
size_t U = 0; U < main_info.
GetNumUnits(); ++U) {
58 units_to_index.push_back(unit);
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);
67 if (units_to_index.empty())
76 const uint64_t total_progress = units_to_index.size() * 2 + 8;
78 llvm::formatv(
"Manually indexing DWARF for {0}", module_desc.
GetData()),
81 std::vector<IndexSet> sets(units_to_index.size());
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]);
92 auto extract_fn = [&](
size_t cu_idx) {
93 clear_cu_dies[cu_idx] = units_to_index[cu_idx]->ExtractDIEsScoped();
109 for (
size_t i = 0; i < units_to_index.size(); ++i)
110 task_group.async(extract_fn, i);
115 for (
size_t i = 0; i < units_to_index.size(); ++i)
116 task_group.async(parser_fn, i);
121 for (
auto &set : sets)
122 result.
Append(set.*index);
146 log,
"ManualDWARFIndex::IndexUnit for unit at .debug_info[{0:x16}]",
172 if (dwo_symbol_file == dwp) {
176 for (
size_t i = 0; i < dwo_info.
GetNumUnits(); ++i)
190 llvm::dwarf::DW_TAG_module)
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:
216 case DW_TAG_union_type:
217 case DW_TAG_unspecified_type:
218 case DW_TAG_variable:
226 const char *name =
nullptr;
227 const char *mangled_cstr =
nullptr;
228 bool is_declaration =
false;
230 bool has_address =
false;
231 bool has_location_or_const_value =
false;
232 bool is_global_or_static_variable =
false;
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) {
246 case DW_AT_declaration:
248 is_declaration = form_value.
Unsigned() != 0;
251 case DW_AT_MIPS_linkage_name:
252 case DW_AT_linkage_name:
268 case DW_AT_const_value:
269 has_location_or_const_value =
true;
270 is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable();
274 case DW_AT_specification:
276 specification_die_form = form_value;
284 case DW_TAG_inlined_subroutine:
285 case DW_TAG_subprogram:
288 bool is_objc_method =
false;
292 if (objc_method.
IsValid(
true)) {
293 is_objc_method =
true;
301 if (class_name_with_category)
303 if (class_name_no_category &&
304 class_name_no_category != class_name_with_category)
306 if (objc_selector_name)
308 if (objc_fullname_no_category_name)
322 if (!is_method && !mangled_cstr && !is_objc_method)
330 if (name && name != mangled_cstr &&
331 ((mangled_cstr[0] ==
'_') ||
332 (::strcmp(name, mangled_cstr) != 0))) {
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:
348 case DW_TAG_union_type:
349 case DW_TAG_unspecified_type:
350 if (name && !is_declaration)
352 if (mangled_cstr && !is_declaration)
356 case DW_TAG_namespace:
361 case DW_TAG_variable:
362 if (name && has_location_or_const_value && is_global_or_static_variable) {
373 if (mangled_cstr && name != mangled_cstr &&
374 ((mangled_cstr[0] ==
'_') || (::strcmp(name, mangled_cstr) != 0))) {
395 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
415 ConstString class_name,
bool must_be_implementation,
416 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
430 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
432 auto name = context[0].name;
446 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
451 if (name_type_mask & eFunctionNameTypeFull) {
458 return callback(die);
463 if (name_type_mask & eFunctionNameTypeBase) {
470 return callback(die);
476 if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.
IsValid()) {
482 if (name_type_mask & eFunctionNameTypeSelector &&
492 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
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");
521 s.
Printf(
"\nNamespaces:\n");
546 if (!strtab.
Decode(data, offset_ptr))
549 llvm::StringRef identifier((
const char *)data.
GetData(offset_ptr, 4), 4);
558 switch (data.
GetU8(offset_ptr)) {
611 DataEncoder index_encoder(encoder.GetByteOrder(),
612 encoder.GetAddressByteSize());
618 if (!function_basenames.IsEmpty()) {
620 function_basenames.Encode(index_encoder, strtab);
622 if (!function_fullnames.IsEmpty()) {
624 function_fullnames.Encode(index_encoder, strtab);
626 if (!function_methods.IsEmpty()) {
628 function_methods.Encode(index_encoder, strtab);
630 if (!function_selectors.IsEmpty()) {
632 function_selectors.Encode(index_encoder, strtab);
634 if (!objc_class_selectors.IsEmpty()) {
636 objc_class_selectors.Encode(index_encoder, strtab);
638 if (!globals.IsEmpty()) {
640 globals.Encode(index_encoder, strtab);
642 if (!types.IsEmpty()) {
644 types.Encode(index_encoder, strtab);
646 if (!namespaces.IsEmpty()) {
648 namespaces.Encode(index_encoder, strtab);
655 encoder.AppendData(index_encoder.GetData());
660 bool &signature_mismatch) {
661 signature_mismatch =
false;
663 if (!signature.
Decode(data, offset_ptr))
666 signature_mismatch =
true;
670 if (!set.
Decode(data, offset_ptr))
672 m_set = std::move(set);
678 if (!signature.
Encode(encoder))
686 llvm::raw_string_ostream strm(key);
692 strm << objfile->
GetModule()->GetCacheKey() <<
"-dwarf-index-"
704 std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
709 mem_buffer_up->getBufferSize(),
712 bool signature_mismatch =
false;
714 const bool result =
Decode(data, &offset, signature_mismatch);
715 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(...)
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
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
DWARFUnit * GetUnitAtIndex(size_t idx)
SymbolFileDWARFDwo * GetDwoSymbolFile()
SymbolFileDWARF & GetSymbolFileDWARF() const
dw_offset_t GetFirstDIEOffset() const
uint16_t GetVersion() const
bool IsSkeletonUnit() const
Note that this check only works for DWARF5+.
DWARFUnit & GetNonSkeletonUnit()
DWARFDIE GetDIE(dw_offset_t die_offset)
die_iterator_range dies()
std::optional< uint64_t > GetDWOId()
dw_offset_t GetOffset() const
void Append(const NameToDIE &other)
bool Find(lldb_private::ConstString name, llvm::function_ref< bool(DIERef ref)> callback) const
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.
void Insert(lldb_private::ConstString name, const DIERef &die_ref)
void FindAllEntriesForUnit(DWARFUnit &unit, llvm::function_ref< bool(DIERef ref)> callback) const
unit must be the skeleton unit if possible, not GetNonSkeletonUnit().
void Dump(lldb_private::Stream *s)
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.
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.
StatsDuration m_index_time
DIERefCallbackImpl DIERefCallback(llvm::function_ref< bool(DWARFDIE die)> callback, llvm::StringRef name={}) const
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::ThreadPool & GetThreadPool()
Shared thread poll. Use only with ThreadPoolTaskGroup.
A class that measures elapsed time in an exception safe way.
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.
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)
ConstString GetFullNameWithoutCategory(bool empty_if_no_category)
ConstString GetClassName()
bool IsValid(bool strict) const
ConstString GetSelector()
ConstString GetClassNameWithCategory()
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)
Increment the progress and send a notification to the intalled 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
llvm::dwarf::Tag dw_tag_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_fullnames
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
void Encode(DataEncoder &encoder) const
NameToDIE objc_class_selectors
NameToDIE function_basenames
NameToDIE function_methods
NameToDIE function_selectors