summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ObjectContainer/Universal-Mach-O
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2013-02-06 17:22:03 +0000
committerGreg Clayton <gclayton@apple.com>2013-02-06 17:22:03 +0000
commit5ce9c5657cb77c0f1919be0aa3c990009a7bc60b (patch)
treeaca6aa117e81783b21300ba0ff86b126ef7035e6 /lldb/source/Plugins/ObjectContainer/Universal-Mach-O
parent0e1cf09c89343dbbe14490c550ab1fc74b642003 (diff)
downloadbcm5719-llvm-5ce9c5657cb77c0f1919be0aa3c990009a7bc60b.tar.gz
bcm5719-llvm-5ce9c5657cb77c0f1919be0aa3c990009a7bc60b.zip
<rdar://problem/13159777>
lldb was mmap'ing archive files once per .o file it loads, now it correctly shares the archive between modules. LLDB was also always mapping entire contents of universal mach-o files, now it maps just the slice that is required. Added a new logging channel for "lldb" called "mmap" to help track future regressions. Modified the ObjectFile and ObjectContainer plugin interfaces to take a data offset along with the file offset and size so we can implement the correct caching and efficient reading of parts of files without mmap'ing the entire file like we used to. The current implementation still keeps entire .a files mmaped (once) and entire slices from universal files mmaped to ensure that if a client builds their binaries during a debug session we don't lose our data and get corrupt object file info and debug info. llvm-svn: 174524
Diffstat (limited to 'lldb/source/Plugins/ObjectContainer/Universal-Mach-O')
-rw-r--r--lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp82
-rw-r--r--lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h14
2 files changed, 52 insertions, 44 deletions
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
index 5641c265675..ad833ff3c31 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
@@ -8,10 +8,11 @@
//===----------------------------------------------------------------------===//
#include "ObjectContainerUniversalMachO.h"
-#include "lldb/Core/Stream.h"
#include "lldb/Core/ArchSpec.h"
+#include "lldb/Core/DataBuffer.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Stream.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Target.h"
@@ -52,26 +53,30 @@ ObjectContainerUniversalMachO::CreateInstance
(
const lldb::ModuleSP &module_sp,
DataBufferSP& data_sp,
+ lldb::offset_t data_offset,
const FileSpec *file,
- addr_t offset,
- addr_t length
+ lldb::offset_t file_offset,
+ lldb::offset_t length
)
{
- DataExtractor data;
- data.SetData (data_sp, offset, length);
- if (ObjectContainerUniversalMachO::MagicBytesMatch(data))
+ // We get data when we aren't trying to look for cached container information,
+ // so only try and look for an architecture slice if we get data
+ if (data_sp)
{
- std::auto_ptr<ObjectContainerUniversalMachO> container_ap(new ObjectContainerUniversalMachO (module_sp, data_sp, file, offset, length));
- if (container_ap->ParseHeader())
+ DataExtractor data;
+ data.SetData (data_sp, data_offset, length);
+ if (ObjectContainerUniversalMachO::MagicBytesMatch(data))
{
- return container_ap.release();
+ std::auto_ptr<ObjectContainerUniversalMachO> container_ap(new ObjectContainerUniversalMachO (module_sp, data_sp, data_offset, file, file_offset, length));
+ if (container_ap->ParseHeader())
+ {
+ return container_ap.release();
+ }
}
}
return NULL;
}
-
-
bool
ObjectContainerUniversalMachO::MagicBytesMatch (const DataExtractor &data)
{
@@ -83,12 +88,13 @@ ObjectContainerUniversalMachO::MagicBytesMatch (const DataExtractor &data)
ObjectContainerUniversalMachO::ObjectContainerUniversalMachO
(
const lldb::ModuleSP &module_sp,
- DataBufferSP& dataSP,
+ DataBufferSP& data_sp,
+ lldb::offset_t data_offset,
const FileSpec *file,
- addr_t offset,
- addr_t length
+ lldb::offset_t file_offset,
+ lldb::offset_t length
) :
- ObjectContainer (module_sp, file, offset, length, dataSP),
+ ObjectContainer (module_sp, file, file_offset, length, data_sp, data_offset),
m_header(),
m_fat_archs()
{
@@ -103,6 +109,7 @@ ObjectContainerUniversalMachO::~ObjectContainerUniversalMachO()
bool
ObjectContainerUniversalMachO::ParseHeader ()
{
+ bool success = false;
// Store the file offset for this universal file as we could have a universal .o file
// in a BSD archive, or be contained in another kind of object.
lldb::offset_t offset = 0;
@@ -130,14 +137,17 @@ ObjectContainerUniversalMachO::ParseHeader ()
}
}
}
- return true;
+ success = true;
}
else
{
memset(&m_header, 0, sizeof(m_header));
}
- return false;
+ // We no longer need any data, we parsed all we needed to parse
+ // and cached it in m_header and m_fat_archs
+ m_data.Clear();
+ return success;
}
void
@@ -206,35 +216,31 @@ ObjectContainerUniversalMachO::GetObjectFile (const FileSpec *file)
// First, try to find an exact match for the Arch of the Target.
for (arch_idx = 0; arch_idx < m_header.nfat_arch; ++arch_idx)
{
- if (GetArchitectureAtIndex (arch_idx, curr_arch))
- {
- if (arch.IsExactMatch(curr_arch))
- {
- return ObjectFile::FindPlugin (module_sp,
- file,
- m_offset + m_fat_archs[arch_idx].offset,
- m_fat_archs[arch_idx].size,
- m_data.GetSharedDataBuffer());
- }
- }
+ if (GetArchitectureAtIndex (arch_idx, curr_arch) && arch.IsExactMatch(curr_arch))
+ break;
}
// Failing an exact match, try to find a compatible Arch of the Target.
- for (arch_idx = 0; arch_idx < m_header.nfat_arch; ++arch_idx)
+ if (arch_idx >= m_header.nfat_arch)
{
- if (GetArchitectureAtIndex (arch_idx, curr_arch))
+ for (arch_idx = 0; arch_idx < m_header.nfat_arch; ++arch_idx)
{
- if (arch.IsCompatibleMatch(curr_arch))
- {
- return ObjectFile::FindPlugin (module_sp,
- file,
- m_offset + m_fat_archs[arch_idx].offset,
- m_fat_archs[arch_idx].size,
- m_data.GetSharedDataBuffer());
- }
+ if (GetArchitectureAtIndex (arch_idx, curr_arch) && arch.IsCompatibleMatch(curr_arch))
+ break;
}
}
+ if (arch_idx < m_header.nfat_arch)
+ {
+ DataBufferSP data_sp;
+ lldb::offset_t data_offset = 0;
+ return ObjectFile::FindPlugin (module_sp,
+ file,
+ m_offset + m_fat_archs[arch_idx].offset,
+ m_fat_archs[arch_idx].size,
+ data_sp,
+ data_offset);
+ }
}
return ObjectFileSP();
}
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
index 088f587c8b1..78945b0ef98 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
@@ -36,10 +36,11 @@ public:
static lldb_private::ObjectContainer *
CreateInstance (const lldb::ModuleSP &module_sp,
- lldb::DataBufferSP& dataSP,
+ lldb::DataBufferSP& data_sp,
+ lldb::offset_t data_offset,
const lldb_private::FileSpec *file,
- lldb::addr_t offset,
- lldb::addr_t length);
+ lldb::offset_t offset,
+ lldb::offset_t length);
static bool
MagicBytesMatch (const lldb_private::DataExtractor &data);
@@ -48,10 +49,11 @@ public:
// Member Functions
//------------------------------------------------------------------
ObjectContainerUniversalMachO (const lldb::ModuleSP &module_sp,
- lldb::DataBufferSP& dataSP,
+ lldb::DataBufferSP& data_sp,
+ lldb::offset_t data_offset,
const lldb_private::FileSpec *file,
- lldb::addr_t offset,
- lldb::addr_t length);
+ lldb::offset_t offset,
+ lldb::offset_t length);
virtual
~ObjectContainerUniversalMachO();
OpenPOWER on IntegriCloud