Skip to content

Commit b8ba232

Browse files
committed
Replace MockProcess with MockProcessWithMemRead
1 parent fac0455 commit b8ba232

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

lldb/unittests/Expression/DWARFExpressionTest.cpp

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,6 @@ using namespace lldb_private;
4040
using namespace llvm::dwarf;
4141

4242
namespace {
43-
struct MockProcess : Process {
44-
MockProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
45-
: Process(target_sp, listener_sp) {}
46-
47-
llvm::StringRef GetPluginName() override { return "mock process"; }
48-
49-
bool CanDebug(lldb::TargetSP target, bool plugin_specified_by_name) override {
50-
return false;
51-
};
52-
53-
Status DoDestroy() override { return {}; }
54-
55-
void RefreshStateAfterStop() override {}
56-
57-
bool DoUpdateThreadList(ThreadList &old_thread_list,
58-
ThreadList &new_thread_list) override {
59-
return false;
60-
};
61-
62-
size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
63-
Status &error) override {
64-
for (size_t i = 0; i < size; ++i)
65-
((char *)buf)[i] = (vm_addr + i) & 0xff;
66-
error.Clear();
67-
return size;
68-
}
69-
};
70-
7143
/// Mock memory implementation for testing.
7244
/// Stores predefined memory contents indexed by {address, size} pairs.
7345
class MockMemory {
@@ -93,6 +65,7 @@ class MockMemory {
9365
};
9466

9567
typedef std::unordered_map<Request, std::vector<uint8_t>, Request::Hash> Map;
68+
MockMemory() = default;
9669
MockMemory(Map memory) : m_memory(std::move(memory)) {
9770
// Make sure the requested memory size matches the returned value.
9871
for (auto &kv : m_memory) {
@@ -118,13 +91,13 @@ class MockMemory {
11891
};
11992

12093
/// A Process whose `ReadMemory` override queries MockMemory.
121-
struct MockProcessWithMemRead : Process {
94+
struct MockProcess : Process {
12295
using addr_t = lldb::addr_t;
12396

12497
MockMemory m_memory;
12598

126-
MockProcessWithMemRead(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
127-
MockMemory memory)
99+
MockProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
100+
MockMemory memory)
128101
: Process(target_sp, listener_sp), m_memory(std::move(memory)) {}
129102
size_t DoReadMemory(addr_t vm_addr, void *buf, size_t size,
130103
Status &error) override {
@@ -320,12 +293,10 @@ static bool CreateTestContext(TestContext *ctx, llvm::StringRef triple,
320293
return false;
321294

322295
lldb::ProcessSP process_sp;
323-
if (process_memory)
324-
process_sp = std::make_shared<MockProcessWithMemRead>(
325-
target_sp, Listener::MakeListener("dummy"), std::move(*process_memory));
326-
else
327-
process_sp = std::make_shared<MockProcess>(target_sp,
328-
Listener::MakeListener("dummy"));
296+
if (!process_memory)
297+
process_memory = MockMemory();
298+
process_sp = std::make_shared<MockProcess>(
299+
target_sp, Listener::MakeListener("dummy"), std::move(*process_memory));
329300

330301
auto thread_sp = std::make_shared<MockThread>(*process_sp);
331302

@@ -604,8 +575,12 @@ TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref) {
604575
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit0, DW_OP_deref}), llvm::Failed());
605576

606577
// Set up a mock process.
578+
MockMemory::Map memory = {
579+
{{0x4, 4}, {0x4, 0x5, 0x6, 0x7}},
580+
};
607581
TestContext test_ctx;
608-
ASSERT_TRUE(CreateTestContext(&test_ctx, "i386-pc-linux"));
582+
ASSERT_TRUE(
583+
CreateTestContext(&test_ctx, "i386-pc-linux", {}, std::move(memory)));
609584

610585
ExecutionContext exe_ctx(test_ctx.process_sp);
611586
// Implicit location: *0x4.

0 commit comments

Comments
 (0)