<rdar://problem/14515139>
Add a GetFoundationVersion() to AppleObjCRuntime
This API is used to return and cache the major version of Foundation.framework, which is potentially a useful piece of data to key off of to enable or disable certain ObjC related behaviors (especially in data formatters)
llvm-svn: 204756
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index e6f2daa..0cc1bc8 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1646,7 +1646,7 @@
if (versions && num_versions)
{
for (uint32_t i=0; i<num_versions; ++i)
- versions[i] = UINT32_MAX;
+ versions[i] = LLDB_INVALID_MODULE_VERSION;
}
return 0;
}
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index 2d2e405..2c8f348 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -251,6 +251,32 @@
return false;
}
+// we use the version of Foundation to make assumptions about the ObjC runtime on a target
+uint32_t
+AppleObjCRuntime::GetFoundationVersion ()
+{
+ if (!m_Foundation_major.hasValue())
+ {
+ const ModuleList& modules = m_process->GetTarget().GetImages();
+ uint32_t major = UINT32_MAX;
+ for (uint32_t idx = 0; idx < modules.GetSize(); idx++)
+ {
+ lldb::ModuleSP module_sp = modules.GetModuleAtIndex(idx);
+ if (!module_sp)
+ continue;
+ if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(""),"Foundation") == 0)
+ {
+ module_sp->GetVersion(&major,1);
+ m_Foundation_major = major;
+ return major;
+ }
+ }
+ return LLDB_INVALID_MODULE_VERSION;
+ }
+ else
+ return m_Foundation_major.getValue();
+}
+
bool
AppleObjCRuntime::IsModuleObjCLibrary (const ModuleSP &module_sp)
{
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
index 96e9874..f9e0054 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
@@ -13,6 +13,9 @@
// C Includes
// C++ Includes
// Other libraries and framework includes
+
+#include "llvm/ADT/Optional.h"
+
// Project includes
#include "lldb/lldb-private.h"
#include "lldb/Target/LanguageRuntime.h"
@@ -103,6 +106,9 @@
virtual lldb::SearchFilterSP
CreateExceptionSearchFilter ();
+ uint32_t
+ GetFoundationVersion ();
+
protected:
Address *
GetPrintForDebuggerAddr();
@@ -112,11 +118,14 @@
std::unique_ptr<lldb_private::AppleObjCTrampolineHandler> m_objc_trampoline_handler_ap;
lldb::BreakpointSP m_objc_exception_bp_sp;
lldb::ModuleWP m_objc_module_wp;
+
+ llvm::Optional<uint32_t> m_Foundation_major;
AppleObjCRuntime(Process *process) :
lldb_private::ObjCLanguageRuntime(process),
m_read_objc_library (false),
- m_objc_trampoline_handler_ap ()
+ m_objc_trampoline_handler_ap (),
+ m_Foundation_major()
{
// Call CreateInstance instead.
}
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index acf415c..921b0ab 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2472,45 +2472,22 @@
return (ptr & 1);
}
-// we use the version of Foundation to make assumptions about the ObjC runtime on a target
-uint32_t
-AppleObjCRuntimeV2::TaggedPointerVendorLegacy::GetFoundationVersion (Target &target)
-{
- const ModuleList& modules = target.GetImages();
- uint32_t major = UINT32_MAX;
- for (uint32_t idx = 0; idx < modules.GetSize(); idx++)
- {
- lldb::ModuleSP module_sp = modules.GetModuleAtIndex(idx);
- if (!module_sp)
- continue;
- if (strcmp(module_sp->GetFileSpec().GetFilename().AsCString(""),"Foundation") == 0)
- {
- module_sp->GetVersion(&major,1);
- break;
- }
- }
- return major;
-}
-
ObjCLanguageRuntime::ClassDescriptorSP
AppleObjCRuntimeV2::TaggedPointerVendorLegacy::GetClassDescriptor (lldb::addr_t ptr)
{
if (!IsPossibleTaggedPointer(ptr))
return ObjCLanguageRuntime::ClassDescriptorSP();
- Process* process(m_runtime.GetProcess());
+ uint32_t foundation_version = m_runtime.GetFoundationVersion();
- if (m_Foundation_version == 0)
- m_Foundation_version = GetFoundationVersion(process->GetTarget());
-
- if (m_Foundation_version == UINT32_MAX)
+ if (foundation_version == LLDB_INVALID_MODULE_VERSION)
return ObjCLanguageRuntime::ClassDescriptorSP();
uint64_t class_bits = (ptr & 0xE) >> 1;
ConstString name;
// TODO: make a table
- if (m_Foundation_version >= 900)
+ if (foundation_version >= 900)
{
switch (class_bits)
{
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
index 5ee7340..c6addc6 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -226,16 +226,10 @@
GetClassDescriptor (lldb::addr_t ptr);
protected:
TaggedPointerVendorLegacy (AppleObjCRuntimeV2& runtime) :
- TaggedPointerVendor (runtime),
- m_Foundation_version(0)
+ TaggedPointerVendor (runtime)
{
}
- static uint32_t
- GetFoundationVersion (Target& target);
-
- uint32_t m_Foundation_version;
-
friend class AppleObjCRuntimeV2::TaggedPointerVendor;
DISALLOW_COPY_AND_ASSIGN(TaggedPointerVendorLegacy);
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 9aad296..e4de46e 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -526,7 +526,7 @@
for (ProgramHeaderCollConstIter I = program_headers.begin();
I != program_headers.end(); ++I)
{
- segment_data_end = std::max (I->p_offset + I->p_filesz, segment_data_end);
+ segment_data_end = std::max<unsigned long long> (I->p_offset + I->p_filesz, segment_data_end);
}
if (segment_data_end > data_sp->GetByteSize())