mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
Fixed a crasher that was happening after making ObjectFile objects have a
weak reference back to the Module. We were crashing when trying to make a memory object file since it was trying to get the object in the Module constructor before the "Module *" had been put into a shared pointer, and the module was trying to initialize a weak pointer back to it. llvm-svn: 151397
This commit is contained in:
@@ -96,9 +96,6 @@ public:
|
||||
const ConstString *object_name = NULL,
|
||||
off_t object_offset = 0);
|
||||
|
||||
Module (const FileSpec& file_spec,
|
||||
const lldb::ProcessSP &processSP,
|
||||
lldb::addr_t header_addr);
|
||||
//------------------------------------------------------------------
|
||||
/// Destructor.
|
||||
//------------------------------------------------------------------
|
||||
@@ -543,6 +540,11 @@ public:
|
||||
ObjectFile *
|
||||
GetObjectFile ();
|
||||
|
||||
// Load an object file from memory.
|
||||
ObjectFile *
|
||||
GetMemoryObjectFile (const lldb::ProcessSP &process_sp,
|
||||
lldb::addr_t header_addr,
|
||||
Error &error);
|
||||
//------------------------------------------------------------------
|
||||
/// Get the symbol vendor interface for the current architecture.
|
||||
///
|
||||
|
||||
@@ -114,63 +114,6 @@ namespace lldb {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Module::Module(const FileSpec& file_spec, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) :
|
||||
m_mutex (Mutex::eMutexTypeRecursive),
|
||||
m_mod_time (),
|
||||
m_arch (),
|
||||
m_uuid (),
|
||||
m_file (file_spec),
|
||||
m_platform_file(),
|
||||
m_symfile_spec (),
|
||||
m_object_name (),
|
||||
m_object_offset (),
|
||||
m_objfile_sp (),
|
||||
m_symfile_ap (),
|
||||
m_ast (),
|
||||
m_did_load_objfile (false),
|
||||
m_did_load_symbol_vendor (false),
|
||||
m_did_parse_uuid (false),
|
||||
m_did_init_ast (false),
|
||||
m_is_dynamic_loader_module (false),
|
||||
m_was_modified (false)
|
||||
{
|
||||
// Scope for locker below...
|
||||
{
|
||||
Mutex::Locker locker (GetAllocationModuleCollectionMutex());
|
||||
GetModuleCollection().push_back(this);
|
||||
}
|
||||
StreamString s;
|
||||
if (m_file.GetFilename())
|
||||
s << m_file.GetFilename();
|
||||
s.Printf("[0x%16.16llx]", header_addr);
|
||||
m_file.GetFilename().SetCString (s.GetData());
|
||||
Mutex::Locker locker (m_mutex);
|
||||
DataBufferSP data_sp;
|
||||
if (process_sp)
|
||||
{
|
||||
m_did_load_objfile = true;
|
||||
std::auto_ptr<DataBufferHeap> data_ap (new DataBufferHeap (512, 0));
|
||||
Error error;
|
||||
const size_t bytes_read = process_sp->ReadMemory (header_addr,
|
||||
data_ap->GetBytes(),
|
||||
data_ap->GetByteSize(),
|
||||
error);
|
||||
if (bytes_read == 512)
|
||||
{
|
||||
data_sp.reset (data_ap.release());
|
||||
m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
|
||||
if (m_objfile_sp)
|
||||
{
|
||||
// Once we get the object file, update our module with the object file's
|
||||
// architecture since it might differ in vendor/os if some parts were
|
||||
// unknown.
|
||||
m_objfile_sp->GetArchitecture (m_arch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Module::Module(const FileSpec& file_spec,
|
||||
const ArchSpec& arch,
|
||||
const ConstString *object_name,
|
||||
@@ -244,6 +187,59 @@ Module::~Module()
|
||||
m_objfile_sp.reset();
|
||||
}
|
||||
|
||||
ObjectFile *
|
||||
Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error)
|
||||
{
|
||||
if (m_objfile_sp)
|
||||
{
|
||||
error.SetErrorString ("object file already exists");
|
||||
}
|
||||
else
|
||||
{
|
||||
Mutex::Locker locker (m_mutex);
|
||||
if (process_sp)
|
||||
{
|
||||
StreamString s;
|
||||
if (m_file.GetFilename())
|
||||
s << m_file.GetFilename();
|
||||
s.Printf("[0x%16.16llx]", header_addr);
|
||||
m_file.GetFilename().SetCString (s.GetData());
|
||||
m_did_load_objfile = true;
|
||||
std::auto_ptr<DataBufferHeap> data_ap (new DataBufferHeap (512, 0));
|
||||
Error readmem_error;
|
||||
const size_t bytes_read = process_sp->ReadMemory (header_addr,
|
||||
data_ap->GetBytes(),
|
||||
data_ap->GetByteSize(),
|
||||
readmem_error);
|
||||
if (bytes_read == 512)
|
||||
{
|
||||
DataBufferSP data_sp(data_ap.release());
|
||||
m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
|
||||
if (m_objfile_sp)
|
||||
{
|
||||
// Once we get the object file, update our module with the object file's
|
||||
// architecture since it might differ in vendor/os if some parts were
|
||||
// unknown.
|
||||
m_objfile_sp->GetArchitecture (m_arch);
|
||||
}
|
||||
else
|
||||
{
|
||||
error.SetErrorString ("unable to find suitable object file plug-in");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error.SetErrorString ("invalid process");
|
||||
}
|
||||
}
|
||||
return m_objfile_sp.get();
|
||||
}
|
||||
|
||||
|
||||
const lldb_private::UUID&
|
||||
Module::GetUUID()
|
||||
|
||||
@@ -2222,20 +2222,26 @@ Process::ReadModuleFromMemory (const FileSpec& file_spec,
|
||||
bool add_image_to_target,
|
||||
bool load_sections_in_target)
|
||||
{
|
||||
ModuleSP module_sp (new Module (file_spec, shared_from_this(), header_addr));
|
||||
ModuleSP module_sp (new Module (file_spec, ArchSpec()));
|
||||
if (module_sp)
|
||||
{
|
||||
if (add_image_to_target)
|
||||
Error error;
|
||||
ObjectFile *objfile = module_sp->GetMemoryObjectFile (shared_from_this(), header_addr, error);
|
||||
if (objfile)
|
||||
{
|
||||
m_target.GetImages().Append(module_sp);
|
||||
if (load_sections_in_target)
|
||||
if (add_image_to_target)
|
||||
{
|
||||
bool changed = false;
|
||||
module_sp->SetLoadAddress (m_target, 0, changed);
|
||||
m_target.GetImages().Append(module_sp);
|
||||
if (load_sections_in_target)
|
||||
{
|
||||
bool changed = false;
|
||||
module_sp->SetLoadAddress (m_target, 0, changed);
|
||||
}
|
||||
}
|
||||
return module_sp;
|
||||
}
|
||||
}
|
||||
return module_sp;
|
||||
return ModuleSP();
|
||||
}
|
||||
|
||||
Error
|
||||
|
||||
Reference in New Issue
Block a user