Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Interpreter/OptionValueUInt64.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/ABI.h"
Expand Down Expand Up @@ -173,6 +174,13 @@ ProcessProperties::ProcessProperties(lldb_private::Process *process)
// Global process properties, set them up one time
m_collection_sp = std::make_shared<ProcessOptionValueProperties>("process");
m_collection_sp->Initialize(g_process_properties_def);
// MemoryCache divides by the cache line size and holds it in a uint32_t, so
// reject a value it could not use.
OptionValueUInt64 *line_size =
m_collection_sp->GetPropertyAtIndexAsOptionValueUInt64(
ePropertyMemCacheLineSize);
line_size->SetMinimumValue(1);
line_size->SetMaximumValue(UINT32_MAX);
m_collection_sp->AppendProperty(
"thread", "Settings specific to threads.", true,
Thread::GetGlobalProperties().GetValueProperties());
Expand Down
39 changes: 39 additions & 0 deletions lldb/unittests/Target/MemoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,45 @@ TEST_F(MemoryTest, TestReadStopsAtAnInvalidRange) {
EXPECT_TRUE(inside_error.Fail());
}

TEST_F(MemoryTest, TestUnusableCacheLineSize) {
ArchSpec arch("arm64-apple-macosx");

Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);

// A Process copies the global properties when it is constructed, so the
// setting must be in place before CreateProcess, and put back afterwards.
struct SettingGuard {
~SettingGuard() {
Process::GetGlobalProperties().SetPropertyValue(
nullptr, eVarSetOperationClear, "memory-cache-line-size", "");
}
} restore_setting;

auto set_line_size = [](const char *setting) {
return Process::GetGlobalProperties().SetPropertyValue(
nullptr, eVarSetOperationAssign, "memory-cache-line-size", setting);
};

// A usable setting must take effect, or the checks below prove nothing.
ASSERT_TRUE(set_line_size("256").Success());
TargetSP target_sp = CreateTarget(debugger_sp, arch);
DummyProcess *process =
static_cast<DummyProcess *>(CreateProcess(target_sp).get());
EXPECT_EQ(process->GetMemoryCacheLineSize(), 256u);

for (const char *setting : {"0", "4294967296"}) {
SCOPED_TRACE(setting);
EXPECT_TRUE(set_line_size(setting).Fail());
// Refused, so the last usable value is still in effect.
EXPECT_EQ(process->GetMemoryCacheLineSize(), 256u);
TargetSP later_target_sp = CreateTarget(debugger_sp, arch);
EXPECT_EQ(CreateProcess(later_target_sp)->GetMemoryCacheLineSize(), 256u);
}
}

TEST_F(MemoryTest, TestReadInteger) {
ArchSpec arch("x86_64-apple-macosx-");

Expand Down
Loading