summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2016-07-29 00:18:39 +0000
committerJason Molenda <jmolenda@apple.com>2016-07-29 00:18:39 +0000
commit13becd4f43226b7272625180ff497081f058a687 (patch)
treebed8f91e9be493fc04963fcf743676cf38f298cc
parent9cbc30103598be2d45e3c93991f2d356835860f5 (diff)
downloadbcm5719-llvm-13becd4f43226b7272625180ff497081f058a687.tar.gz
bcm5719-llvm-13becd4f43226b7272625180ff497081f058a687.zip
Move the code which knows how to get information about the shared
cache from ObjectFileMachO (very wrong place) to the DynamicLoader plugins (better place). Not much change to the code itself, although the old ObjectFileMachO method would try both the new dyld SPI and reading the dyld_all_image_infos structure. In the new methods, I've separated those into the appropriate DynamicLoader plugins. llvm-svn: 277088
-rw-r--r--lldb/include/lldb/Target/DynamicLoader.h50
-rw-r--r--lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp46
-rw-r--r--lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h6
-rw-r--r--lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp73
-rw-r--r--lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h6
-rw-r--r--lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp70
6 files changed, 188 insertions, 63 deletions
diff --git a/lldb/include/lldb/Target/DynamicLoader.h b/lldb/include/lldb/Target/DynamicLoader.h
index 2c4956829b2..7f8cf9a5ff5 100644
--- a/lldb/include/lldb/Target/DynamicLoader.h
+++ b/lldb/include/lldb/Target/DynamicLoader.h
@@ -14,6 +14,7 @@
#include "lldb/lldb-private.h"
#include "lldb/Core/Error.h"
#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/UUID.h"
namespace lldb_private {
@@ -251,6 +252,55 @@ public:
lldb::addr_t base_addr,
bool base_addr_is_offset);
+ //------------------------------------------------------------------
+ /// Get information about the shared cache for a process, if possible.
+ ///
+ /// On some systems (e.g. Darwin based systems), a set of libraries
+ /// that are common to most processes may be put in a single region
+ /// of memory and mapped into every process, this is called the
+ /// shared cache, as a performance optimization.
+ ///
+ /// Many targets will not have the concept of a shared cache.
+ ///
+ /// Depending on how the DynamicLoader gathers information about the
+ /// shared cache, it may be able to only return basic information -
+ /// like the UUID of the cache - or it may be able to return additional
+ /// information about the cache.
+ ///
+ /// @param[out] base_address
+ /// The base address (load address) of the shared cache.
+ /// LLDB_INVALID_ADDRESS if it cannot be determined.
+ ///
+ /// @param[out] uuid
+ /// The UUID of the shared cache, if it can be determined.
+ /// If the UUID cannot be fetched, IsValid() will be false.
+ ///
+ /// @param[out] using_shared_cache
+ /// If this process is using a shared cache.
+ /// If unknown, eLazyBoolCalculate is returned.
+ ///
+ /// @param[out] private_shared_cache
+ /// A LazyBool indicating whether this process is using a
+ /// private shared cache.
+ /// If this information cannot be fetched, eLazyBoolCalculate.
+ ///
+ /// @return
+ /// Returns false if this DynamicLoader cannot gather information
+ /// about the shared cache / has no concept of a shared cache.
+ //------------------------------------------------------------------
+ virtual bool
+ GetSharedCacheInformation (lldb::addr_t &base_address,
+ UUID &uuid,
+ LazyBool &using_shared_cache,
+ LazyBool &private_shared_cache)
+ {
+ base_address = LLDB_INVALID_ADDRESS;
+ uuid.Clear();
+ using_shared_cache = eLazyBoolCalculate;
+ private_shared_cache = eLazyBoolCalculate;
+ return false;
+ }
+
protected:
//------------------------------------------------------------------
// Utility methods for derived classes
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
index d78b8a761f2..718134ac4d7 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
@@ -490,6 +490,52 @@ DynamicLoaderMacOS::CanLoadImage ()
return error;
}
+bool
+DynamicLoaderMacOS::GetSharedCacheInformation (lldb::addr_t &base_address,
+ UUID &uuid,
+ LazyBool &using_shared_cache,
+ LazyBool &private_shared_cache)
+{
+ base_address = LLDB_INVALID_ADDRESS;
+ uuid.Clear();
+ using_shared_cache = eLazyBoolCalculate;
+ private_shared_cache = eLazyBoolCalculate;
+
+ if (m_process)
+ {
+ StructuredData::ObjectSP info = m_process->GetSharedCacheInfo();
+ StructuredData::Dictionary *info_dict = nullptr;
+ if (info.get() && info->GetAsDictionary())
+ {
+ info_dict = info->GetAsDictionary();
+ }
+
+ // {"shared_cache_base_address":140735683125248,"shared_cache_uuid":"DDB8D70C-C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false}
+
+ if (info_dict
+ && info_dict->HasKey("shared_cache_uuid")
+ && info_dict->HasKey("no_shared_cache")
+ && info_dict->HasKey("shared_cache_base_address"))
+ {
+ base_address = info_dict->GetValueForKey("shared_cache_base_address")->GetIntegerValue(LLDB_INVALID_ADDRESS);
+ std::string uuid_str = info_dict->GetValueForKey("shared_cache_uuid")->GetStringValue().c_str();
+ if (!uuid_str.empty())
+ uuid.SetFromCString (uuid_str.c_str());
+ if (info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue() == false)
+ using_shared_cache = eLazyBoolYes;
+ else
+ using_shared_cache = eLazyBoolNo;
+ if (info_dict->GetValueForKey("shared_cache_private_cache")->GetBooleanValue())
+ private_shared_cache = eLazyBoolYes;
+ else
+ private_shared_cache = eLazyBoolNo;
+
+ return true;
+ }
+ }
+ return false;
+}
+
void
DynamicLoaderMacOS::Initialize()
{
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
index 79eee51c46b..63d67308d69 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
@@ -70,6 +70,12 @@ public:
lldb_private::Error
CanLoadImage() override;
+ bool
+ GetSharedCacheInformation (lldb::addr_t &base_address,
+ lldb_private::UUID &uuid,
+ lldb_private::LazyBool &using_shared_cache,
+ lldb_private::LazyBool &private_shared_cache) override;
+
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 109abd04b0c..6e2d625a9b5 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -1153,6 +1153,79 @@ DynamicLoaderMacOSXDYLD::CanLoadImage ()
return error;
}
+bool
+DynamicLoaderMacOSXDYLD::GetSharedCacheInformation (lldb::addr_t &base_address,
+ UUID &uuid,
+ LazyBool &using_shared_cache,
+ LazyBool &private_shared_cache)
+{
+ base_address = LLDB_INVALID_ADDRESS;
+ uuid.Clear();
+ using_shared_cache = eLazyBoolCalculate;
+ private_shared_cache = eLazyBoolCalculate;
+
+ if (m_process)
+ {
+ addr_t all_image_infos = m_process->GetImageInfoAddress();
+
+ // The address returned by GetImageInfoAddress may be the address of dyld (don't want)
+ // or it may be the address of the dyld_all_image_infos structure (want). The first four
+ // bytes will be either the version field (all_image_infos) or a Mach-O file magic constant.
+ // Version 13 and higher of dyld_all_image_infos is required to get the sharedCacheUUID field.
+
+ Error err;
+ uint32_t version_or_magic = m_process->ReadUnsignedIntegerFromMemory (all_image_infos, 4, -1, err);
+ if (version_or_magic != static_cast<uint32_t>(-1)
+ && version_or_magic != llvm::MachO::MH_MAGIC
+ && version_or_magic != llvm::MachO::MH_CIGAM
+ && version_or_magic != llvm::MachO::MH_MAGIC_64
+ && version_or_magic != llvm::MachO::MH_CIGAM_64
+ && version_or_magic >= 13)
+ {
+ addr_t sharedCacheUUID_address = LLDB_INVALID_ADDRESS;
+ int wordsize = m_process->GetAddressByteSize();
+ if (wordsize == 8)
+ {
+ sharedCacheUUID_address = all_image_infos + 160; // sharedCacheUUID <mach-o/dyld_images.h>
+ }
+ if (wordsize == 4)
+ {
+ sharedCacheUUID_address = all_image_infos + 84; // sharedCacheUUID <mach-o/dyld_images.h>
+ }
+ if (sharedCacheUUID_address != LLDB_INVALID_ADDRESS)
+ {
+ uuid_t shared_cache_uuid;
+ if (m_process->ReadMemory (sharedCacheUUID_address, shared_cache_uuid, sizeof (uuid_t), err) == sizeof (uuid_t))
+ {
+ uuid.SetBytes (shared_cache_uuid);
+ if (uuid.IsValid ())
+ {
+ using_shared_cache = eLazyBoolYes;
+ }
+ }
+
+ if (version_or_magic >= 15)
+ {
+ // The sharedCacheBaseAddress field is the next one in the dyld_all_image_infos struct.
+ addr_t sharedCacheBaseAddr_address = sharedCacheUUID_address + 16;
+ Error error;
+ base_address = m_process->ReadUnsignedIntegerFromMemory (sharedCacheBaseAddr_address, wordsize, LLDB_INVALID_ADDRESS, error);
+ if (error.Fail())
+ base_address = LLDB_INVALID_ADDRESS;
+ }
+
+ return true;
+ }
+
+ //
+ // add
+ // NB: sharedCacheBaseAddress is the next field in dyld_all_image_infos after
+ // sharedCacheUUID -- that is, 16 bytes after it, if we wanted to fetch it.
+ }
+ }
+ return false;
+}
+
void
DynamicLoaderMacOSXDYLD::Initialize()
{
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
index 81e16d1f454..5c970218b9a 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
@@ -74,6 +74,12 @@ public:
lldb_private::Error
CanLoadImage() override;
+ bool
+ GetSharedCacheInformation (lldb::addr_t &base_address,
+ lldb_private::UUID &uuid,
+ lldb_private::LazyBool &using_shared_cache,
+ lldb_private::LazyBool &private_shared_cache) override;
+
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 2f2d34d252f..6c72ef8b1f5 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -32,6 +32,7 @@
#include "lldb/Host/FileSpec.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
@@ -5449,70 +5450,13 @@ UUID
ObjectFileMachO::GetProcessSharedCacheUUID (Process *process)
{
UUID uuid;
-
- // First see if we can get the shared cache details from debugserver
- if (process)
- {
- StructuredData::ObjectSP info = process->GetSharedCacheInfo();
- StructuredData::Dictionary *info_dict = nullptr;
- if (info.get() && info->GetAsDictionary())
- {
- info_dict = info->GetAsDictionary();
- }
-
- // {"shared_cache_base_address":140735683125248,"shared_cache_uuid":"DDB8D70C-C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false}
-
- if (info_dict
- && info_dict->HasKey("shared_cache_uuid")
- && info_dict->HasKey("no_shared_cache")
- && info_dict->HasKey("shared_cache_base_address"))
- {
- bool process_using_shared_cache = info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue() == false;
- std::string uuid_str = info_dict->GetValueForKey("shared_cache_uuid")->GetStringValue();
-
- if (process_using_shared_cache && !uuid_str.empty() && uuid.SetFromCString (uuid_str.c_str()) == 0)
- return uuid;
- }
- }
-
- // Fall back to trying to read the shared cache info out of dyld's internal data structures
- if (process)
+ if (process && process->GetDynamicLoader())
{
- addr_t all_image_infos = process->GetImageInfoAddress();
-
- // The address returned by GetImageInfoAddress may be the address of dyld (don't want)
- // or it may be the address of the dyld_all_image_infos structure (want). The first four
- // bytes will be either the version field (all_image_infos) or a Mach-O file magic constant.
- // Version 13 and higher of dyld_all_image_infos is required to get the sharedCacheUUID field.
-
- Error err;
- uint32_t version_or_magic = process->ReadUnsignedIntegerFromMemory (all_image_infos, 4, -1, err);
- if (version_or_magic != static_cast<uint32_t>(-1)
- && version_or_magic != MH_MAGIC
- && version_or_magic != MH_CIGAM
- && version_or_magic != MH_MAGIC_64
- && version_or_magic != MH_CIGAM_64
- && version_or_magic >= 13)
- {
- addr_t sharedCacheUUID_address = LLDB_INVALID_ADDRESS;
- int wordsize = process->GetAddressByteSize();
- if (wordsize == 8)
- {
- sharedCacheUUID_address = all_image_infos + 160; // sharedCacheUUID <mach-o/dyld_images.h>
- }
- if (wordsize == 4)
- {
- sharedCacheUUID_address = all_image_infos + 84; // sharedCacheUUID <mach-o/dyld_images.h>
- }
- if (sharedCacheUUID_address != LLDB_INVALID_ADDRESS)
- {
- uuid_t shared_cache_uuid;
- if (process->ReadMemory (sharedCacheUUID_address, shared_cache_uuid, sizeof (uuid_t), err) == sizeof (uuid_t))
- {
- uuid.SetBytes (shared_cache_uuid);
- }
- }
- }
+ DynamicLoader *dl = process->GetDynamicLoader();
+ addr_t load_address;
+ LazyBool using_shared_cache;
+ LazyBool private_shared_cache;
+ dl->GetSharedCacheInformation (load_address, uuid, using_shared_cache, private_shared_cache);
}
return uuid;
}
OpenPOWER on IntegriCloud