Summary: some unwind formats are specific to a single symbol file and so it does not make sense for their parsing code live in the general Symbol library (as is the case with eh_frame for instance). This is the case for the unwind information in breakpad files, but the same will probably be true for PDB unwind info (once we are able to parse that). This patch adds the ability to fetch an unwind plan provided by a symbol file plugin, as discussed in the RFC at <http://lists.llvm.org/pipermail/lldb-dev/2019-February/014703.html>. I've kept the set of changes to a minimum, as there is no way to test them until we have a symbol file which implements this API -- that is comming in a follow-up patch, which will also implicitly test this change. The interesting part here is the introduction of the "RegisterInfoResolver" interface. The reason for this is that breakpad needs to be able to resolve register names (which are present as strings in the file) into register enums so that it can construct the unwind plan. This is normally done via the RegisterContext class, handing this over to the SymbolFile plugin would mean that it has full access to the debugged process, which is not something we want it to have. So instead, I create a facade, which only provides the ability to query register names, and hide the RegisterContext behind the facade. Also note that this only adds the ability to dump the unwind plan created by the symbol file plugin -- the plan is not used for unwinding yet -- this will be added in a third patch, which will add additional tests which makes sure the unwinding works as a whole. Reviewers: jasonmolenda, clayborg Subscribers: markmentovai, amccarth, lldb-commits Differential Revision: https://reviews.llvm.org/D61732 llvm-svn: 360409
173 lines
5.8 KiB
C++
173 lines
5.8 KiB
C++
//===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Symbol/SymbolFile.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
#include "lldb/Core/PluginManager.h"
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
#include "lldb/Symbol/TypeMap.h"
|
|
#include "lldb/Symbol/TypeSystem.h"
|
|
#include "lldb/Symbol/VariableList.h"
|
|
#include "lldb/Utility/Log.h"
|
|
#include "lldb/Utility/StreamString.h"
|
|
#include "lldb/lldb-private.h"
|
|
|
|
#include <future>
|
|
|
|
using namespace lldb_private;
|
|
|
|
void SymbolFile::PreloadSymbols() {
|
|
// No-op for most implementations.
|
|
}
|
|
|
|
std::recursive_mutex &SymbolFile::GetModuleMutex() const {
|
|
return GetObjectFile()->GetModule()->GetMutex();
|
|
}
|
|
|
|
SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
|
|
std::unique_ptr<SymbolFile> best_symfile_up;
|
|
if (obj_file != nullptr) {
|
|
|
|
// We need to test the abilities of this section list. So create what it
|
|
// would be with this new obj_file.
|
|
lldb::ModuleSP module_sp(obj_file->GetModule());
|
|
if (module_sp) {
|
|
// Default to the main module section list.
|
|
ObjectFile *module_obj_file = module_sp->GetObjectFile();
|
|
if (module_obj_file != obj_file) {
|
|
// Make sure the main object file's sections are created
|
|
module_obj_file->GetSectionList();
|
|
obj_file->CreateSections(*module_sp->GetUnifiedSectionList());
|
|
}
|
|
}
|
|
|
|
// TODO: Load any plug-ins in the appropriate plug-in search paths and
|
|
// iterate over all of them to find the best one for the job.
|
|
|
|
uint32_t best_symfile_abilities = 0;
|
|
|
|
SymbolFileCreateInstance create_callback;
|
|
for (uint32_t idx = 0;
|
|
(create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(
|
|
idx)) != nullptr;
|
|
++idx) {
|
|
std::unique_ptr<SymbolFile> curr_symfile_up(create_callback(obj_file));
|
|
|
|
if (curr_symfile_up) {
|
|
const uint32_t sym_file_abilities = curr_symfile_up->GetAbilities();
|
|
if (sym_file_abilities > best_symfile_abilities) {
|
|
best_symfile_abilities = sym_file_abilities;
|
|
best_symfile_up.reset(curr_symfile_up.release());
|
|
// If any symbol file parser has all of the abilities, then we should
|
|
// just stop looking.
|
|
if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (best_symfile_up) {
|
|
// Let the winning symbol file parser initialize itself more completely
|
|
// now that it has been chosen
|
|
best_symfile_up->InitializeObject();
|
|
}
|
|
}
|
|
return best_symfile_up.release();
|
|
}
|
|
|
|
TypeList *SymbolFile::GetTypeList() {
|
|
if (m_obj_file)
|
|
return m_obj_file->GetModule()->GetTypeList();
|
|
return nullptr;
|
|
}
|
|
|
|
TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) {
|
|
TypeSystem *type_system =
|
|
m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
|
|
if (type_system)
|
|
type_system->SetSymbolFile(this);
|
|
return type_system;
|
|
}
|
|
|
|
uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
|
|
uint32_t line, bool check_inlines,
|
|
lldb::SymbolContextItem resolve_scope,
|
|
SymbolContextList &sc_list) {
|
|
return 0;
|
|
}
|
|
|
|
uint32_t
|
|
SymbolFile::FindGlobalVariables(ConstString name,
|
|
const CompilerDeclContext *parent_decl_ctx,
|
|
uint32_t max_matches, VariableList &variables) {
|
|
return 0;
|
|
}
|
|
|
|
uint32_t SymbolFile::FindGlobalVariables(const RegularExpression ®ex,
|
|
uint32_t max_matches,
|
|
VariableList &variables) {
|
|
return 0;
|
|
}
|
|
|
|
uint32_t SymbolFile::FindFunctions(ConstString name,
|
|
const CompilerDeclContext *parent_decl_ctx,
|
|
lldb::FunctionNameType name_type_mask,
|
|
bool include_inlines, bool append,
|
|
SymbolContextList &sc_list) {
|
|
if (!append)
|
|
sc_list.Clear();
|
|
return 0;
|
|
}
|
|
|
|
uint32_t SymbolFile::FindFunctions(const RegularExpression ®ex,
|
|
bool include_inlines, bool append,
|
|
SymbolContextList &sc_list) {
|
|
if (!append)
|
|
sc_list.Clear();
|
|
return 0;
|
|
}
|
|
|
|
void SymbolFile::GetMangledNamesForFunction(
|
|
const std::string &scope_qualified_name,
|
|
std::vector<ConstString> &mangled_names) {
|
|
return;
|
|
}
|
|
|
|
uint32_t SymbolFile::FindTypes(
|
|
ConstString name, const CompilerDeclContext *parent_decl_ctx,
|
|
bool append, uint32_t max_matches,
|
|
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
|
|
TypeMap &types) {
|
|
if (!append)
|
|
types.Clear();
|
|
return 0;
|
|
}
|
|
|
|
size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
|
|
bool append, TypeMap &types) {
|
|
if (!append)
|
|
types.Clear();
|
|
return 0;
|
|
}
|
|
|
|
void SymbolFile::AssertModuleLock() {
|
|
// The code below is too expensive to leave enabled in release builds. It's
|
|
// enabled in debug builds or when the correct macro is set.
|
|
#if defined(LLDB_CONFIGURATION_DEBUG)
|
|
// We assert that we have to module lock by trying to acquire the lock from a
|
|
// different thread. Note that we must abort if the result is true to
|
|
// guarantee correctness.
|
|
assert(std::async(std::launch::async,
|
|
[this] { return this->GetModuleMutex().try_lock(); })
|
|
.get() == false &&
|
|
"Module is not locked");
|
|
#endif
|
|
}
|
|
|
|
SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;
|