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_imported_declaration:
212 case DW_TAG_string_type:
213 case DW_TAG_structure_type:
214 case DW_TAG_subprogram:
215 case DW_TAG_subroutine_type:
217 case DW_TAG_union_type:
218 case DW_TAG_unspecified_type:
219 case DW_TAG_variable:
226 const char *name =
nullptr;
227 const char *mangled_cstr =
nullptr;
228 bool is_declaration =
false;
229 bool has_address =
false;
230 bool has_location_or_const_value =
false;
231 bool is_global_or_static_variable =
false;
235 for (
size_t i = 0; i < attributes.
Size(); ++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;
283 case DW_TAG_inlined_subroutine:
284 case DW_TAG_subprogram:
287 bool is_objc_method =
false;
290 std::optional<const ObjCLanguage::MethodName> objc_method =
293 is_objc_method =
true;
295 objc_method->GetClassNameWithCategory());
296 ConstString objc_selector_name(objc_method->GetSelector());
298 objc_method->GetFullNameWithoutCategory().c_str());
299 ConstString class_name_no_category(objc_method->GetClassName());
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:
357 case DW_TAG_imported_declaration:
362 case DW_TAG_variable:
363 if (name && has_location_or_const_value && is_global_or_static_variable) {
374 if (mangled_cstr && name != mangled_cstr &&
375 ((mangled_cstr[0] ==
'_') || (::strcmp(name, mangled_cstr) != 0))) {
396 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");
549 if (!strtab.
Decode(data, offset_ptr))
552 llvm::StringRef identifier((
const char *)data.
GetData(offset_ptr, 4), 4);
561 switch (data.
GetU8(offset_ptr)) {
614 DataEncoder index_encoder(encoder.GetByteOrder(),
615 encoder.GetAddressByteSize());
621 if (!function_basenames.IsEmpty()) {
623 function_basenames.Encode(index_encoder, strtab);
625 if (!function_fullnames.IsEmpty()) {
627 function_fullnames.Encode(index_encoder, strtab);
629 if (!function_methods.IsEmpty()) {
631 function_methods.Encode(index_encoder, strtab);
633 if (!function_selectors.IsEmpty()) {
635 function_selectors.Encode(index_encoder, strtab);
637 if (!objc_class_selectors.IsEmpty()) {
639 objc_class_selectors.Encode(index_encoder, strtab);
641 if (!globals.IsEmpty()) {
643 globals.Encode(index_encoder, strtab);
645 if (!types.IsEmpty()) {
647 types.Encode(index_encoder, strtab);
649 if (!namespaces.IsEmpty()) {
651 namespaces.Encode(index_encoder, strtab);
658 encoder.AppendData(index_encoder.GetData());
663 bool &signature_mismatch) {
664 signature_mismatch =
false;
666 if (!signature.
Decode(data, offset_ptr))
669 signature_mismatch =
true;
673 if (!set.
Decode(data, offset_ptr))
675 m_set = std::move(set);
681 if (!signature.
Encode(encoder))
689 llvm::raw_string_ostream strm(key);
695 strm << objfile->
GetModule()->GetCacheKey() <<
"-dwarf-index-"
707 std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
712 mem_buffer_up->getBufferSize(),
715 bool signature_mismatch =
false;
717 const bool result =
Decode(data, &offset, signature_mismatch);
718 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()
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)
static bool DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx, const DWARFDIE &die, bool only_root_namespaces=false)
const std::shared_ptr< SymbolFileDWARFDwo > & GetDwpSymbolFile()
static lldb::LanguageType GetLanguage(DWARFUnit &unit)
DWARFDebugInfo & DebugInfo()
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)
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::string update={})
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
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_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