summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/Module.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-02-24 21:55:59 +0000
committerGreg Clayton <gclayton@apple.com>2012-02-24 21:55:59 +0000
commitc7f09cca6d8cd0f6da76a351548a548585d5f321 (patch)
treee98a2b6b4a7558c873acee4134557473aa082042 /lldb/source/Core/Module.cpp
parent7f99142804a94856bf2f9006922db1ed491598da (diff)
downloadbcm5719-llvm-c7f09cca6d8cd0f6da76a351548a548585d5f321.tar.gz
bcm5719-llvm-c7f09cca6d8cd0f6da76a351548a548585d5f321.zip
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
Diffstat (limited to 'lldb/source/Core/Module.cpp')
-rw-r--r--lldb/source/Core/Module.cpp110
1 files changed, 53 insertions, 57 deletions
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index eb8d35c2188..18f07ae9189 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -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()
OpenPOWER on IntegriCloud