2010-06-09 00:52:24 +08:00
|
|
|
//===-- Symtab.cpp ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <map>
|
2015-09-02 09:59:14 +08:00
|
|
|
#include <set>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/RegularExpression.h"
|
2013-03-05 05:46:16 +08:00
|
|
|
#include "lldb/Core/Section.h"
|
2015-09-02 09:59:14 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Timer.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2015-02-26 06:41:34 +08:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2013-01-08 08:01:36 +08:00
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Symtab.h"
|
2015-09-02 09:59:14 +08:00
|
|
|
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
|
|
|
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
Symtab::Symtab(ObjectFile *objfile)
|
|
|
|
: m_objfile(objfile),
|
|
|
|
m_symbols(),
|
|
|
|
m_file_addr_to_index(),
|
|
|
|
m_name_to_index(),
|
|
|
|
m_mutex(),
|
|
|
|
m_file_addr_to_index_computed(false),
|
|
|
|
m_name_indexes_computed(false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Symtab::~Symtab()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-26 02:06:21 +08:00
|
|
|
Symtab::Reserve(size_t count)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
// Clients should grab the mutex from this symbol table and lock it manually
|
|
|
|
// when calling this function to avoid performance issues.
|
2010-06-09 00:52:24 +08:00
|
|
|
m_symbols.reserve (count);
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *
|
2013-01-26 02:06:21 +08:00
|
|
|
Symtab::Resize(size_t count)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
// Clients should grab the mutex from this symbol table and lock it manually
|
|
|
|
// when calling this function to avoid performance issues.
|
2010-06-09 00:52:24 +08:00
|
|
|
m_symbols.resize (count);
|
2016-02-10 08:06:50 +08:00
|
|
|
return m_symbols.empty() ? nullptr : &m_symbols[0];
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Symtab::AddSymbol(const Symbol& symbol)
|
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
// Clients should grab the mutex from this symbol table and lock it manually
|
|
|
|
// when calling this function to avoid performance issues.
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t symbol_idx = m_symbols.size();
|
|
|
|
m_name_to_index.Clear();
|
2013-07-10 09:23:25 +08:00
|
|
|
m_file_addr_to_index.Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
m_symbols.push_back(symbol);
|
2013-07-10 09:23:25 +08:00
|
|
|
m_file_addr_to_index_computed = false;
|
2010-10-08 12:20:14 +08:00
|
|
|
m_name_indexes_computed = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
return symbol_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Symtab::GetNumSymbols() const
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_symbols.size();
|
|
|
|
}
|
|
|
|
|
2014-08-22 10:46:46 +08:00
|
|
|
void
|
|
|
|
Symtab::SectionFileAddressesChanged ()
|
|
|
|
{
|
|
|
|
m_name_to_index.Clear();
|
|
|
|
m_file_addr_to_index_computed = false;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
2011-03-25 05:19:54 +08:00
|
|
|
Symtab::Dump (Stream *s, Target *target, SortOrder sort_order)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Indent();
|
|
|
|
const FileSpec &file_spec = m_objfile->GetFileSpec();
|
2014-04-20 21:17:36 +08:00
|
|
|
const char * object_name = nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_objfile->GetModule())
|
|
|
|
object_name = m_objfile->GetModule()->GetObjectName().GetCString();
|
|
|
|
|
|
|
|
if (file_spec)
|
2014-03-04 03:15:20 +08:00
|
|
|
s->Printf("Symtab, file = %s%s%s%s, num_symbols = %" PRIu64,
|
2013-04-30 01:25:54 +08:00
|
|
|
file_spec.GetPath().c_str(),
|
2010-06-09 00:52:24 +08:00
|
|
|
object_name ? "(" : "",
|
|
|
|
object_name ? object_name : "",
|
|
|
|
object_name ? ")" : "",
|
2014-03-04 03:15:20 +08:00
|
|
|
(uint64_t)m_symbols.size());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2014-03-04 03:15:20 +08:00
|
|
|
s->Printf("Symtab, num_symbols = %" PRIu64 "", (uint64_t)m_symbols.size());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (!m_symbols.empty())
|
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
switch (sort_order)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
case eSortOrderNone:
|
|
|
|
{
|
|
|
|
s->PutCString (":\n");
|
|
|
|
DumpSymbolHeader (s);
|
|
|
|
const_iterator begin = m_symbols.begin();
|
|
|
|
const_iterator end = m_symbols.end();
|
|
|
|
for (const_iterator pos = m_symbols.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
s->Indent();
|
|
|
|
pos->Dump(s, target, std::distance(begin, pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSortOrderByName:
|
|
|
|
{
|
|
|
|
// Although we maintain a lookup by exact name map, the table
|
|
|
|
// isn't sorted by name. So we must make the ordered symbol list
|
|
|
|
// up ourselves.
|
|
|
|
s->PutCString (" (sorted by name):\n");
|
|
|
|
DumpSymbolHeader (s);
|
|
|
|
typedef std::multimap<const char*, const Symbol *, CStringCompareFunctionObject> CStringToSymbol;
|
|
|
|
CStringToSymbol name_map;
|
|
|
|
for (const_iterator pos = m_symbols.begin(), end = m_symbols.end(); pos != end; ++pos)
|
|
|
|
{
|
2015-07-09 06:32:23 +08:00
|
|
|
const char *name = pos->GetName().AsCString();
|
2010-10-08 12:20:14 +08:00
|
|
|
if (name && name[0])
|
|
|
|
name_map.insert (std::make_pair(name, &(*pos)));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CStringToSymbol::const_iterator pos = name_map.begin(), end = name_map.end(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
s->Indent();
|
|
|
|
pos->second->Dump (s, target, pos->second - &m_symbols[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSortOrderByAddress:
|
|
|
|
s->PutCString (" (sorted by address):\n");
|
|
|
|
DumpSymbolHeader (s);
|
2013-07-10 09:23:25 +08:00
|
|
|
if (!m_file_addr_to_index_computed)
|
2010-10-08 12:20:14 +08:00
|
|
|
InitAddressIndexes();
|
2013-07-10 09:23:25 +08:00
|
|
|
const size_t num_entries = m_file_addr_to_index.GetSize();
|
|
|
|
for (size_t i=0; i<num_entries; ++i)
|
2010-10-08 12:20:14 +08:00
|
|
|
{
|
2013-07-10 09:23:25 +08:00
|
|
|
s->Indent();
|
|
|
|
const uint32_t symbol_idx = m_file_addr_to_index.GetEntryRef(i).data;
|
|
|
|
m_symbols[symbol_idx].Dump(s, target, symbol_idx);
|
2010-10-08 12:20:14 +08:00
|
|
|
}
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-09-15 07:36:40 +08:00
|
|
|
Symtab::Dump(Stream *s, Target *target, std::vector<uint32_t>& indexes) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const size_t num_symbols = GetNumSymbols();
|
2010-10-08 12:20:14 +08:00
|
|
|
//s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Indent();
|
2014-03-04 03:15:20 +08:00
|
|
|
s->Printf("Symtab %" PRIu64 " symbol indexes (%" PRIu64 " symbols total):\n", (uint64_t)indexes.size(), (uint64_t)m_symbols.size());
|
2010-06-09 00:52:24 +08:00
|
|
|
s->IndentMore();
|
|
|
|
|
|
|
|
if (!indexes.empty())
|
|
|
|
{
|
|
|
|
std::vector<uint32_t>::const_iterator pos;
|
|
|
|
std::vector<uint32_t>::const_iterator end = indexes.end();
|
|
|
|
DumpSymbolHeader (s);
|
|
|
|
for (pos = indexes.begin(); pos != end; ++pos)
|
|
|
|
{
|
2013-01-26 02:06:21 +08:00
|
|
|
size_t idx = *pos;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < num_symbols)
|
|
|
|
{
|
|
|
|
s->Indent();
|
2010-09-15 07:36:40 +08:00
|
|
|
m_symbols[idx].Dump(s, target, idx);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->IndentLess ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Symtab::DumpSymbolHeader (Stream *s)
|
|
|
|
{
|
|
|
|
s->Indent(" Debug symbol\n");
|
|
|
|
s->Indent(" |Synthetic symbol\n");
|
|
|
|
s->Indent(" ||Externally Visible\n");
|
|
|
|
s->Indent(" |||\n");
|
2015-02-26 01:22:05 +08:00
|
|
|
s->Indent("Index UserID DSX Type File Address/Value Load Address Size Flags Name\n");
|
|
|
|
s->Indent("------- ------ --- --------------- ------------------ ------------------ ------------------ ---------- ----------------------------------\n");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-08 01:36:17 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
CompareSymbolID (const void *key, const void *p)
|
|
|
|
{
|
2015-05-13 08:25:54 +08:00
|
|
|
const user_id_t match_uid = *(const user_id_t*) key;
|
|
|
|
const user_id_t symbol_uid = ((const Symbol *)p)->GetID();
|
2010-09-08 01:36:17 +08:00
|
|
|
if (match_uid < symbol_uid)
|
|
|
|
return -1;
|
|
|
|
if (match_uid > symbol_uid)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *
|
|
|
|
Symtab::FindSymbolByID (lldb::user_id_t symbol_uid) const
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-09-08 01:36:17 +08:00
|
|
|
Symbol *symbol = (Symbol*)::bsearch (&symbol_uid,
|
|
|
|
&m_symbols[0],
|
|
|
|
m_symbols.size(),
|
2015-05-13 08:25:54 +08:00
|
|
|
sizeof(m_symbols[0]),
|
2010-09-08 01:36:17 +08:00
|
|
|
CompareSymbolID);
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Symbol *
|
2013-01-26 02:06:21 +08:00
|
|
|
Symtab::SymbolAtIndex(size_t idx)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
// Clients should grab the mutex from this symbol table and lock it manually
|
|
|
|
// when calling this function to avoid performance issues.
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_symbols.size())
|
|
|
|
return &m_symbols[idx];
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Symbol *
|
2013-01-26 02:06:21 +08:00
|
|
|
Symtab::SymbolAtIndex(size_t idx) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
// Clients should grab the mutex from this symbol table and lock it manually
|
|
|
|
// when calling this function to avoid performance issues.
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_symbols.size())
|
|
|
|
return &m_symbols[idx];
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// InitNameIndexes
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
Symtab::InitNameIndexes()
|
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
// Protected function, no need to lock mutex...
|
|
|
|
if (!m_name_indexes_computed)
|
|
|
|
{
|
|
|
|
m_name_indexes_computed = true;
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION);
|
2010-10-08 12:20:14 +08:00
|
|
|
// Create the name index vector to be able to quickly search by name
|
2013-04-03 10:00:15 +08:00
|
|
|
const size_t num_symbols = m_symbols.size();
|
2010-10-08 12:20:14 +08:00
|
|
|
#if 1
|
2013-04-03 10:00:15 +08:00
|
|
|
m_name_to_index.Reserve (num_symbols);
|
2010-10-08 12:20:14 +08:00
|
|
|
#else
|
|
|
|
// TODO: benchmark this to see if we save any memory. Otherwise we
|
|
|
|
// will always keep the memory reserved in the vector unless we pull
|
|
|
|
// some STL swap magic and then recopy...
|
|
|
|
uint32_t actual_count = 0;
|
|
|
|
for (const_iterator pos = m_symbols.begin(), end = m_symbols.end();
|
|
|
|
pos != end;
|
|
|
|
++pos)
|
|
|
|
{
|
|
|
|
const Mangled &mangled = pos->GetMangled();
|
|
|
|
if (mangled.GetMangledName())
|
|
|
|
++actual_count;
|
|
|
|
|
|
|
|
if (mangled.GetDemangledName())
|
|
|
|
++actual_count;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-08 12:20:14 +08:00
|
|
|
m_name_to_index.Reserve (actual_count);
|
|
|
|
#endif
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-12-04 04:02:42 +08:00
|
|
|
NameToIndexMap::Entry entry;
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
// The "const char *" in "class_contexts" must come from a ConstString::GetCString()
|
|
|
|
std::set<const char *> class_contexts;
|
|
|
|
UniqueCStringMap<uint32_t> mangled_name_to_index;
|
2014-04-20 21:17:36 +08:00
|
|
|
std::vector<const char *> symbol_contexts(num_symbols, nullptr);
|
2013-04-03 10:00:15 +08:00
|
|
|
|
|
|
|
for (entry.value = 0; entry.value<num_symbols; ++entry.value)
|
2010-10-08 12:20:14 +08:00
|
|
|
{
|
|
|
|
const Symbol *symbol = &m_symbols[entry.value];
|
|
|
|
|
|
|
|
// Don't let trampolines get into the lookup by name map
|
|
|
|
// If we ever need the trampoline symbols to be searchable by name
|
|
|
|
// we can remove this and then possibly add a new bool to any of the
|
|
|
|
// Symtab functions that lookup symbols by name to indicate if they
|
|
|
|
// want trampolines.
|
|
|
|
if (symbol->IsTrampoline())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const Mangled &mangled = symbol->GetMangled();
|
|
|
|
entry.cstring = mangled.GetMangledName().GetCString();
|
|
|
|
if (entry.cstring && entry.cstring[0])
|
2013-04-03 10:00:15 +08:00
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
m_name_to_index.Append (entry);
|
2015-03-04 18:25:22 +08:00
|
|
|
|
|
|
|
if (symbol->ContainsLinkerAnnotations()) {
|
|
|
|
// If the symbol has linker annotations, also add the version without the
|
|
|
|
// annotations.
|
|
|
|
entry.cstring = ConstString(m_objfile->StripLinkerSymbolAnnotations(entry.cstring)).GetCString();
|
|
|
|
m_name_to_index.Append (entry);
|
|
|
|
}
|
2013-04-03 10:00:15 +08:00
|
|
|
|
|
|
|
const SymbolType symbol_type = symbol->GetType();
|
|
|
|
if (symbol_type == eSymbolTypeCode || symbol_type == eSymbolTypeResolver)
|
|
|
|
{
|
|
|
|
if (entry.cstring[0] == '_' && entry.cstring[1] == 'Z' &&
|
|
|
|
(entry.cstring[2] != 'T' && // avoid virtual table, VTT structure, typeinfo structure, and typeinfo name
|
|
|
|
entry.cstring[2] != 'G' && // avoid guard variables
|
|
|
|
entry.cstring[2] != 'Z')) // named local entities (if we eventually handle eSymbolTypeData, we will want this back)
|
|
|
|
{
|
2015-09-02 09:59:14 +08:00
|
|
|
CPlusPlusLanguage::MethodName cxx_method (mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus));
|
2013-05-18 08:11:21 +08:00
|
|
|
entry.cstring = ConstString(cxx_method.GetBasename()).GetCString();
|
2013-04-03 10:00:15 +08:00
|
|
|
if (entry.cstring && entry.cstring[0])
|
|
|
|
{
|
|
|
|
// ConstString objects permanently store the string in the pool so calling
|
|
|
|
// GetCString() on the value gets us a const char * that will never go away
|
|
|
|
const char *const_context = ConstString(cxx_method.GetContext()).GetCString();
|
|
|
|
|
|
|
|
if (entry.cstring[0] == '~' || !cxx_method.GetQualifiers().empty())
|
|
|
|
{
|
|
|
|
// The first character of the demangled basename is '~' which
|
|
|
|
// means we have a class destructor. We can use this information
|
|
|
|
// to help us know what is a class and what isn't.
|
|
|
|
if (class_contexts.find(const_context) == class_contexts.end())
|
|
|
|
class_contexts.insert(const_context);
|
|
|
|
m_method_to_index.Append (entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (const_context && const_context[0])
|
|
|
|
{
|
|
|
|
if (class_contexts.find(const_context) != class_contexts.end())
|
|
|
|
{
|
|
|
|
// The current decl context is in our "class_contexts" which means
|
|
|
|
// this is a method on a class
|
|
|
|
m_method_to_index.Append (entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We don't know if this is a function basename or a method,
|
|
|
|
// so put it into a temporary collection so once we are done
|
|
|
|
// we can look in class_contexts to see if each entry is a class
|
|
|
|
// or just a function and will put any remaining items into
|
|
|
|
// m_method_to_index or m_basename_to_index as needed
|
|
|
|
mangled_name_to_index.Append (entry);
|
|
|
|
symbol_contexts[entry.value] = const_context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No context for this function so this has to be a basename
|
|
|
|
m_basename_to_index.Append(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
entry.cstring = mangled.GetDemangledName(symbol->GetLanguage()).GetCString();
|
2015-03-04 18:25:22 +08:00
|
|
|
if (entry.cstring && entry.cstring[0]) {
|
2010-10-08 12:20:14 +08:00
|
|
|
m_name_to_index.Append (entry);
|
2015-03-04 18:25:22 +08:00
|
|
|
|
|
|
|
if (symbol->ContainsLinkerAnnotations()) {
|
|
|
|
// If the symbol has linker annotations, also add the version without the
|
|
|
|
// annotations.
|
|
|
|
entry.cstring = ConstString(m_objfile->StripLinkerSymbolAnnotations(entry.cstring)).GetCString();
|
|
|
|
m_name_to_index.Append (entry);
|
|
|
|
}
|
|
|
|
}
|
2011-08-15 09:32:22 +08:00
|
|
|
|
|
|
|
// If the demangled name turns out to be an ObjC name, and
|
|
|
|
// is a category name, add the version without categories to the index too.
|
2015-09-02 09:59:14 +08:00
|
|
|
ObjCLanguage::MethodName objc_method (entry.cstring, true);
|
2013-01-30 08:18:29 +08:00
|
|
|
if (objc_method.IsValid(true))
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2013-01-30 08:18:29 +08:00
|
|
|
entry.cstring = objc_method.GetSelector().GetCString();
|
2013-01-08 08:01:36 +08:00
|
|
|
m_selector_to_index.Append (entry);
|
2013-01-30 08:18:29 +08:00
|
|
|
|
|
|
|
ConstString objc_method_no_category (objc_method.GetFullNameWithoutCategory(true));
|
|
|
|
if (objc_method_no_category)
|
|
|
|
{
|
|
|
|
entry.cstring = objc_method_no_category.GetCString();
|
|
|
|
m_name_to_index.Append (entry);
|
|
|
|
}
|
2011-08-15 09:32:22 +08:00
|
|
|
}
|
|
|
|
|
2010-10-08 12:20:14 +08:00
|
|
|
}
|
2013-04-03 10:00:15 +08:00
|
|
|
|
|
|
|
size_t count;
|
|
|
|
if (!mangled_name_to_index.IsEmpty())
|
|
|
|
{
|
|
|
|
count = mangled_name_to_index.GetSize();
|
|
|
|
for (size_t i=0; i<count; ++i)
|
|
|
|
{
|
|
|
|
if (mangled_name_to_index.GetValueAtIndex(i, entry.value))
|
|
|
|
{
|
|
|
|
entry.cstring = mangled_name_to_index.GetCStringAtIndex(i);
|
|
|
|
if (symbol_contexts[entry.value] && class_contexts.find(symbol_contexts[entry.value]) != class_contexts.end())
|
|
|
|
{
|
|
|
|
m_method_to_index.Append (entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If we got here, we have something that had a context (was inside a namespace or class)
|
|
|
|
// yet we don't know if the entry
|
|
|
|
m_method_to_index.Append (entry);
|
|
|
|
m_basename_to_index.Append (entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-08 12:20:14 +08:00
|
|
|
m_name_to_index.Sort();
|
2011-12-29 06:24:04 +08:00
|
|
|
m_name_to_index.SizeToFit();
|
2013-01-08 08:01:36 +08:00
|
|
|
m_selector_to_index.Sort();
|
|
|
|
m_selector_to_index.SizeToFit();
|
2013-04-03 10:00:15 +08:00
|
|
|
m_basename_to_index.Sort();
|
|
|
|
m_basename_to_index.SizeToFit();
|
|
|
|
m_method_to_index.Sort();
|
|
|
|
m_method_to_index.SizeToFit();
|
|
|
|
|
|
|
|
// static StreamFile a ("/tmp/a.txt");
|
|
|
|
//
|
|
|
|
// count = m_basename_to_index.GetSize();
|
|
|
|
// if (count)
|
|
|
|
// {
|
|
|
|
// for (size_t i=0; i<count; ++i)
|
|
|
|
// {
|
|
|
|
// if (m_basename_to_index.GetValueAtIndex(i, entry.value))
|
|
|
|
// a.Printf ("%s BASENAME\n", m_symbols[entry.value].GetMangled().GetName().GetCString());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// count = m_method_to_index.GetSize();
|
|
|
|
// if (count)
|
|
|
|
// {
|
|
|
|
// for (size_t i=0; i<count; ++i)
|
|
|
|
// {
|
|
|
|
// if (m_method_to_index.GetValueAtIndex(i, entry.value))
|
|
|
|
// a.Printf ("%s METHOD\n", m_symbols[entry.value].GetMangled().GetName().GetCString());
|
|
|
|
// }
|
|
|
|
// }
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-04 04:02:42 +08:00
|
|
|
void
|
2013-04-03 10:00:15 +08:00
|
|
|
Symtab::AppendSymbolNamesToMap (const IndexCollection &indexes,
|
2011-12-04 04:02:42 +08:00
|
|
|
bool add_demangled,
|
|
|
|
bool add_mangled,
|
|
|
|
NameToIndexMap &name_to_index_map) const
|
|
|
|
{
|
|
|
|
if (add_demangled || add_mangled)
|
|
|
|
{
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION);
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2011-12-04 04:02:42 +08:00
|
|
|
|
|
|
|
// Create the name index vector to be able to quickly search by name
|
|
|
|
NameToIndexMap::Entry entry;
|
|
|
|
const size_t num_indexes = indexes.size();
|
|
|
|
for (size_t i=0; i<num_indexes; ++i)
|
|
|
|
{
|
|
|
|
entry.value = indexes[i];
|
|
|
|
assert (i < m_symbols.size());
|
|
|
|
const Symbol *symbol = &m_symbols[entry.value];
|
|
|
|
|
|
|
|
const Mangled &mangled = symbol->GetMangled();
|
|
|
|
if (add_demangled)
|
|
|
|
{
|
2015-07-09 06:32:23 +08:00
|
|
|
entry.cstring = mangled.GetDemangledName(symbol->GetLanguage()).GetCString();
|
2011-12-04 04:02:42 +08:00
|
|
|
if (entry.cstring && entry.cstring[0])
|
|
|
|
name_to_index_map.Append (entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_mangled)
|
|
|
|
{
|
|
|
|
entry.cstring = mangled.GetMangledName().GetCString();
|
|
|
|
if (entry.cstring && entry.cstring[0])
|
|
|
|
name_to_index_map.Append (entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t
|
2010-09-11 11:13:28 +08:00
|
|
|
Symtab::AppendSymbolIndexesWithType (SymbolType symbol_type, std::vector<uint32_t>& indexes, uint32_t start_idx, uint32_t end_index) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t prev_size = indexes.size();
|
|
|
|
|
|
|
|
const uint32_t count = std::min<uint32_t> (m_symbols.size(), end_index);
|
|
|
|
|
|
|
|
for (uint32_t i = start_idx; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type)
|
|
|
|
indexes.push_back(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return indexes.size() - prev_size;
|
|
|
|
}
|
|
|
|
|
2011-01-20 14:08:59 +08:00
|
|
|
uint32_t
|
|
|
|
Symtab::AppendSymbolIndexesWithTypeAndFlagsValue (SymbolType symbol_type, uint32_t flags_value, std::vector<uint32_t>& indexes, uint32_t start_idx, uint32_t end_index) const
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2011-01-20 14:08:59 +08:00
|
|
|
|
|
|
|
uint32_t prev_size = indexes.size();
|
|
|
|
|
|
|
|
const uint32_t count = std::min<uint32_t> (m_symbols.size(), end_index);
|
|
|
|
|
|
|
|
for (uint32_t i = start_idx; i < count; ++i)
|
|
|
|
{
|
|
|
|
if ((symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type) && m_symbols[i].GetFlags() == flags_value)
|
|
|
|
indexes.push_back(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return indexes.size() - prev_size;
|
|
|
|
}
|
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
uint32_t
|
|
|
|
Symtab::AppendSymbolIndexesWithType (SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes, uint32_t start_idx, uint32_t end_index) const
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
uint32_t prev_size = indexes.size();
|
|
|
|
|
|
|
|
const uint32_t count = std::min<uint32_t> (m_symbols.size(), end_index);
|
|
|
|
|
|
|
|
for (uint32_t i = start_idx; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type)
|
|
|
|
{
|
|
|
|
if (CheckSymbolAtIndex(i, symbol_debug_type, symbol_visibility))
|
|
|
|
indexes.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return indexes.size() - prev_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Symtab::GetIndexForSymbol (const Symbol *symbol) const
|
|
|
|
{
|
2015-02-26 06:41:34 +08:00
|
|
|
if (!m_symbols.empty())
|
|
|
|
{
|
|
|
|
const Symbol *first_symbol = &m_symbols[0];
|
|
|
|
if (symbol >= first_symbol && symbol < first_symbol + m_symbols.size())
|
|
|
|
return symbol - first_symbol;
|
|
|
|
}
|
2010-09-11 11:13:28 +08:00
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
struct SymbolSortInfo
|
|
|
|
{
|
|
|
|
const bool sort_by_load_addr;
|
|
|
|
const Symbol *symbols;
|
|
|
|
};
|
|
|
|
|
2010-06-17 01:34:05 +08:00
|
|
|
namespace {
|
|
|
|
struct SymbolIndexComparator {
|
|
|
|
const std::vector<Symbol>& symbols;
|
2012-05-01 09:34:15 +08:00
|
|
|
std::vector<lldb::addr_t> &addr_cache;
|
|
|
|
|
|
|
|
// Getting from the symbol to the Address to the File Address involves some work.
|
|
|
|
// Since there are potentially many symbols here, and we're using this for sorting so
|
|
|
|
// we're going to be computing the address many times, cache that in addr_cache.
|
|
|
|
// The array passed in has to be the same size as the symbols array passed into the
|
|
|
|
// member variable symbols, and should be initialized with LLDB_INVALID_ADDRESS.
|
|
|
|
// NOTE: You have to make addr_cache externally and pass it in because std::stable_sort
|
|
|
|
// makes copies of the comparator it is initially passed in, and you end up spending
|
|
|
|
// huge amounts of time copying this array...
|
|
|
|
|
|
|
|
SymbolIndexComparator(const std::vector<Symbol>& s, std::vector<lldb::addr_t> &a) : symbols(s), addr_cache(a) {
|
|
|
|
assert (symbols.size() == addr_cache.size());
|
|
|
|
}
|
2010-06-17 01:34:05 +08:00
|
|
|
bool operator()(uint32_t index_a, uint32_t index_b) {
|
2012-05-01 09:34:15 +08:00
|
|
|
addr_t value_a = addr_cache[index_a];
|
|
|
|
if (value_a == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
value_a = symbols[index_a].GetAddressRef().GetFileAddress();
|
2012-05-01 09:34:15 +08:00
|
|
|
addr_cache[index_a] = value_a;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr_t value_b = addr_cache[index_b];
|
|
|
|
if (value_b == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
value_b = symbols[index_b].GetAddressRef().GetFileAddress();
|
2012-05-01 09:34:15 +08:00
|
|
|
addr_cache[index_b] = value_b;
|
|
|
|
}
|
|
|
|
|
2010-06-12 05:07:26 +08:00
|
|
|
|
2010-06-17 01:34:05 +08:00
|
|
|
if (value_a == value_b) {
|
|
|
|
// The if the values are equal, use the original symbol user ID
|
|
|
|
lldb::user_id_t uid_a = symbols[index_a].GetID();
|
|
|
|
lldb::user_id_t uid_b = symbols[index_b].GetID();
|
|
|
|
if (uid_a < uid_b)
|
|
|
|
return true;
|
|
|
|
if (uid_a > uid_b)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} else if (value_a < value_b)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2010-06-11 07:36:31 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
Symtab::SortSymbolIndexesByValue (std::vector<uint32_t>& indexes, bool remove_duplicates) const
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION,LLVM_PRETTY_FUNCTION);
|
2010-06-09 00:52:24 +08:00
|
|
|
// No need to sort if we have zero or one items...
|
|
|
|
if (indexes.size() <= 1)
|
|
|
|
return;
|
|
|
|
|
2010-06-17 08:51:12 +08:00
|
|
|
// Sort the indexes in place using std::stable_sort.
|
|
|
|
// NOTE: The use of std::stable_sort instead of std::sort here is strictly for performance,
|
|
|
|
// not correctness. The indexes vector tends to be "close" to sorted, which the
|
|
|
|
// stable sort handles better.
|
2012-05-01 09:34:15 +08:00
|
|
|
|
|
|
|
std::vector<lldb::addr_t> addr_cache(m_symbols.size(), LLDB_INVALID_ADDRESS);
|
|
|
|
|
|
|
|
SymbolIndexComparator comparator(m_symbols, addr_cache);
|
|
|
|
std::stable_sort(indexes.begin(), indexes.end(), comparator);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Remove any duplicates if requested
|
|
|
|
if (remove_duplicates)
|
|
|
|
std::unique(indexes.begin(), indexes.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2010-09-11 11:13:28 +08:00
|
|
|
Symtab::AppendSymbolIndexesWithName (const ConstString& symbol_name, std::vector<uint32_t>& indexes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (symbol_name)
|
|
|
|
{
|
2011-09-11 08:20:09 +08:00
|
|
|
const char *symbol_cstr = symbol_name.GetCString();
|
2010-10-08 12:20:14 +08:00
|
|
|
if (!m_name_indexes_computed)
|
2010-06-09 00:52:24 +08:00
|
|
|
InitNameIndexes();
|
|
|
|
|
2011-09-11 08:20:09 +08:00
|
|
|
return m_name_to_index.GetValues (symbol_cstr, indexes);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2010-09-11 11:13:28 +08:00
|
|
|
Symtab::AppendSymbolIndexesWithName (const ConstString& symbol_name, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION);
|
2010-09-11 11:13:28 +08:00
|
|
|
if (symbol_name)
|
|
|
|
{
|
|
|
|
const size_t old_size = indexes.size();
|
2010-10-08 12:20:14 +08:00
|
|
|
if (!m_name_indexes_computed)
|
2010-09-11 11:13:28 +08:00
|
|
|
InitNameIndexes();
|
|
|
|
|
|
|
|
const char *symbol_cstr = symbol_name.GetCString();
|
2011-09-11 08:20:09 +08:00
|
|
|
|
|
|
|
std::vector<uint32_t> all_name_indexes;
|
|
|
|
const size_t name_match_count = m_name_to_index.GetValues (symbol_cstr, all_name_indexes);
|
|
|
|
for (size_t i=0; i<name_match_count; ++i)
|
2010-09-11 11:13:28 +08:00
|
|
|
{
|
2011-09-11 08:20:09 +08:00
|
|
|
if (CheckSymbolAtIndex(all_name_indexes[i], symbol_debug_type, symbol_visibility))
|
|
|
|
indexes.push_back (all_name_indexes[i]);
|
2010-09-11 11:13:28 +08:00
|
|
|
}
|
|
|
|
return indexes.size() - old_size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Symtab::AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, SymbolType symbol_type, std::vector<uint32_t>& indexes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (AppendSymbolIndexesWithName(symbol_name, indexes) > 0)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t>::iterator pos = indexes.begin();
|
|
|
|
while (pos != indexes.end())
|
|
|
|
{
|
|
|
|
if (symbol_type == eSymbolTypeAny || m_symbols[*pos].GetType() == symbol_type)
|
|
|
|
++pos;
|
|
|
|
else
|
2013-09-28 04:58:17 +08:00
|
|
|
pos = indexes.erase(pos);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return indexes.size();
|
|
|
|
}
|
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
uint32_t
|
|
|
|
Symtab::AppendSymbolIndexesWithNameAndType (const ConstString& symbol_name, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
if (AppendSymbolIndexesWithName(symbol_name, symbol_debug_type, symbol_visibility, indexes) > 0)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t>::iterator pos = indexes.begin();
|
|
|
|
while (pos != indexes.end())
|
|
|
|
{
|
|
|
|
if (symbol_type == eSymbolTypeAny || m_symbols[*pos].GetType() == symbol_type)
|
|
|
|
++pos;
|
|
|
|
else
|
2013-09-28 04:58:17 +08:00
|
|
|
pos = indexes.erase(pos);
|
2010-09-11 11:13:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return indexes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t
|
|
|
|
Symtab::AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®exp, SymbolType symbol_type, std::vector<uint32_t>& indexes)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t prev_size = indexes.size();
|
|
|
|
uint32_t sym_end = m_symbols.size();
|
|
|
|
|
2013-06-20 03:04:53 +08:00
|
|
|
for (uint32_t i = 0; i < sym_end; i++)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type)
|
|
|
|
{
|
2015-07-09 06:32:23 +08:00
|
|
|
const char *name = m_symbols[i].GetName().AsCString();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (regexp.Execute (name))
|
|
|
|
indexes.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return indexes.size() - prev_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
uint32_t
|
|
|
|
Symtab::AppendSymbolIndexesMatchingRegExAndType (const RegularExpression ®exp, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
uint32_t prev_size = indexes.size();
|
|
|
|
uint32_t sym_end = m_symbols.size();
|
|
|
|
|
2013-06-20 03:04:53 +08:00
|
|
|
for (uint32_t i = 0; i < sym_end; i++)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-11 11:13:28 +08:00
|
|
|
if (symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-11 11:13:28 +08:00
|
|
|
if (CheckSymbolAtIndex(i, symbol_debug_type, symbol_visibility) == false)
|
|
|
|
continue;
|
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
const char *name = m_symbols[i].GetName().AsCString();
|
2010-09-11 11:13:28 +08:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (regexp.Execute (name))
|
|
|
|
indexes.push_back(i);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-11 11:13:28 +08:00
|
|
|
return indexes.size() - prev_size;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
Symbol *
|
|
|
|
Symtab::FindSymbolWithType (SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t& start_idx)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const size_t count = m_symbols.size();
|
2013-01-26 02:06:21 +08:00
|
|
|
for (size_t idx = start_idx; idx < count; ++idx)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (symbol_type == eSymbolTypeAny || m_symbols[idx].GetType() == symbol_type)
|
|
|
|
{
|
2010-09-11 11:13:28 +08:00
|
|
|
if (CheckSymbolAtIndex(idx, symbol_debug_type, symbol_visibility))
|
|
|
|
{
|
|
|
|
start_idx = idx;
|
|
|
|
return &m_symbols[idx];
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Symtab::FindAllSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, std::vector<uint32_t>& symbol_indexes)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION);
|
2010-06-09 00:52:24 +08:00
|
|
|
// Initialize all of the lookup by name indexes before converting NAME
|
|
|
|
// to a uniqued string NAME_STR below.
|
2010-10-08 12:20:14 +08:00
|
|
|
if (!m_name_indexes_computed)
|
2010-06-09 00:52:24 +08:00
|
|
|
InitNameIndexes();
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
// The string table did have a string that matched, but we need
|
|
|
|
// to check the symbols and match the symbol_type if any was given.
|
2010-09-11 11:13:28 +08:00
|
|
|
AppendSymbolIndexesWithNameAndType (name, symbol_type, symbol_indexes);
|
|
|
|
}
|
|
|
|
return symbol_indexes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Symtab::FindAllSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION);
|
2010-09-11 11:13:28 +08:00
|
|
|
// Initialize all of the lookup by name indexes before converting NAME
|
|
|
|
// to a uniqued string NAME_STR below.
|
2010-10-08 12:20:14 +08:00
|
|
|
if (!m_name_indexes_computed)
|
2010-09-11 11:13:28 +08:00
|
|
|
InitNameIndexes();
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
// The string table did have a string that matched, but we need
|
|
|
|
// to check the symbols and match the symbol_type if any was given.
|
|
|
|
AppendSymbolIndexesWithNameAndType (name, symbol_type, symbol_debug_type, symbol_visibility, symbol_indexes);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return symbol_indexes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2010-09-11 11:13:28 +08:00
|
|
|
Symtab::FindAllSymbolsMatchingRexExAndType (const RegularExpression ®ex, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2010-09-11 11:13:28 +08:00
|
|
|
AppendSymbolIndexesMatchingRegExAndType(regex, symbol_type, symbol_debug_type, symbol_visibility, symbol_indexes);
|
2010-06-09 00:52:24 +08:00
|
|
|
return symbol_indexes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *
|
2010-09-11 11:13:28 +08:00
|
|
|
Symtab::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-08-10 07:06:08 +08:00
|
|
|
Timer scoped_timer (LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION);
|
2010-10-08 12:20:14 +08:00
|
|
|
if (!m_name_indexes_computed)
|
2010-06-09 00:52:24 +08:00
|
|
|
InitNameIndexes();
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> matching_indexes;
|
|
|
|
// The string table did have a string that matched, but we need
|
|
|
|
// to check the symbols and match the symbol_type if any was given.
|
2010-09-11 11:13:28 +08:00
|
|
|
if (AppendSymbolIndexesWithNameAndType (name, symbol_type, symbol_debug_type, symbol_visibility, matching_indexes))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
std::vector<uint32_t>::const_iterator pos, end = matching_indexes.end();
|
|
|
|
for (pos = matching_indexes.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
Symbol *symbol = SymbolAtIndex(*pos);
|
|
|
|
|
|
|
|
if (symbol->Compare(name, symbol_type))
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const Symtab *symtab;
|
|
|
|
const addr_t file_addr;
|
|
|
|
Symbol *match_symbol;
|
|
|
|
const uint32_t *match_index_ptr;
|
|
|
|
addr_t match_offset;
|
|
|
|
} SymbolSearchInfo;
|
|
|
|
|
2016-04-13 12:32:49 +08:00
|
|
|
// Add all the section file start address & size to the RangeVector,
|
|
|
|
// recusively adding any children sections.
|
|
|
|
static void
|
|
|
|
AddSectionsToRangeMap (SectionList *sectlist, RangeVector<addr_t, addr_t> §ion_ranges)
|
|
|
|
{
|
|
|
|
const int num_sections = sectlist->GetNumSections (0);
|
|
|
|
for (int i = 0; i < num_sections; i++)
|
|
|
|
{
|
|
|
|
SectionSP sect_sp = sectlist->GetSectionAtIndex (i);
|
|
|
|
if (sect_sp)
|
|
|
|
{
|
|
|
|
SectionList &child_sectlist = sect_sp->GetChildren();
|
|
|
|
|
|
|
|
// If this section has children, add the children to the RangeVector.
|
|
|
|
// Else add this section to the RangeVector.
|
|
|
|
if (child_sectlist.GetNumSections (0) > 0)
|
|
|
|
{
|
|
|
|
AddSectionsToRangeMap (&child_sectlist, section_ranges);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t size = sect_sp->GetByteSize();
|
2016-04-23 06:35:08 +08:00
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
addr_t base_addr = sect_sp->GetFileAddress();
|
|
|
|
RangeVector<addr_t, addr_t>::Entry entry;
|
|
|
|
entry.SetRangeBase (base_addr);
|
|
|
|
entry.SetByteSize (size);
|
|
|
|
section_ranges.Append (entry);
|
|
|
|
}
|
2016-04-13 12:32:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
Symtab::InitAddressIndexes()
|
|
|
|
{
|
2010-10-08 12:20:14 +08:00
|
|
|
// Protected function, no need to lock mutex...
|
2013-07-10 09:23:25 +08:00
|
|
|
if (!m_file_addr_to_index_computed && !m_symbols.empty())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-07-10 09:23:25 +08:00
|
|
|
m_file_addr_to_index_computed = true;
|
2013-04-14 07:17:23 +08:00
|
|
|
|
2013-07-10 09:23:25 +08:00
|
|
|
FileRangeToIndexMap::Entry entry;
|
2010-10-08 12:20:14 +08:00
|
|
|
const_iterator begin = m_symbols.begin();
|
|
|
|
const_iterator end = m_symbols.end();
|
|
|
|
for (const_iterator pos = m_symbols.begin(); pos != end; ++pos)
|
|
|
|
{
|
2012-03-08 05:03:09 +08:00
|
|
|
if (pos->ValueIsAddress())
|
2013-07-10 09:23:25 +08:00
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
entry.SetRangeBase(pos->GetAddressRef().GetFileAddress());
|
2013-07-10 09:23:25 +08:00
|
|
|
entry.SetByteSize(pos->GetByteSize());
|
|
|
|
entry.data = std::distance(begin, pos);
|
|
|
|
m_file_addr_to_index.Append(entry);
|
|
|
|
}
|
2010-10-08 12:20:14 +08:00
|
|
|
}
|
2013-07-10 09:23:25 +08:00
|
|
|
const size_t num_entries = m_file_addr_to_index.GetSize();
|
|
|
|
if (num_entries > 0)
|
|
|
|
{
|
|
|
|
m_file_addr_to_index.Sort();
|
2016-02-18 19:12:18 +08:00
|
|
|
|
2016-04-13 12:32:49 +08:00
|
|
|
// Create a RangeVector with the start & size of all the sections for
|
|
|
|
// this objfile. We'll need to check this for any FileRangeToIndexMap
|
|
|
|
// entries with an uninitialized size, which could potentially be a
|
|
|
|
// large number so reconstituting the weak pointer is busywork when it
|
|
|
|
// is invariant information.
|
|
|
|
SectionList *sectlist = m_objfile->GetSectionList();
|
|
|
|
RangeVector<addr_t, addr_t> section_ranges;
|
|
|
|
if (sectlist)
|
2013-07-10 09:23:25 +08:00
|
|
|
{
|
2016-04-13 12:32:49 +08:00
|
|
|
AddSectionsToRangeMap (sectlist, section_ranges);
|
|
|
|
section_ranges.Sort();
|
2013-07-10 09:23:25 +08:00
|
|
|
}
|
2016-02-18 19:12:18 +08:00
|
|
|
|
2016-04-13 12:32:49 +08:00
|
|
|
// Iterate through the FileRangeToIndexMap and fill in the size for any
|
|
|
|
// entries that didn't already have a size from the Symbol (e.g. if we
|
|
|
|
// have a plain linker symbol with an address only, instead of debug info
|
|
|
|
// where we get an address and a size and a type, etc.)
|
2016-04-13 21:32:06 +08:00
|
|
|
for (size_t i = 0; i < num_entries; i++)
|
2016-04-13 12:32:49 +08:00
|
|
|
{
|
|
|
|
FileRangeToIndexMap::Entry *entry = m_file_addr_to_index.GetMutableEntryAtIndex (i);
|
|
|
|
if (entry->GetByteSize() == 0)
|
|
|
|
{
|
|
|
|
addr_t curr_base_addr = entry->GetRangeBase();
|
|
|
|
const RangeVector<addr_t, addr_t>::Entry *containing_section =
|
|
|
|
section_ranges.FindEntryThatContains (curr_base_addr);
|
|
|
|
|
|
|
|
// Use the end of the section as the default max size of the symbol
|
|
|
|
addr_t sym_size = 0;
|
|
|
|
if (containing_section)
|
|
|
|
{
|
|
|
|
sym_size = containing_section->GetByteSize() -
|
|
|
|
(entry->GetRangeBase() - containing_section->GetRangeBase());
|
|
|
|
}
|
|
|
|
|
2016-04-13 21:32:06 +08:00
|
|
|
for (size_t j = i; j < num_entries; j++)
|
2016-04-13 12:32:49 +08:00
|
|
|
{
|
|
|
|
FileRangeToIndexMap::Entry *next_entry = m_file_addr_to_index.GetMutableEntryAtIndex (j);
|
|
|
|
addr_t next_base_addr = next_entry->GetRangeBase();
|
|
|
|
if (next_base_addr > curr_base_addr)
|
|
|
|
{
|
|
|
|
addr_t size_to_next_symbol = next_base_addr - curr_base_addr;
|
|
|
|
|
|
|
|
// Take the difference between this symbol and the next one as its size,
|
|
|
|
// if it is less than the size of the section.
|
|
|
|
if (sym_size == 0 || size_to_next_symbol < sym_size)
|
|
|
|
{
|
|
|
|
sym_size = size_to_next_symbol;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sym_size > 0)
|
|
|
|
{
|
|
|
|
entry->SetByteSize (sym_size);
|
|
|
|
Symbol &symbol = m_symbols[entry->data];
|
|
|
|
symbol.SetByteSize (sym_size);
|
|
|
|
symbol.SetSizeIsSynthesized (true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort again in case the range size changes the ordering
|
|
|
|
m_file_addr_to_index.Sort();
|
2013-07-10 09:23:25 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:23:25 +08:00
|
|
|
void
|
|
|
|
Symtab::CalculateSymbolSizes ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2013-07-10 09:23:25 +08:00
|
|
|
if (!m_symbols.empty())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-07-10 09:23:25 +08:00
|
|
|
if (!m_file_addr_to_index_computed)
|
2010-06-09 00:52:24 +08:00
|
|
|
InitAddressIndexes();
|
2013-07-10 09:23:25 +08:00
|
|
|
|
|
|
|
const size_t num_entries = m_file_addr_to_index.GetSize();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_entries; ++i)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-07-10 09:23:25 +08:00
|
|
|
// The entries in the m_file_addr_to_index have calculated the sizes already
|
|
|
|
// so we will use this size if we need to.
|
|
|
|
const FileRangeToIndexMap::Entry &entry = m_file_addr_to_index.GetEntryRef(i);
|
|
|
|
|
|
|
|
Symbol &symbol = m_symbols[entry.data];
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-07-10 09:23:25 +08:00
|
|
|
// If the symbol size is already valid, no need to do anything
|
|
|
|
if (symbol.GetByteSizeIsValid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const addr_t range_size = entry.GetByteSize();
|
|
|
|
if (range_size > 0)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-07-10 09:23:25 +08:00
|
|
|
symbol.SetByteSize(range_size);
|
|
|
|
symbol.SetSizeIsSynthesized(true);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *
|
2016-02-18 19:12:18 +08:00
|
|
|
Symtab::FindSymbolAtFileAddress (addr_t file_addr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-02-18 19:12:18 +08:00
|
|
|
if (!m_file_addr_to_index_computed)
|
|
|
|
InitAddressIndexes();
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2016-02-18 19:12:18 +08:00
|
|
|
const FileRangeToIndexMap::Entry *entry = m_file_addr_to_index.FindEntryStartsAt(file_addr);
|
|
|
|
if (entry)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2016-02-18 19:12:18 +08:00
|
|
|
Symbol* symbol = SymbolAtIndex(entry->data);
|
|
|
|
if (symbol->GetFileAddress() == file_addr)
|
|
|
|
return symbol;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *
|
|
|
|
Symtab::FindSymbolContainingFileAddress (addr_t file_addr)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 12:20:14 +08:00
|
|
|
|
2013-07-10 09:23:25 +08:00
|
|
|
if (!m_file_addr_to_index_computed)
|
2010-06-09 00:52:24 +08:00
|
|
|
InitAddressIndexes();
|
|
|
|
|
2013-07-10 09:23:25 +08:00
|
|
|
const FileRangeToIndexMap::Entry *entry = m_file_addr_to_index.FindEntryThatContains(file_addr);
|
|
|
|
if (entry)
|
2016-01-19 18:24:51 +08:00
|
|
|
{
|
|
|
|
Symbol* symbol = SymbolAtIndex(entry->data);
|
|
|
|
if (symbol->ContainsFileAddress(file_addr))
|
|
|
|
return symbol;
|
|
|
|
}
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-01-23 18:36:06 +08:00
|
|
|
void
|
2016-01-26 08:58:09 +08:00
|
|
|
Symtab::ForEachSymbolContainingFileAddress(addr_t file_addr, std::function<bool(Symbol *)> const &callback)
|
2016-01-23 18:36:06 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-01-23 18:36:06 +08:00
|
|
|
|
|
|
|
if (!m_file_addr_to_index_computed)
|
|
|
|
InitAddressIndexes();
|
|
|
|
|
|
|
|
std::vector<uint32_t> all_addr_indexes;
|
|
|
|
|
|
|
|
// Get all symbols with file_addr
|
2016-01-26 08:58:09 +08:00
|
|
|
const size_t addr_match_count = m_file_addr_to_index.FindEntryIndexesThatContain(file_addr, all_addr_indexes);
|
2016-01-23 18:36:06 +08:00
|
|
|
|
2016-01-26 08:58:09 +08:00
|
|
|
for (size_t i = 0; i < addr_match_count; ++i)
|
2016-01-23 18:36:06 +08:00
|
|
|
{
|
2016-02-18 19:12:18 +08:00
|
|
|
Symbol* symbol = SymbolAtIndex(all_addr_indexes[i]);
|
|
|
|
if (symbol->ContainsFileAddress(file_addr))
|
|
|
|
{
|
|
|
|
if (!callback(symbol))
|
|
|
|
break;
|
|
|
|
}
|
2016-01-23 18:36:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:01:36 +08:00
|
|
|
void
|
|
|
|
Symtab::SymbolIndicesToSymbolContextList (std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
|
|
|
|
{
|
|
|
|
// No need to protect this call using m_mutex all other method calls are
|
|
|
|
// already thread safe.
|
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
const bool merge_symbol_into_function = true;
|
2013-01-08 08:01:36 +08:00
|
|
|
size_t num_indices = symbol_indexes.size();
|
|
|
|
if (num_indices > 0)
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
sc.module_sp = m_objfile->GetModule();
|
|
|
|
for (size_t i = 0; i < num_indices; i++)
|
|
|
|
{
|
|
|
|
sc.symbol = SymbolAtIndex (symbol_indexes[i]);
|
|
|
|
if (sc.symbol)
|
2013-04-03 10:00:15 +08:00
|
|
|
sc_list.AppendIfUnique(sc, merge_symbol_into_function);
|
2013-01-08 08:01:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Symtab::FindFunctionSymbols (const ConstString &name,
|
|
|
|
uint32_t name_type_mask,
|
|
|
|
SymbolContextList& sc_list)
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
std::vector<uint32_t> symbol_indexes;
|
2013-04-03 10:00:15 +08:00
|
|
|
|
|
|
|
const char *name_cstr = name.GetCString();
|
|
|
|
|
|
|
|
// eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
|
|
|
|
assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
|
|
|
|
|
|
|
|
if (name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull))
|
2013-01-08 08:01:36 +08:00
|
|
|
{
|
2013-04-23 01:02:04 +08:00
|
|
|
std::vector<uint32_t> temp_symbol_indexes;
|
|
|
|
FindAllSymbolsWithNameAndType (name, eSymbolTypeAny, temp_symbol_indexes);
|
|
|
|
|
|
|
|
unsigned temp_symbol_indexes_size = temp_symbol_indexes.size();
|
|
|
|
if (temp_symbol_indexes_size > 0)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2013-04-23 01:02:04 +08:00
|
|
|
for (unsigned i = 0; i < temp_symbol_indexes_size; i++)
|
|
|
|
{
|
|
|
|
SymbolContext sym_ctx;
|
|
|
|
sym_ctx.symbol = SymbolAtIndex (temp_symbol_indexes[i]);
|
|
|
|
if (sym_ctx.symbol)
|
|
|
|
{
|
|
|
|
switch (sym_ctx.symbol->GetType())
|
|
|
|
{
|
|
|
|
case eSymbolTypeCode:
|
|
|
|
case eSymbolTypeResolver:
|
2013-10-22 02:40:51 +08:00
|
|
|
case eSymbolTypeReExported:
|
2013-04-23 01:02:04 +08:00
|
|
|
symbol_indexes.push_back(temp_symbol_indexes[i]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-08 08:01:36 +08:00
|
|
|
}
|
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
if (name_type_mask & eFunctionNameTypeBase)
|
|
|
|
{
|
|
|
|
// From mangled names we can't tell what is a basename and what
|
|
|
|
// is a method name, so we just treat them the same
|
|
|
|
if (!m_name_indexes_computed)
|
|
|
|
InitNameIndexes();
|
|
|
|
|
|
|
|
if (!m_basename_to_index.IsEmpty())
|
|
|
|
{
|
|
|
|
const UniqueCStringMap<uint32_t>::Entry *match;
|
|
|
|
for (match = m_basename_to_index.FindFirstValueForName(name_cstr);
|
2014-04-20 21:17:36 +08:00
|
|
|
match != nullptr;
|
2013-04-03 10:00:15 +08:00
|
|
|
match = m_basename_to_index.FindNextValueForName(match))
|
|
|
|
{
|
|
|
|
symbol_indexes.push_back(match->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name_type_mask & eFunctionNameTypeMethod)
|
|
|
|
{
|
|
|
|
if (!m_name_indexes_computed)
|
|
|
|
InitNameIndexes();
|
|
|
|
|
|
|
|
if (!m_method_to_index.IsEmpty())
|
|
|
|
{
|
|
|
|
const UniqueCStringMap<uint32_t>::Entry *match;
|
|
|
|
for (match = m_method_to_index.FindFirstValueForName(name_cstr);
|
2014-04-20 21:17:36 +08:00
|
|
|
match != nullptr;
|
2013-04-03 10:00:15 +08:00
|
|
|
match = m_method_to_index.FindNextValueForName(match))
|
|
|
|
{
|
|
|
|
symbol_indexes.push_back(match->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:01:36 +08:00
|
|
|
if (name_type_mask & eFunctionNameTypeSelector)
|
|
|
|
{
|
|
|
|
if (!m_name_indexes_computed)
|
|
|
|
InitNameIndexes();
|
|
|
|
|
|
|
|
if (!m_selector_to_index.IsEmpty())
|
|
|
|
{
|
|
|
|
const UniqueCStringMap<uint32_t>::Entry *match;
|
2013-04-03 10:00:15 +08:00
|
|
|
for (match = m_selector_to_index.FindFirstValueForName(name_cstr);
|
2014-04-20 21:17:36 +08:00
|
|
|
match != nullptr;
|
2013-01-08 08:01:36 +08:00
|
|
|
match = m_selector_to_index.FindNextValueForName(match))
|
|
|
|
{
|
|
|
|
symbol_indexes.push_back(match->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!symbol_indexes.empty())
|
|
|
|
{
|
|
|
|
std::sort(symbol_indexes.begin(), symbol_indexes.end());
|
|
|
|
symbol_indexes.erase(std::unique(symbol_indexes.begin(), symbol_indexes.end()), symbol_indexes.end());
|
|
|
|
count = symbol_indexes.size();
|
|
|
|
SymbolIndicesToSymbolContextList (symbol_indexes, sc_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2015-02-26 06:41:34 +08:00
|
|
|
|
|
|
|
const Symbol *
|
|
|
|
Symtab::GetParent (Symbol *child_symbol) const
|
|
|
|
{
|
|
|
|
uint32_t child_idx = GetIndexForSymbol(child_symbol);
|
|
|
|
if (child_idx != UINT32_MAX && child_idx > 0)
|
|
|
|
{
|
|
|
|
for (uint32_t idx = child_idx - 1; idx != UINT32_MAX; --idx)
|
|
|
|
{
|
|
|
|
const Symbol *symbol = SymbolAtIndex (idx);
|
|
|
|
const uint32_t sibling_idx = symbol->GetSiblingIndex();
|
|
|
|
if (sibling_idx != UINT32_MAX && sibling_idx > child_idx)
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|