mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[lldb] Change Module to have a concrete UnwindTable, update (#101130)
Currently a Module has a std::optional<UnwindTable> which is created when the UnwindTable is requested from outside the Module. The idea is to delay its creation until the Module has an ObjectFile initialized, which will have been done by the time we're doing an unwind. However, Module::GetUnwindTable wasn't doing any locking, so it was possible for two threads to ask for the UnwindTable for the first time, one would be created and returned while another thread would create one, destroy the first in the process of emplacing it. It was an uncommon crash, but it was possible. Grabbing the Module's mutex would be one way to address it, but when loading ELF binaries, we start creating the SymbolTable on one thread (ObjectFileELF) grabbing the Module's mutex, and then spin up worker threads to parse the individual DWARF compilation units, which then try to also get the UnwindTable and deadlock if they try to get the Module's mutex. This changes Module to have a concrete UnwindTable as an ivar, and when it adds an ObjectFile or SymbolFileVendor, it will call the Update method on it, which will re-evaluate which sections exist in the ObjectFile/SymbolFile. UnwindTable used to have an Initialize method which set all the sections, and an Update method which would set some of them if they weren't set. I unified these with the Initialize method taking a `force` option to re-initialize the section pointers even if they had been done already before. This is addressing a rare crash report we've received, and also a failure Adrian spotted on the -fsanitize=address CI bot last week, it's still uncommon with ASAN but it can happen with the standard testsuite. rdar://128876433
This commit is contained in:
@@ -131,7 +131,8 @@ Module *Module::GetAllocatedModuleAtIndex(size_t idx) {
|
||||
}
|
||||
|
||||
Module::Module(const ModuleSpec &module_spec)
|
||||
: m_file_has_changed(false), m_first_file_changed_log(false) {
|
||||
: m_unwind_table(*this), m_file_has_changed(false),
|
||||
m_first_file_changed_log(false) {
|
||||
// Scope for locker below...
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(
|
||||
@@ -238,7 +239,8 @@ Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
|
||||
: m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)),
|
||||
m_arch(arch), m_file(file_spec), m_object_name(object_name),
|
||||
m_object_offset(object_offset), m_object_mod_time(object_mod_time),
|
||||
m_file_has_changed(false), m_first_file_changed_log(false) {
|
||||
m_unwind_table(*this), m_file_has_changed(false),
|
||||
m_first_file_changed_log(false) {
|
||||
// Scope for locker below...
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(
|
||||
@@ -254,7 +256,9 @@ Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
|
||||
m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")");
|
||||
}
|
||||
|
||||
Module::Module() : m_file_has_changed(false), m_first_file_changed_log(false) {
|
||||
Module::Module()
|
||||
: m_unwind_table(*this), m_file_has_changed(false),
|
||||
m_first_file_changed_log(false) {
|
||||
std::lock_guard<std::recursive_mutex> guard(
|
||||
GetAllocationModuleCollectionMutex());
|
||||
GetModuleCollection().push_back(this);
|
||||
@@ -323,6 +327,8 @@ ObjectFile *Module::GetMemoryObjectFile(const lldb::ProcessSP &process_sp,
|
||||
// Augment the arch with the target's information in case
|
||||
// we are unable to extract the os/environment from memory.
|
||||
m_arch.MergeFrom(process_sp->GetTarget().GetArchitecture());
|
||||
|
||||
m_unwind_table.ModuleWasUpdated();
|
||||
} else {
|
||||
error.SetErrorString("unable to find suitable object file plug-in");
|
||||
}
|
||||
@@ -1009,8 +1015,7 @@ SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
|
||||
m_symfile_up.reset(
|
||||
SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
|
||||
m_did_load_symfile = true;
|
||||
if (m_unwind_table)
|
||||
m_unwind_table->Update();
|
||||
m_unwind_table.ModuleWasUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1210,6 +1215,8 @@ ObjectFile *Module::GetObjectFile() {
|
||||
// more specific than the generic COFF architecture, only merge in
|
||||
// those values that overwrite unspecified unknown values.
|
||||
m_arch.MergeFrom(m_objfile_sp->GetArchitecture());
|
||||
|
||||
m_unwind_table.ModuleWasUpdated();
|
||||
} else {
|
||||
ReportError("failed to load objfile for {0}\nDebugging will be "
|
||||
"degraded for this module.",
|
||||
@@ -1240,12 +1247,9 @@ void Module::SectionFileAddressesChanged() {
|
||||
}
|
||||
|
||||
UnwindTable &Module::GetUnwindTable() {
|
||||
if (!m_unwind_table) {
|
||||
if (!m_symfile_spec)
|
||||
SymbolLocator::DownloadSymbolFileAsync(GetUUID());
|
||||
m_unwind_table.emplace(*this);
|
||||
}
|
||||
return *m_unwind_table;
|
||||
if (!m_symfile_spec)
|
||||
SymbolLocator::DownloadSymbolFileAsync(GetUUID());
|
||||
return m_unwind_table;
|
||||
}
|
||||
|
||||
SectionList *Module::GetUnifiedSectionList() {
|
||||
|
||||
Reference in New Issue
Block a user