diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 5c878c9b792b..b50b7db1a3b2 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -947,7 +947,6 @@ class ModuleCache; virtual const std::vector & GetTrapHandlerSymbolNames (); - //------------------------------------------------------------------ /// Find a support executable that may not live within in the /// standard locations related to LLDB. @@ -970,6 +969,14 @@ class ModuleCache; return FileSpec(); } + //------------------------------------------------------------------ + /// Allow the platform to set preferred memory cache line size. If non-zero (and the user + /// has not set cache line size explicitly), this value will be used as the cache line + /// size for memory reads. + //------------------------------------------------------------------ + virtual uint32_t + GetDefaultMemoryCacheLineSize() { return 0; } + protected: bool m_is_host; // Set to true when we are able to actually set the OS version while diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index dc73460d0e4e..403e641952ca 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -28,6 +28,7 @@ using namespace lldb_private; using namespace lldb_private::platform_android; static uint32_t g_initialize_count = 0; +static const unsigned int g_android_default_cache_size = 2048; // Fits inside 4k adb packet. void PlatformAndroid::Initialize () @@ -274,6 +275,12 @@ PlatformAndroid::DisconnectRemote() return error; } +uint32_t +PlatformAndroid::GetDefaultMemoryCacheLineSize() +{ + return g_android_default_cache_size; +} + uint32_t PlatformAndroid::GetSdkVersion() { diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.h b/lldb/source/Plugins/Platform/Android/PlatformAndroid.h index abe43686d1cc..dfca4f022a64 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.h +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.h @@ -83,6 +83,9 @@ namespace platform_android { Error DisconnectRemote () override; + uint32_t + GetDefaultMemoryCacheLineSize() override; + protected: const char * GetCacheHostname () override; diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index e634c1d53184..57034e9f8a27 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -813,6 +813,13 @@ Process::Process(lldb::TargetSP target_sp, Listener &listener, const UnixSignals eBroadcastInternalStateControlResume); // We need something valid here, even if just the default UnixSignalsSP. assert (m_unix_signals_sp && "null m_unix_signals_sp after initialization"); + + // Allow the platform to override the default cache line size + OptionValueSP value_sp = + m_collection_sp->GetPropertyAtIndex(nullptr, true, ePropertyMemCacheLineSize)->GetValue(); + uint32_t platform_cache_line_size = target_sp->GetPlatform()->GetDefaultMemoryCacheLineSize(); + if (! value_sp->OptionWasSet() && platform_cache_line_size != 0) + value_sp->SetUInt64Value(platform_cache_line_size); } //---------------------------------------------------------------------- diff --git a/lldb/test/android/platform/Makefile b/lldb/test/android/platform/Makefile new file mode 100644 index 000000000000..22e42c5a776e --- /dev/null +++ b/lldb/test/android/platform/Makefile @@ -0,0 +1,4 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/android/platform/TestDefaultCacheLineSize.py b/lldb/test/android/platform/TestDefaultCacheLineSize.py new file mode 100644 index 000000000000..f0cdab8a31bc --- /dev/null +++ b/lldb/test/android/platform/TestDefaultCacheLineSize.py @@ -0,0 +1,41 @@ +""" +Verify the default cache line size for android targets +""" + +import os +import unittest2 +import lldb +from lldbtest import * +import lldbutil + +class DefaultCacheLineSizeTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessPlatform(['android']) + def test_cache_line_size(self): + self.build(dictionary=self.getBuildFlags()) + exe = os.path.join(os.getcwd(), "a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target and target.IsValid(), "Target is valid") + + breakpoint = target.BreakpointCreateByName("main") + self.assertTrue(breakpoint and breakpoint.IsValid(), "Breakpoint is valid") + + # Run the program. + process = target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) + self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) + + # check the setting value + self.expect("settings show target.process.memory-cache-line-size", patterns=[" = 2048"]) + + # Run to completion. + process.Continue() + self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/android/platform/main.cpp b/lldb/test/android/platform/main.cpp new file mode 100644 index 000000000000..3fb9edc47270 --- /dev/null +++ b/lldb/test/android/platform/main.cpp @@ -0,0 +1,13 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main () +{ + return 0; +}