llvm-project
1374 строки · 48.7 Кб
1//===-- Symtab.cpp --------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <map>10#include <set>11
12#include "lldb/Core/DataFileCache.h"13#include "lldb/Core/Module.h"14#include "lldb/Core/RichManglingContext.h"15#include "lldb/Core/Section.h"16#include "lldb/Symbol/ObjectFile.h"17#include "lldb/Symbol/Symbol.h"18#include "lldb/Symbol/SymbolContext.h"19#include "lldb/Symbol/Symtab.h"20#include "lldb/Target/Language.h"21#include "lldb/Utility/DataEncoder.h"22#include "lldb/Utility/Endian.h"23#include "lldb/Utility/RegularExpression.h"24#include "lldb/Utility/Stream.h"25#include "lldb/Utility/Timer.h"26
27#include "llvm/ADT/ArrayRef.h"28#include "llvm/ADT/StringRef.h"29#include "llvm/Support/DJB.h"30
31using namespace lldb;32using namespace lldb_private;33
34Symtab::Symtab(ObjectFile *objfile)35: m_objfile(objfile), m_symbols(), m_file_addr_to_index(*this),36m_name_to_symbol_indices(), m_mutex(),37m_file_addr_to_index_computed(false), m_name_indexes_computed(false),38m_loaded_from_cache(false), m_saved_to_cache(false) {39m_name_to_symbol_indices.emplace(std::make_pair(40lldb::eFunctionNameTypeNone, UniqueCStringMap<uint32_t>()));41m_name_to_symbol_indices.emplace(std::make_pair(42lldb::eFunctionNameTypeBase, UniqueCStringMap<uint32_t>()));43m_name_to_symbol_indices.emplace(std::make_pair(44lldb::eFunctionNameTypeMethod, UniqueCStringMap<uint32_t>()));45m_name_to_symbol_indices.emplace(std::make_pair(46lldb::eFunctionNameTypeSelector, UniqueCStringMap<uint32_t>()));47}
48
49Symtab::~Symtab() = default;50
51void Symtab::Reserve(size_t count) {52// Clients should grab the mutex from this symbol table and lock it manually53// when calling this function to avoid performance issues.54m_symbols.reserve(count);55}
56
57Symbol *Symtab::Resize(size_t count) {58// Clients should grab the mutex from this symbol table and lock it manually59// when calling this function to avoid performance issues.60m_symbols.resize(count);61return m_symbols.empty() ? nullptr : &m_symbols[0];62}
63
64uint32_t Symtab::AddSymbol(const Symbol &symbol) {65// Clients should grab the mutex from this symbol table and lock it manually66// when calling this function to avoid performance issues.67uint32_t symbol_idx = m_symbols.size();68auto &name_to_index = GetNameToSymbolIndexMap(lldb::eFunctionNameTypeNone);69name_to_index.Clear();70m_file_addr_to_index.Clear();71m_symbols.push_back(symbol);72m_file_addr_to_index_computed = false;73m_name_indexes_computed = false;74return symbol_idx;75}
76
77size_t Symtab::GetNumSymbols() const {78std::lock_guard<std::recursive_mutex> guard(m_mutex);79return m_symbols.size();80}
81
82void Symtab::SectionFileAddressesChanged() {83m_file_addr_to_index.Clear();84m_file_addr_to_index_computed = false;85}
86
87void Symtab::Dump(Stream *s, Target *target, SortOrder sort_order,88Mangled::NamePreference name_preference) {89std::lock_guard<std::recursive_mutex> guard(m_mutex);90
91// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);92s->Indent();93const FileSpec &file_spec = m_objfile->GetFileSpec();94const char *object_name = nullptr;95if (m_objfile->GetModule())96object_name = m_objfile->GetModule()->GetObjectName().GetCString();97
98if (file_spec)99s->Printf("Symtab, file = %s%s%s%s, num_symbols = %" PRIu64,100file_spec.GetPath().c_str(), object_name ? "(" : "",101object_name ? object_name : "", object_name ? ")" : "",102(uint64_t)m_symbols.size());103else104s->Printf("Symtab, num_symbols = %" PRIu64 "", (uint64_t)m_symbols.size());105
106if (!m_symbols.empty()) {107switch (sort_order) {108case eSortOrderNone: {109s->PutCString(":\n");110DumpSymbolHeader(s);111const_iterator begin = m_symbols.begin();112const_iterator end = m_symbols.end();113for (const_iterator pos = m_symbols.begin(); pos != end; ++pos) {114s->Indent();115pos->Dump(s, target, std::distance(begin, pos), name_preference);116}117}118break;119
120case eSortOrderByName: {121// Although we maintain a lookup by exact name map, the table isn't122// sorted by name. So we must make the ordered symbol list up ourselves.123s->PutCString(" (sorted by name):\n");124DumpSymbolHeader(s);125
126std::multimap<llvm::StringRef, const Symbol *> name_map;127for (const Symbol &symbol : m_symbols)128name_map.emplace(symbol.GetName().GetStringRef(), &symbol);129
130for (const auto &name_to_symbol : name_map) {131const Symbol *symbol = name_to_symbol.second;132s->Indent();133symbol->Dump(s, target, symbol - &m_symbols[0], name_preference);134}135} break;136
137case eSortOrderBySize: {138s->PutCString(" (sorted by size):\n");139DumpSymbolHeader(s);140
141std::multimap<size_t, const Symbol *, std::greater<size_t>> size_map;142for (const Symbol &symbol : m_symbols)143size_map.emplace(symbol.GetByteSize(), &symbol);144
145size_t idx = 0;146for (const auto &size_to_symbol : size_map) {147const Symbol *symbol = size_to_symbol.second;148s->Indent();149symbol->Dump(s, target, idx++, name_preference);150}151} break;152
153case eSortOrderByAddress:154s->PutCString(" (sorted by address):\n");155DumpSymbolHeader(s);156if (!m_file_addr_to_index_computed)157InitAddressIndexes();158const size_t num_entries = m_file_addr_to_index.GetSize();159for (size_t i = 0; i < num_entries; ++i) {160s->Indent();161const uint32_t symbol_idx = m_file_addr_to_index.GetEntryRef(i).data;162m_symbols[symbol_idx].Dump(s, target, symbol_idx, name_preference);163}164break;165}166} else {167s->PutCString("\n");168}169}
170
171void Symtab::Dump(Stream *s, Target *target, std::vector<uint32_t> &indexes,172Mangled::NamePreference name_preference) const {173std::lock_guard<std::recursive_mutex> guard(m_mutex);174
175const size_t num_symbols = GetNumSymbols();176// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);177s->Indent();178s->Printf("Symtab %" PRIu64 " symbol indexes (%" PRIu64 " symbols total):\n",179(uint64_t)indexes.size(), (uint64_t)m_symbols.size());180s->IndentMore();181
182if (!indexes.empty()) {183std::vector<uint32_t>::const_iterator pos;184std::vector<uint32_t>::const_iterator end = indexes.end();185DumpSymbolHeader(s);186for (pos = indexes.begin(); pos != end; ++pos) {187size_t idx = *pos;188if (idx < num_symbols) {189s->Indent();190m_symbols[idx].Dump(s, target, idx, name_preference);191}192}193}194s->IndentLess();195}
196
197void Symtab::DumpSymbolHeader(Stream *s) {198s->Indent(" Debug symbol\n");199s->Indent(" |Synthetic symbol\n");200s->Indent(" ||Externally Visible\n");201s->Indent(" |||\n");202s->Indent("Index UserID DSX Type File Address/Value Load "203"Address Size Flags Name\n");204s->Indent("------- ------ --- --------------- ------------------ "205"------------------ ------------------ ---------- "206"----------------------------------\n");207}
208
209static int CompareSymbolID(const void *key, const void *p) {210const user_id_t match_uid = *(const user_id_t *)key;211const user_id_t symbol_uid = ((const Symbol *)p)->GetID();212if (match_uid < symbol_uid)213return -1;214if (match_uid > symbol_uid)215return 1;216return 0;217}
218
219Symbol *Symtab::FindSymbolByID(lldb::user_id_t symbol_uid) const {220std::lock_guard<std::recursive_mutex> guard(m_mutex);221
222Symbol *symbol =223(Symbol *)::bsearch(&symbol_uid, &m_symbols[0], m_symbols.size(),224sizeof(m_symbols[0]), CompareSymbolID);225return symbol;226}
227
228Symbol *Symtab::SymbolAtIndex(size_t idx) {229// Clients should grab the mutex from this symbol table and lock it manually230// when calling this function to avoid performance issues.231if (idx < m_symbols.size())232return &m_symbols[idx];233return nullptr;234}
235
236const Symbol *Symtab::SymbolAtIndex(size_t idx) const {237// Clients should grab the mutex from this symbol table and lock it manually238// when calling this function to avoid performance issues.239if (idx < m_symbols.size())240return &m_symbols[idx];241return nullptr;242}
243
244static bool lldb_skip_name(llvm::StringRef mangled,245Mangled::ManglingScheme scheme) {246switch (scheme) {247case Mangled::eManglingSchemeItanium: {248if (mangled.size() < 3 || !mangled.starts_with("_Z"))249return true;250
251// Avoid the following types of symbols in the index.252switch (mangled[2]) {253case 'G': // guard variables254case 'T': // virtual tables, VTT structures, typeinfo structures + names255case 'Z': // named local entities (if we eventually handle256// eSymbolTypeData, we will want this back)257return true;258
259default:260break;261}262
263// Include this name in the index.264return false;265}266
267// No filters for this scheme yet. Include all names in indexing.268case Mangled::eManglingSchemeMSVC:269case Mangled::eManglingSchemeRustV0:270case Mangled::eManglingSchemeD:271case Mangled::eManglingSchemeSwift:272return false;273
274// Don't try and demangle things we can't categorize.275case Mangled::eManglingSchemeNone:276return true;277}278llvm_unreachable("unknown scheme!");279}
280
281void Symtab::InitNameIndexes() {282// Protected function, no need to lock mutex...283if (!m_name_indexes_computed) {284m_name_indexes_computed = true;285ElapsedTime elapsed(m_objfile->GetModule()->GetSymtabIndexTime());286LLDB_SCOPED_TIMER();287
288// Collect all loaded language plugins.289std::vector<Language *> languages;290Language::ForEach([&languages](Language *l) {291languages.push_back(l);292return true;293});294
295auto &name_to_index = GetNameToSymbolIndexMap(lldb::eFunctionNameTypeNone);296auto &basename_to_index =297GetNameToSymbolIndexMap(lldb::eFunctionNameTypeBase);298auto &method_to_index =299GetNameToSymbolIndexMap(lldb::eFunctionNameTypeMethod);300auto &selector_to_index =301GetNameToSymbolIndexMap(lldb::eFunctionNameTypeSelector);302// Create the name index vector to be able to quickly search by name303const size_t num_symbols = m_symbols.size();304name_to_index.Reserve(num_symbols);305
306// The "const char *" in "class_contexts" and backlog::value_type::second307// must come from a ConstString::GetCString()308std::set<const char *> class_contexts;309std::vector<std::pair<NameToIndexMap::Entry, const char *>> backlog;310backlog.reserve(num_symbols / 2);311
312// Instantiation of the demangler is expensive, so better use a single one313// for all entries during batch processing.314RichManglingContext rmc;315for (uint32_t value = 0; value < num_symbols; ++value) {316Symbol *symbol = &m_symbols[value];317
318// Don't let trampolines get into the lookup by name map If we ever need319// the trampoline symbols to be searchable by name we can remove this and320// then possibly add a new bool to any of the Symtab functions that321// lookup symbols by name to indicate if they want trampolines. We also322// don't want any synthetic symbols with auto generated names in the323// name lookups.324if (symbol->IsTrampoline() || symbol->IsSyntheticWithAutoGeneratedName())325continue;326
327// If the symbol's name string matched a Mangled::ManglingScheme, it is328// stored in the mangled field.329Mangled &mangled = symbol->GetMangled();330if (ConstString name = mangled.GetMangledName()) {331name_to_index.Append(name, value);332
333if (symbol->ContainsLinkerAnnotations()) {334// If the symbol has linker annotations, also add the version without335// the annotations.336ConstString stripped = ConstString(337m_objfile->StripLinkerSymbolAnnotations(name.GetStringRef()));338name_to_index.Append(stripped, value);339}340
341const SymbolType type = symbol->GetType();342if (type == eSymbolTypeCode || type == eSymbolTypeResolver) {343if (mangled.GetRichManglingInfo(rmc, lldb_skip_name)) {344RegisterMangledNameEntry(value, class_contexts, backlog, rmc);345continue;346}347}348}349
350// Symbol name strings that didn't match a Mangled::ManglingScheme, are351// stored in the demangled field.352if (ConstString name = mangled.GetDemangledName()) {353name_to_index.Append(name, value);354
355if (symbol->ContainsLinkerAnnotations()) {356// If the symbol has linker annotations, also add the version without357// the annotations.358name = ConstString(359m_objfile->StripLinkerSymbolAnnotations(name.GetStringRef()));360name_to_index.Append(name, value);361}362
363// If the demangled name turns out to be an ObjC name, and is a category364// name, add the version without categories to the index too.365for (Language *lang : languages) {366for (auto variant : lang->GetMethodNameVariants(name)) {367if (variant.GetType() & lldb::eFunctionNameTypeSelector)368selector_to_index.Append(variant.GetName(), value);369else if (variant.GetType() & lldb::eFunctionNameTypeFull)370name_to_index.Append(variant.GetName(), value);371else if (variant.GetType() & lldb::eFunctionNameTypeMethod)372method_to_index.Append(variant.GetName(), value);373else if (variant.GetType() & lldb::eFunctionNameTypeBase)374basename_to_index.Append(variant.GetName(), value);375}376}377}378}379
380for (const auto &record : backlog) {381RegisterBacklogEntry(record.first, record.second, class_contexts);382}383
384name_to_index.Sort();385name_to_index.SizeToFit();386selector_to_index.Sort();387selector_to_index.SizeToFit();388basename_to_index.Sort();389basename_to_index.SizeToFit();390method_to_index.Sort();391method_to_index.SizeToFit();392}393}
394
395void Symtab::RegisterMangledNameEntry(396uint32_t value, std::set<const char *> &class_contexts,397std::vector<std::pair<NameToIndexMap::Entry, const char *>> &backlog,398RichManglingContext &rmc) {399// Only register functions that have a base name.400llvm::StringRef base_name = rmc.ParseFunctionBaseName();401if (base_name.empty())402return;403
404// The base name will be our entry's name.405NameToIndexMap::Entry entry(ConstString(base_name), value);406llvm::StringRef decl_context = rmc.ParseFunctionDeclContextName();407
408// Register functions with no context.409if (decl_context.empty()) {410// This has to be a basename411auto &basename_to_index =412GetNameToSymbolIndexMap(lldb::eFunctionNameTypeBase);413basename_to_index.Append(entry);414// If there is no context (no namespaces or class scopes that come before415// the function name) then this also could be a fullname.416auto &name_to_index = GetNameToSymbolIndexMap(lldb::eFunctionNameTypeNone);417name_to_index.Append(entry);418return;419}420
421// Make sure we have a pool-string pointer and see if we already know the422// context name.423const char *decl_context_ccstr = ConstString(decl_context).GetCString();424auto it = class_contexts.find(decl_context_ccstr);425
426auto &method_to_index =427GetNameToSymbolIndexMap(lldb::eFunctionNameTypeMethod);428// Register constructors and destructors. They are methods and create429// declaration contexts.430if (rmc.IsCtorOrDtor()) {431method_to_index.Append(entry);432if (it == class_contexts.end())433class_contexts.insert(it, decl_context_ccstr);434return;435}436
437// Register regular methods with a known declaration context.438if (it != class_contexts.end()) {439method_to_index.Append(entry);440return;441}442
443// Regular methods in unknown declaration contexts are put to the backlog. We444// will revisit them once we processed all remaining symbols.445backlog.push_back(std::make_pair(entry, decl_context_ccstr));446}
447
448void Symtab::RegisterBacklogEntry(449const NameToIndexMap::Entry &entry, const char *decl_context,450const std::set<const char *> &class_contexts) {451auto &method_to_index =452GetNameToSymbolIndexMap(lldb::eFunctionNameTypeMethod);453auto it = class_contexts.find(decl_context);454if (it != class_contexts.end()) {455method_to_index.Append(entry);456} else {457// If we got here, we have something that had a context (was inside458// a namespace or class) yet we don't know the entry459method_to_index.Append(entry);460auto &basename_to_index =461GetNameToSymbolIndexMap(lldb::eFunctionNameTypeBase);462basename_to_index.Append(entry);463}464}
465
466void Symtab::PreloadSymbols() {467std::lock_guard<std::recursive_mutex> guard(m_mutex);468InitNameIndexes();469}
470
471void Symtab::AppendSymbolNamesToMap(const IndexCollection &indexes,472bool add_demangled, bool add_mangled,473NameToIndexMap &name_to_index_map) const {474LLDB_SCOPED_TIMER();475if (add_demangled || add_mangled) {476std::lock_guard<std::recursive_mutex> guard(m_mutex);477
478// Create the name index vector to be able to quickly search by name479const size_t num_indexes = indexes.size();480for (size_t i = 0; i < num_indexes; ++i) {481uint32_t value = indexes[i];482assert(i < m_symbols.size());483const Symbol *symbol = &m_symbols[value];484
485const Mangled &mangled = symbol->GetMangled();486if (add_demangled) {487if (ConstString name = mangled.GetDemangledName())488name_to_index_map.Append(name, value);489}490
491if (add_mangled) {492if (ConstString name = mangled.GetMangledName())493name_to_index_map.Append(name, value);494}495}496}497}
498
499uint32_t Symtab::AppendSymbolIndexesWithType(SymbolType symbol_type,500std::vector<uint32_t> &indexes,501uint32_t start_idx,502uint32_t end_index) const {503std::lock_guard<std::recursive_mutex> guard(m_mutex);504
505uint32_t prev_size = indexes.size();506
507const uint32_t count = std::min<uint32_t>(m_symbols.size(), end_index);508
509for (uint32_t i = start_idx; i < count; ++i) {510if (symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type)511indexes.push_back(i);512}513
514return indexes.size() - prev_size;515}
516
517uint32_t Symtab::AppendSymbolIndexesWithTypeAndFlagsValue(518SymbolType symbol_type, uint32_t flags_value,519std::vector<uint32_t> &indexes, uint32_t start_idx,520uint32_t end_index) const {521std::lock_guard<std::recursive_mutex> guard(m_mutex);522
523uint32_t prev_size = indexes.size();524
525const uint32_t count = std::min<uint32_t>(m_symbols.size(), end_index);526
527for (uint32_t i = start_idx; i < count; ++i) {528if ((symbol_type == eSymbolTypeAny ||529m_symbols[i].GetType() == symbol_type) &&530m_symbols[i].GetFlags() == flags_value)531indexes.push_back(i);532}533
534return indexes.size() - prev_size;535}
536
537uint32_t Symtab::AppendSymbolIndexesWithType(SymbolType symbol_type,538Debug symbol_debug_type,539Visibility symbol_visibility,540std::vector<uint32_t> &indexes,541uint32_t start_idx,542uint32_t end_index) const {543std::lock_guard<std::recursive_mutex> guard(m_mutex);544
545uint32_t prev_size = indexes.size();546
547const uint32_t count = std::min<uint32_t>(m_symbols.size(), end_index);548
549for (uint32_t i = start_idx; i < count; ++i) {550if (symbol_type == eSymbolTypeAny ||551m_symbols[i].GetType() == symbol_type) {552if (CheckSymbolAtIndex(i, symbol_debug_type, symbol_visibility))553indexes.push_back(i);554}555}556
557return indexes.size() - prev_size;558}
559
560uint32_t Symtab::GetIndexForSymbol(const Symbol *symbol) const {561if (!m_symbols.empty()) {562const Symbol *first_symbol = &m_symbols[0];563if (symbol >= first_symbol && symbol < first_symbol + m_symbols.size())564return symbol - first_symbol;565}566return UINT32_MAX;567}
568
569struct SymbolSortInfo {570const bool sort_by_load_addr;571const Symbol *symbols;572};573
574namespace {575struct SymbolIndexComparator {576const std::vector<Symbol> &symbols;577std::vector<lldb::addr_t> &addr_cache;578
579// Getting from the symbol to the Address to the File Address involves some580// work. Since there are potentially many symbols here, and we're using this581// for sorting so we're going to be computing the address many times, cache582// that in addr_cache. The array passed in has to be the same size as the583// symbols array passed into the member variable symbols, and should be584// initialized with LLDB_INVALID_ADDRESS.585// NOTE: You have to make addr_cache externally and pass it in because586// std::stable_sort587// makes copies of the comparator it is initially passed in, and you end up588// spending huge amounts of time copying this array...589
590SymbolIndexComparator(const std::vector<Symbol> &s,591std::vector<lldb::addr_t> &a)592: symbols(s), addr_cache(a) {593assert(symbols.size() == addr_cache.size());594}595bool operator()(uint32_t index_a, uint32_t index_b) {596addr_t value_a = addr_cache[index_a];597if (value_a == LLDB_INVALID_ADDRESS) {598value_a = symbols[index_a].GetAddressRef().GetFileAddress();599addr_cache[index_a] = value_a;600}601
602addr_t value_b = addr_cache[index_b];603if (value_b == LLDB_INVALID_ADDRESS) {604value_b = symbols[index_b].GetAddressRef().GetFileAddress();605addr_cache[index_b] = value_b;606}607
608if (value_a == value_b) {609// The if the values are equal, use the original symbol user ID610lldb::user_id_t uid_a = symbols[index_a].GetID();611lldb::user_id_t uid_b = symbols[index_b].GetID();612if (uid_a < uid_b)613return true;614if (uid_a > uid_b)615return false;616return false;617} else if (value_a < value_b)618return true;619
620return false;621}622};623}
624
625void Symtab::SortSymbolIndexesByValue(std::vector<uint32_t> &indexes,626bool remove_duplicates) const {627std::lock_guard<std::recursive_mutex> guard(m_mutex);628LLDB_SCOPED_TIMER();629// No need to sort if we have zero or one items...630if (indexes.size() <= 1)631return;632
633// Sort the indexes in place using std::stable_sort.634// NOTE: The use of std::stable_sort instead of llvm::sort here is strictly635// for performance, not correctness. The indexes vector tends to be "close"636// to sorted, which the stable sort handles better.637
638std::vector<lldb::addr_t> addr_cache(m_symbols.size(), LLDB_INVALID_ADDRESS);639
640SymbolIndexComparator comparator(m_symbols, addr_cache);641std::stable_sort(indexes.begin(), indexes.end(), comparator);642
643// Remove any duplicates if requested644if (remove_duplicates) {645auto last = std::unique(indexes.begin(), indexes.end());646indexes.erase(last, indexes.end());647}648}
649
650uint32_t Symtab::GetNameIndexes(ConstString symbol_name,651std::vector<uint32_t> &indexes) {652auto &name_to_index = GetNameToSymbolIndexMap(lldb::eFunctionNameTypeNone);653const uint32_t count = name_to_index.GetValues(symbol_name, indexes);654if (count)655return count;656// Synthetic symbol names are not added to the name indexes, but they start657// with a prefix and end with a the symbol UserID. This allows users to find658// these symbols without having to add them to the name indexes. These659// queries will not happen very often since the names don't mean anything, so660// performance is not paramount in this case.661llvm::StringRef name = symbol_name.GetStringRef();662// String the synthetic prefix if the name starts with it.663if (!name.consume_front(Symbol::GetSyntheticSymbolPrefix()))664return 0; // Not a synthetic symbol name665
666// Extract the user ID from the symbol name667unsigned long long uid = 0;668if (getAsUnsignedInteger(name, /*Radix=*/10, uid))669return 0; // Failed to extract the user ID as an integer670Symbol *symbol = FindSymbolByID(uid);671if (symbol == nullptr)672return 0;673const uint32_t symbol_idx = GetIndexForSymbol(symbol);674if (symbol_idx == UINT32_MAX)675return 0;676indexes.push_back(symbol_idx);677return 1;678}
679
680uint32_t Symtab::AppendSymbolIndexesWithName(ConstString symbol_name,681std::vector<uint32_t> &indexes) {682std::lock_guard<std::recursive_mutex> guard(m_mutex);683
684if (symbol_name) {685if (!m_name_indexes_computed)686InitNameIndexes();687
688return GetNameIndexes(symbol_name, indexes);689}690return 0;691}
692
693uint32_t Symtab::AppendSymbolIndexesWithName(ConstString symbol_name,694Debug symbol_debug_type,695Visibility symbol_visibility,696std::vector<uint32_t> &indexes) {697std::lock_guard<std::recursive_mutex> guard(m_mutex);698
699LLDB_SCOPED_TIMER();700if (symbol_name) {701const size_t old_size = indexes.size();702if (!m_name_indexes_computed)703InitNameIndexes();704
705std::vector<uint32_t> all_name_indexes;706const size_t name_match_count =707GetNameIndexes(symbol_name, all_name_indexes);708for (size_t i = 0; i < name_match_count; ++i) {709if (CheckSymbolAtIndex(all_name_indexes[i], symbol_debug_type,710symbol_visibility))711indexes.push_back(all_name_indexes[i]);712}713return indexes.size() - old_size;714}715return 0;716}
717
718uint32_t
719Symtab::AppendSymbolIndexesWithNameAndType(ConstString symbol_name,720SymbolType symbol_type,721std::vector<uint32_t> &indexes) {722std::lock_guard<std::recursive_mutex> guard(m_mutex);723
724if (AppendSymbolIndexesWithName(symbol_name, indexes) > 0) {725std::vector<uint32_t>::iterator pos = indexes.begin();726while (pos != indexes.end()) {727if (symbol_type == eSymbolTypeAny ||728m_symbols[*pos].GetType() == symbol_type)729++pos;730else731pos = indexes.erase(pos);732}733}734return indexes.size();735}
736
737uint32_t Symtab::AppendSymbolIndexesWithNameAndType(738ConstString symbol_name, SymbolType symbol_type,739Debug symbol_debug_type, Visibility symbol_visibility,740std::vector<uint32_t> &indexes) {741std::lock_guard<std::recursive_mutex> guard(m_mutex);742
743if (AppendSymbolIndexesWithName(symbol_name, symbol_debug_type,744symbol_visibility, indexes) > 0) {745std::vector<uint32_t>::iterator pos = indexes.begin();746while (pos != indexes.end()) {747if (symbol_type == eSymbolTypeAny ||748m_symbols[*pos].GetType() == symbol_type)749++pos;750else751pos = indexes.erase(pos);752}753}754return indexes.size();755}
756
757uint32_t Symtab::AppendSymbolIndexesMatchingRegExAndType(758const RegularExpression ®exp, SymbolType symbol_type,759std::vector<uint32_t> &indexes, Mangled::NamePreference name_preference) {760std::lock_guard<std::recursive_mutex> guard(m_mutex);761
762uint32_t prev_size = indexes.size();763uint32_t sym_end = m_symbols.size();764
765for (uint32_t i = 0; i < sym_end; i++) {766if (symbol_type == eSymbolTypeAny ||767m_symbols[i].GetType() == symbol_type) {768const char *name =769m_symbols[i].GetMangled().GetName(name_preference).AsCString();770if (name) {771if (regexp.Execute(name))772indexes.push_back(i);773}774}775}776return indexes.size() - prev_size;777}
778
779uint32_t Symtab::AppendSymbolIndexesMatchingRegExAndType(780const RegularExpression ®exp, SymbolType symbol_type,781Debug symbol_debug_type, Visibility symbol_visibility,782std::vector<uint32_t> &indexes, Mangled::NamePreference name_preference) {783std::lock_guard<std::recursive_mutex> guard(m_mutex);784
785uint32_t prev_size = indexes.size();786uint32_t sym_end = m_symbols.size();787
788for (uint32_t i = 0; i < sym_end; i++) {789if (symbol_type == eSymbolTypeAny ||790m_symbols[i].GetType() == symbol_type) {791if (!CheckSymbolAtIndex(i, symbol_debug_type, symbol_visibility))792continue;793
794const char *name =795m_symbols[i].GetMangled().GetName(name_preference).AsCString();796if (name) {797if (regexp.Execute(name))798indexes.push_back(i);799}800}801}802return indexes.size() - prev_size;803}
804
805Symbol *Symtab::FindSymbolWithType(SymbolType symbol_type,806Debug symbol_debug_type,807Visibility symbol_visibility,808uint32_t &start_idx) {809std::lock_guard<std::recursive_mutex> guard(m_mutex);810
811const size_t count = m_symbols.size();812for (size_t idx = start_idx; idx < count; ++idx) {813if (symbol_type == eSymbolTypeAny ||814m_symbols[idx].GetType() == symbol_type) {815if (CheckSymbolAtIndex(idx, symbol_debug_type, symbol_visibility)) {816start_idx = idx;817return &m_symbols[idx];818}819}820}821return nullptr;822}
823
824void
825Symtab::FindAllSymbolsWithNameAndType(ConstString name,826SymbolType symbol_type,827std::vector<uint32_t> &symbol_indexes) {828std::lock_guard<std::recursive_mutex> guard(m_mutex);829
830// Initialize all of the lookup by name indexes before converting NAME to a831// uniqued string NAME_STR below.832if (!m_name_indexes_computed)833InitNameIndexes();834
835if (name) {836// The string table did have a string that matched, but we need to check837// the symbols and match the symbol_type if any was given.838AppendSymbolIndexesWithNameAndType(name, symbol_type, symbol_indexes);839}840}
841
842void Symtab::FindAllSymbolsWithNameAndType(843ConstString name, SymbolType symbol_type, Debug symbol_debug_type,844Visibility symbol_visibility, std::vector<uint32_t> &symbol_indexes) {845std::lock_guard<std::recursive_mutex> guard(m_mutex);846
847LLDB_SCOPED_TIMER();848// Initialize all of the lookup by name indexes before converting NAME to a849// uniqued string NAME_STR below.850if (!m_name_indexes_computed)851InitNameIndexes();852
853if (name) {854// The string table did have a string that matched, but we need to check855// the symbols and match the symbol_type if any was given.856AppendSymbolIndexesWithNameAndType(name, symbol_type, symbol_debug_type,857symbol_visibility, symbol_indexes);858}859}
860
861void Symtab::FindAllSymbolsMatchingRexExAndType(862const RegularExpression ®ex, SymbolType symbol_type,863Debug symbol_debug_type, Visibility symbol_visibility,864std::vector<uint32_t> &symbol_indexes,865Mangled::NamePreference name_preference) {866std::lock_guard<std::recursive_mutex> guard(m_mutex);867
868AppendSymbolIndexesMatchingRegExAndType(regex, symbol_type, symbol_debug_type,869symbol_visibility, symbol_indexes,870name_preference);871}
872
873Symbol *Symtab::FindFirstSymbolWithNameAndType(ConstString name,874SymbolType symbol_type,875Debug symbol_debug_type,876Visibility symbol_visibility) {877std::lock_guard<std::recursive_mutex> guard(m_mutex);878LLDB_SCOPED_TIMER();879if (!m_name_indexes_computed)880InitNameIndexes();881
882if (name) {883std::vector<uint32_t> matching_indexes;884// The string table did have a string that matched, but we need to check885// the symbols and match the symbol_type if any was given.886if (AppendSymbolIndexesWithNameAndType(name, symbol_type, symbol_debug_type,887symbol_visibility,888matching_indexes)) {889std::vector<uint32_t>::const_iterator pos, end = matching_indexes.end();890for (pos = matching_indexes.begin(); pos != end; ++pos) {891Symbol *symbol = SymbolAtIndex(*pos);892
893if (symbol->Compare(name, symbol_type))894return symbol;895}896}897}898return nullptr;899}
900
901typedef struct {902const Symtab *symtab;903const addr_t file_addr;904Symbol *match_symbol;905const uint32_t *match_index_ptr;906addr_t match_offset;907} SymbolSearchInfo;908
909// Add all the section file start address & size to the RangeVector, recusively
910// adding any children sections.
911static void AddSectionsToRangeMap(SectionList *sectlist,912RangeVector<addr_t, addr_t> §ion_ranges) {913const int num_sections = sectlist->GetNumSections(0);914for (int i = 0; i < num_sections; i++) {915SectionSP sect_sp = sectlist->GetSectionAtIndex(i);916if (sect_sp) {917SectionList &child_sectlist = sect_sp->GetChildren();918
919// If this section has children, add the children to the RangeVector.920// Else add this section to the RangeVector.921if (child_sectlist.GetNumSections(0) > 0) {922AddSectionsToRangeMap(&child_sectlist, section_ranges);923} else {924size_t size = sect_sp->GetByteSize();925if (size > 0) {926addr_t base_addr = sect_sp->GetFileAddress();927RangeVector<addr_t, addr_t>::Entry entry;928entry.SetRangeBase(base_addr);929entry.SetByteSize(size);930section_ranges.Append(entry);931}932}933}934}935}
936
937void Symtab::InitAddressIndexes() {938// Protected function, no need to lock mutex...939if (!m_file_addr_to_index_computed && !m_symbols.empty()) {940m_file_addr_to_index_computed = true;941
942FileRangeToIndexMap::Entry entry;943const_iterator begin = m_symbols.begin();944const_iterator end = m_symbols.end();945for (const_iterator pos = m_symbols.begin(); pos != end; ++pos) {946if (pos->ValueIsAddress()) {947entry.SetRangeBase(pos->GetAddressRef().GetFileAddress());948entry.SetByteSize(pos->GetByteSize());949entry.data = std::distance(begin, pos);950m_file_addr_to_index.Append(entry);951}952}953const size_t num_entries = m_file_addr_to_index.GetSize();954if (num_entries > 0) {955m_file_addr_to_index.Sort();956
957// Create a RangeVector with the start & size of all the sections for958// this objfile. We'll need to check this for any FileRangeToIndexMap959// entries with an uninitialized size, which could potentially be a large960// number so reconstituting the weak pointer is busywork when it is961// invariant information.962SectionList *sectlist = m_objfile->GetSectionList();963RangeVector<addr_t, addr_t> section_ranges;964if (sectlist) {965AddSectionsToRangeMap(sectlist, section_ranges);966section_ranges.Sort();967}968
969// Iterate through the FileRangeToIndexMap and fill in the size for any970// entries that didn't already have a size from the Symbol (e.g. if we971// have a plain linker symbol with an address only, instead of debug info972// where we get an address and a size and a type, etc.)973for (size_t i = 0; i < num_entries; i++) {974FileRangeToIndexMap::Entry *entry =975m_file_addr_to_index.GetMutableEntryAtIndex(i);976if (entry->GetByteSize() == 0) {977addr_t curr_base_addr = entry->GetRangeBase();978const RangeVector<addr_t, addr_t>::Entry *containing_section =979section_ranges.FindEntryThatContains(curr_base_addr);980
981// Use the end of the section as the default max size of the symbol982addr_t sym_size = 0;983if (containing_section) {984sym_size =985containing_section->GetByteSize() -986(entry->GetRangeBase() - containing_section->GetRangeBase());987}988
989for (size_t j = i; j < num_entries; j++) {990FileRangeToIndexMap::Entry *next_entry =991m_file_addr_to_index.GetMutableEntryAtIndex(j);992addr_t next_base_addr = next_entry->GetRangeBase();993if (next_base_addr > curr_base_addr) {994addr_t size_to_next_symbol = next_base_addr - curr_base_addr;995
996// Take the difference between this symbol and the next one as997// its size, if it is less than the size of the section.998if (sym_size == 0 || size_to_next_symbol < sym_size) {999sym_size = size_to_next_symbol;1000}1001break;1002}1003}1004
1005if (sym_size > 0) {1006entry->SetByteSize(sym_size);1007Symbol &symbol = m_symbols[entry->data];1008symbol.SetByteSize(sym_size);1009symbol.SetSizeIsSynthesized(true);1010}1011}1012}1013
1014// Sort again in case the range size changes the ordering1015m_file_addr_to_index.Sort();1016}1017}1018}
1019
1020void Symtab::Finalize() {1021std::lock_guard<std::recursive_mutex> guard(m_mutex);1022// Calculate the size of symbols inside InitAddressIndexes.1023InitAddressIndexes();1024// Shrink to fit the symbols so we don't waste memory1025m_symbols.shrink_to_fit();1026SaveToCache();1027}
1028
1029Symbol *Symtab::FindSymbolAtFileAddress(addr_t file_addr) {1030std::lock_guard<std::recursive_mutex> guard(m_mutex);1031if (!m_file_addr_to_index_computed)1032InitAddressIndexes();1033
1034const FileRangeToIndexMap::Entry *entry =1035m_file_addr_to_index.FindEntryStartsAt(file_addr);1036if (entry) {1037Symbol *symbol = SymbolAtIndex(entry->data);1038if (symbol->GetFileAddress() == file_addr)1039return symbol;1040}1041return nullptr;1042}
1043
1044Symbol *Symtab::FindSymbolContainingFileAddress(addr_t file_addr) {1045std::lock_guard<std::recursive_mutex> guard(m_mutex);1046
1047if (!m_file_addr_to_index_computed)1048InitAddressIndexes();1049
1050const FileRangeToIndexMap::Entry *entry =1051m_file_addr_to_index.FindEntryThatContains(file_addr);1052if (entry) {1053Symbol *symbol = SymbolAtIndex(entry->data);1054if (symbol->ContainsFileAddress(file_addr))1055return symbol;1056}1057return nullptr;1058}
1059
1060void Symtab::ForEachSymbolContainingFileAddress(1061addr_t file_addr, std::function<bool(Symbol *)> const &callback) {1062std::lock_guard<std::recursive_mutex> guard(m_mutex);1063
1064if (!m_file_addr_to_index_computed)1065InitAddressIndexes();1066
1067std::vector<uint32_t> all_addr_indexes;1068
1069// Get all symbols with file_addr1070const size_t addr_match_count =1071m_file_addr_to_index.FindEntryIndexesThatContain(file_addr,1072all_addr_indexes);1073
1074for (size_t i = 0; i < addr_match_count; ++i) {1075Symbol *symbol = SymbolAtIndex(all_addr_indexes[i]);1076if (symbol->ContainsFileAddress(file_addr)) {1077if (!callback(symbol))1078break;1079}1080}1081}
1082
1083void Symtab::SymbolIndicesToSymbolContextList(1084std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list) {1085// No need to protect this call using m_mutex all other method calls are1086// already thread safe.1087
1088const bool merge_symbol_into_function = true;1089size_t num_indices = symbol_indexes.size();1090if (num_indices > 0) {1091SymbolContext sc;1092sc.module_sp = m_objfile->GetModule();1093for (size_t i = 0; i < num_indices; i++) {1094sc.symbol = SymbolAtIndex(symbol_indexes[i]);1095if (sc.symbol)1096sc_list.AppendIfUnique(sc, merge_symbol_into_function);1097}1098}1099}
1100
1101void Symtab::FindFunctionSymbols(ConstString name, uint32_t name_type_mask,1102SymbolContextList &sc_list) {1103std::vector<uint32_t> symbol_indexes;1104
1105// eFunctionNameTypeAuto should be pre-resolved by a call to1106// Module::LookupInfo::LookupInfo()1107assert((name_type_mask & eFunctionNameTypeAuto) == 0);1108
1109if (name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull)) {1110std::vector<uint32_t> temp_symbol_indexes;1111FindAllSymbolsWithNameAndType(name, eSymbolTypeAny, temp_symbol_indexes);1112
1113unsigned temp_symbol_indexes_size = temp_symbol_indexes.size();1114if (temp_symbol_indexes_size > 0) {1115std::lock_guard<std::recursive_mutex> guard(m_mutex);1116for (unsigned i = 0; i < temp_symbol_indexes_size; i++) {1117SymbolContext sym_ctx;1118sym_ctx.symbol = SymbolAtIndex(temp_symbol_indexes[i]);1119if (sym_ctx.symbol) {1120switch (sym_ctx.symbol->GetType()) {1121case eSymbolTypeCode:1122case eSymbolTypeResolver:1123case eSymbolTypeReExported:1124case eSymbolTypeAbsolute:1125symbol_indexes.push_back(temp_symbol_indexes[i]);1126break;1127default:1128break;1129}1130}1131}1132}1133}1134
1135if (!m_name_indexes_computed)1136InitNameIndexes();1137
1138for (lldb::FunctionNameType type :1139{lldb::eFunctionNameTypeBase, lldb::eFunctionNameTypeMethod,1140lldb::eFunctionNameTypeSelector}) {1141if (name_type_mask & type) {1142auto map = GetNameToSymbolIndexMap(type);1143
1144const UniqueCStringMap<uint32_t>::Entry *match;1145for (match = map.FindFirstValueForName(name); match != nullptr;1146match = map.FindNextValueForName(match)) {1147symbol_indexes.push_back(match->value);1148}1149}1150}1151
1152if (!symbol_indexes.empty()) {1153llvm::sort(symbol_indexes);1154symbol_indexes.erase(1155std::unique(symbol_indexes.begin(), symbol_indexes.end()),1156symbol_indexes.end());1157SymbolIndicesToSymbolContextList(symbol_indexes, sc_list);1158}1159}
1160
1161const Symbol *Symtab::GetParent(Symbol *child_symbol) const {1162uint32_t child_idx = GetIndexForSymbol(child_symbol);1163if (child_idx != UINT32_MAX && child_idx > 0) {1164for (uint32_t idx = child_idx - 1; idx != UINT32_MAX; --idx) {1165const Symbol *symbol = SymbolAtIndex(idx);1166const uint32_t sibling_idx = symbol->GetSiblingIndex();1167if (sibling_idx != UINT32_MAX && sibling_idx > child_idx)1168return symbol;1169}1170}1171return nullptr;1172}
1173
1174std::string Symtab::GetCacheKey() {1175std::string key;1176llvm::raw_string_ostream strm(key);1177// Symbol table can come from different object files for the same module. A1178// module can have one object file as the main executable and might have1179// another object file in a separate symbol file.1180strm << m_objfile->GetModule()->GetCacheKey() << "-symtab-"1181<< llvm::format_hex(m_objfile->GetCacheHash(), 10);1182return strm.str();1183}
1184
1185void Symtab::SaveToCache() {1186DataFileCache *cache = Module::GetIndexCache();1187if (!cache)1188return; // Caching is not enabled.1189InitNameIndexes(); // Init the name indexes so we can cache them as well.1190const auto byte_order = endian::InlHostByteOrder();1191DataEncoder file(byte_order, /*addr_size=*/8);1192// Encode will return false if the symbol table's object file doesn't have1193// anything to make a signature from.1194if (Encode(file))1195if (cache->SetCachedData(GetCacheKey(), file.GetData()))1196SetWasSavedToCache();1197}
1198
1199constexpr llvm::StringLiteral kIdentifierCStrMap("CMAP");1200
1201static void EncodeCStrMap(DataEncoder &encoder, ConstStringTable &strtab,1202const UniqueCStringMap<uint32_t> &cstr_map) {1203encoder.AppendData(kIdentifierCStrMap);1204encoder.AppendU32(cstr_map.GetSize());1205for (const auto &entry: cstr_map) {1206// Make sure there are no empty strings.1207assert((bool)entry.cstring);1208encoder.AppendU32(strtab.Add(entry.cstring));1209encoder.AppendU32(entry.value);1210}1211}
1212
1213bool DecodeCStrMap(const DataExtractor &data, lldb::offset_t *offset_ptr,1214const StringTableReader &strtab,1215UniqueCStringMap<uint32_t> &cstr_map) {1216llvm::StringRef identifier((const char *)data.GetData(offset_ptr, 4), 4);1217if (identifier != kIdentifierCStrMap)1218return false;1219const uint32_t count = data.GetU32(offset_ptr);1220cstr_map.Reserve(count);1221for (uint32_t i=0; i<count; ++i)1222{1223llvm::StringRef str(strtab.Get(data.GetU32(offset_ptr)));1224uint32_t value = data.GetU32(offset_ptr);1225// No empty strings in the name indexes in Symtab1226if (str.empty())1227return false;1228cstr_map.Append(ConstString(str), value);1229}1230// We must sort the UniqueCStringMap after decoding it since it is a vector1231// of UniqueCStringMap::Entry objects which contain a ConstString and type T.1232// ConstString objects are sorted by "const char *" and then type T and1233// the "const char *" are point values that will depend on the order in which1234// ConstString objects are created and in which of the 256 string pools they1235// are created in. So after we decode all of the entries, we must sort the1236// name map to ensure name lookups succeed. If we encode and decode within1237// the same process we wouldn't need to sort, so unit testing didn't catch1238// this issue when first checked in.1239cstr_map.Sort();1240return true;1241}
1242
1243constexpr llvm::StringLiteral kIdentifierSymbolTable("SYMB");1244constexpr uint32_t CURRENT_CACHE_VERSION = 1;1245
1246/// The encoding format for the symbol table is as follows:
1247///
1248/// Signature signature;
1249/// ConstStringTable strtab;
1250/// Identifier four character code: 'SYMB'
1251/// uint32_t version;
1252/// uint32_t num_symbols;
1253/// Symbol symbols[num_symbols];
1254/// uint8_t num_cstr_maps;
1255/// UniqueCStringMap<uint32_t> cstr_maps[num_cstr_maps]
1256bool Symtab::Encode(DataEncoder &encoder) const {1257// Name indexes must be computed before calling this function.1258assert(m_name_indexes_computed);1259
1260// Encode the object file's signature1261CacheSignature signature(m_objfile);1262if (!signature.Encode(encoder))1263return false;1264ConstStringTable strtab;1265
1266// Encoder the symbol table into a separate encoder first. This allows us1267// gather all of the strings we willl need in "strtab" as we will need to1268// write the string table out before the symbol table.1269DataEncoder symtab_encoder(encoder.GetByteOrder(),1270encoder.GetAddressByteSize());1271symtab_encoder.AppendData(kIdentifierSymbolTable);1272// Encode the symtab data version.1273symtab_encoder.AppendU32(CURRENT_CACHE_VERSION);1274// Encode the number of symbols.1275symtab_encoder.AppendU32(m_symbols.size());1276// Encode the symbol data for all symbols.1277for (const auto &symbol: m_symbols)1278symbol.Encode(symtab_encoder, strtab);1279
1280// Emit a byte for how many C string maps we emit. We will fix this up after1281// we emit the C string maps since we skip emitting C string maps if they are1282// empty.1283size_t num_cmaps_offset = symtab_encoder.GetByteSize();1284uint8_t num_cmaps = 0;1285symtab_encoder.AppendU8(0);1286for (const auto &pair: m_name_to_symbol_indices) {1287if (pair.second.IsEmpty())1288continue;1289++num_cmaps;1290symtab_encoder.AppendU8(pair.first);1291EncodeCStrMap(symtab_encoder, strtab, pair.second);1292}1293if (num_cmaps > 0)1294symtab_encoder.PutU8(num_cmaps_offset, num_cmaps);1295
1296// Now that all strings have been gathered, we will emit the string table.1297strtab.Encode(encoder);1298// Followed by the symbol table data.1299encoder.AppendData(symtab_encoder.GetData());1300return true;1301}
1302
1303bool Symtab::Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,1304bool &signature_mismatch) {1305signature_mismatch = false;1306CacheSignature signature;1307StringTableReader strtab;1308{ // Scope for "elapsed" object below so it can measure the time parse.1309ElapsedTime elapsed(m_objfile->GetModule()->GetSymtabParseTime());1310if (!signature.Decode(data, offset_ptr))1311return false;1312if (CacheSignature(m_objfile) != signature) {1313signature_mismatch = true;1314return false;1315}1316// We now decode the string table for all strings in the data cache file.1317if (!strtab.Decode(data, offset_ptr))1318return false;1319
1320// And now we can decode the symbol table with string table we just decoded.1321llvm::StringRef identifier((const char *)data.GetData(offset_ptr, 4), 4);1322if (identifier != kIdentifierSymbolTable)1323return false;1324const uint32_t version = data.GetU32(offset_ptr);1325if (version != CURRENT_CACHE_VERSION)1326return false;1327const uint32_t num_symbols = data.GetU32(offset_ptr);1328if (num_symbols == 0)1329return true;1330m_symbols.resize(num_symbols);1331SectionList *sections = m_objfile->GetModule()->GetSectionList();1332for (uint32_t i=0; i<num_symbols; ++i) {1333if (!m_symbols[i].Decode(data, offset_ptr, sections, strtab))1334return false;1335}1336}1337
1338{ // Scope for "elapsed" object below so it can measure the time to index.1339ElapsedTime elapsed(m_objfile->GetModule()->GetSymtabIndexTime());1340const uint8_t num_cstr_maps = data.GetU8(offset_ptr);1341for (uint8_t i=0; i<num_cstr_maps; ++i) {1342uint8_t type = data.GetU8(offset_ptr);1343UniqueCStringMap<uint32_t> &cstr_map =1344GetNameToSymbolIndexMap((lldb::FunctionNameType)type);1345if (!DecodeCStrMap(data, offset_ptr, strtab, cstr_map))1346return false;1347}1348m_name_indexes_computed = true;1349}1350return true;1351}
1352
1353bool Symtab::LoadFromCache() {1354DataFileCache *cache = Module::GetIndexCache();1355if (!cache)1356return false;1357
1358std::unique_ptr<llvm::MemoryBuffer> mem_buffer_up =1359cache->GetCachedData(GetCacheKey());1360if (!mem_buffer_up)1361return false;1362DataExtractor data(mem_buffer_up->getBufferStart(),1363mem_buffer_up->getBufferSize(),1364m_objfile->GetByteOrder(),1365m_objfile->GetAddressByteSize());1366bool signature_mismatch = false;1367lldb::offset_t offset = 0;1368const bool result = Decode(data, &offset, signature_mismatch);1369if (signature_mismatch)1370cache->RemoveCacheFile(GetCacheKey());1371if (result)1372SetWasLoadedFromCache();1373return result;1374}
1375