24#include "llvm/Support/FormatVariadic.h"
25#include "llvm/Support/ThreadPool.h"
49 std::vector<DWARFUnit *> units_to_index;
56 for (
size_t U = 0; U < main_info.
GetNumUnits(); ++U) {
59 units_to_index.push_back(unit);
62 for (
size_t U = 0; U < dwp_info->
GetNumUnits(); ++U) {
66 units_to_index.push_back(tu);
71 if (units_to_index.empty())
80 const uint64_t total_progress = units_to_index.size() * 2 + 8;
84 std::vector<IndexSet> sets(units_to_index.size());
88 std::vector<std::optional<DWARFUnit::ScopedExtractDIEs>> clear_cu_dies(
89 units_to_index.size());
90 auto parser_fn = [&](
size_t cu_idx) {
91 IndexUnit(*units_to_index[cu_idx], dwp_dwarf, sets[cu_idx]);
95 auto extract_fn = [&](
size_t cu_idx) {
96 clear_cu_dies[cu_idx] = units_to_index[cu_idx]->ExtractDIEsScoped();
112 for (
size_t i = 0; i < units_to_index.size(); ++i)
113 task_group.async(extract_fn, i);
118 for (
size_t i = 0; i < units_to_index.size(); ++i)
119 task_group.async(parser_fn, i);
124 for (
auto &set : sets)
125 result.
Append(set.*index);
149 log,
"ManualDWARFIndex::IndexUnit for unit at .debug_info[{0:x16}]",
175 if (dwo_symbol_file == dwp) {
179 for (
size_t i = 0; i < dwo_info.
GetNumUnits(); ++i)
193 llvm::dwarf::DW_TAG_module)
207 case DW_TAG_array_type:
208 case DW_TAG_base_type:
209 case DW_TAG_class_type:
210 case DW_TAG_constant:
211 case DW_TAG_enumeration_type:
212 case DW_TAG_inlined_subroutine:
213 case DW_TAG_namespace:
214 case DW_TAG_imported_declaration:
215 case DW_TAG_string_type:
216 case DW_TAG_structure_type:
217 case DW_TAG_subprogram:
218 case DW_TAG_subroutine_type:
220 case DW_TAG_union_type:
221 case DW_TAG_unspecified_type:
222 case DW_TAG_variable:
229 const char *name =
nullptr;
230 const char *mangled_cstr =
nullptr;
231 bool is_declaration =
false;
232 bool has_address =
false;
233 bool has_location_or_const_value =
false;
234 bool is_global_or_static_variable =
false;
238 for (
size_t i = 0; i < attributes.
Size(); ++i) {
249 case DW_AT_declaration:
251 is_declaration = form_value.
Unsigned() != 0;
254 case DW_AT_MIPS_linkage_name:
255 case DW_AT_linkage_name:
271 case DW_AT_const_value:
272 has_location_or_const_value =
true;
273 is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable();
277 case DW_AT_specification:
279 specification_die_form = form_value;
286 case DW_TAG_inlined_subroutine:
287 case DW_TAG_subprogram:
290 bool is_objc_method =
false;
293 std::optional<const ObjCLanguage::MethodName> objc_method =
296 is_objc_method =
true;
298 objc_method->GetClassNameWithCategory());
299 ConstString objc_selector_name(objc_method->GetSelector());
301 objc_method->GetFullNameWithoutCategory().c_str());
302 ConstString class_name_no_category(objc_method->GetClassName());
304 if (class_name_with_category)
306 if (class_name_no_category &&
307 class_name_no_category != class_name_with_category)
309 if (objc_selector_name)
311 if (objc_fullname_no_category_name)
325 if (!is_method && !mangled_cstr && !is_objc_method)
333 if (name && name != mangled_cstr &&
334 ((mangled_cstr[0] ==
'_') ||
335 (::strcmp(name, mangled_cstr) != 0))) {
342 case DW_TAG_array_type:
343 case DW_TAG_base_type:
344 case DW_TAG_class_type:
345 case DW_TAG_constant:
346 case DW_TAG_enumeration_type:
347 case DW_TAG_string_type:
348 case DW_TAG_structure_type:
349 case DW_TAG_subroutine_type:
351 case DW_TAG_union_type:
352 case DW_TAG_unspecified_type:
353 if (name && !is_declaration)
355 if (mangled_cstr && !is_declaration)
359 case DW_TAG_namespace:
360 case DW_TAG_imported_declaration:
365 case DW_TAG_variable:
366 if (name && has_location_or_const_value && is_global_or_static_variable) {
377 if (mangled_cstr && name != mangled_cstr &&
378 ((mangled_cstr[0] ==
'_') || (::strcmp(name, mangled_cstr) != 0))) {
399 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
418 ConstString class_name,
bool must_be_implementation,
419 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
433 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
435 auto name = context[0].name;
449 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
454 if (name_type_mask & eFunctionNameTypeFull) {
461 return callback(die);
466 if (name_type_mask & eFunctionNameTypeBase) {
473 return callback(die);
479 if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.
IsValid()) {
485 if (name_type_mask & eFunctionNameTypeSelector &&
495 llvm::function_ref<
bool(
DWARFDIE die)> callback) {
507 s.
Format(
"Manual DWARF index for ({0}) '{1:F}':",
510 s.
Printf(
"\nFunction basenames:\n");
512 s.
Printf(
"\nFunction fullnames:\n");
514 s.
Printf(
"\nFunction methods:\n");
516 s.
Printf(
"\nFunction selectors:\n");
518 s.
Printf(
"\nObjective-C class selectors:\n");
520 s.
Printf(
"\nGlobals and statics:\n");
524 s.
Printf(
"\nNamespaces:\n");
552 if (!strtab.
Decode(data, offset_ptr))
555 llvm::StringRef identifier((
const char *)data.
GetData(offset_ptr, 4), 4);
558 const uint32_t version = data.
GetU32(offset_ptr);
564 switch (data.
GetU8(offset_ptr)) {
624 if (!function_basenames.IsEmpty()) {
626 function_basenames.Encode(index_encoder, strtab);
628 if (!function_fullnames.IsEmpty()) {
630 function_fullnames.Encode(index_encoder, strtab);
632 if (!function_methods.IsEmpty()) {
634 function_methods.Encode(index_encoder, strtab);
636 if (!function_selectors.IsEmpty()) {
638 function_selectors.Encode(index_encoder, strtab);
640 if (!objc_class_selectors.IsEmpty()) {
642 objc_class_selectors.Encode(index_encoder, strtab);
644 if (!globals.IsEmpty()) {
646 globals.Encode(index_encoder, strtab);
648 if (!types.IsEmpty()) {
650 types.Encode(index_encoder, strtab);
652 if (!namespaces.IsEmpty()) {
654 namespaces.Encode(index_encoder, strtab);
666 bool &signature_mismatch) {
667 signature_mismatch =
false;
669 if (!signature.
Decode(data, offset_ptr))
672 signature_mismatch =
true;
676 if (!set.
Decode(data, offset_ptr))
678 m_set = std::move(set);
684 if (!signature.
Encode(encoder))
692 llvm::raw_string_ostream strm(key);
698 strm << objfile->
GetModule()->GetCacheKey() <<
"-dwarf-index-"
710 std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =
715 mem_buffer_up->getBufferSize(),
718 bool signature_mismatch =
false;
720 const bool result =
Decode(data, &offset, signature_mismatch);
721 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
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()
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
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