unwindstack: rename Memory::ReadPartially to Read.

Test: mma
Test: treehugger
Change-Id: I53c2c5600fb44620b629c01db85a67789594595f
This commit is contained in:
Josh Gao 2017-10-18 11:52:53 -07:00
parent ef35aa5d40
commit b837763b49
8 changed files with 31 additions and 31 deletions

View File

@ -85,7 +85,7 @@ static size_t ProcessVmRead(pid_t pid, void* dst, uint64_t remote_src, size_t le
namespace unwindstack {
bool Memory::ReadFully(uint64_t addr, void* dst, size_t size) {
size_t rc = ReadPartially(addr, dst, size);
size_t rc = Read(addr, dst, size);
return rc == size;
}
@ -114,7 +114,7 @@ std::shared_ptr<Memory> Memory::CreateProcessMemory(pid_t pid) {
return std::shared_ptr<Memory>(new MemoryRemote(pid));
}
size_t MemoryBuffer::ReadPartially(uint64_t addr, void* dst, size_t size) {
size_t MemoryBuffer::Read(uint64_t addr, void* dst, size_t size) {
if (addr >= raw_.size()) {
return 0;
}
@ -185,7 +185,7 @@ bool MemoryFileAtOffset::Init(const std::string& file, uint64_t offset, uint64_t
return true;
}
size_t MemoryFileAtOffset::ReadPartially(uint64_t addr, void* dst, size_t size) {
size_t MemoryFileAtOffset::Read(uint64_t addr, void* dst, size_t size) {
if (addr >= size_) {
return 0;
}
@ -198,11 +198,11 @@ size_t MemoryFileAtOffset::ReadPartially(uint64_t addr, void* dst, size_t size)
return actual_len;
}
size_t MemoryRemote::ReadPartially(uint64_t addr, void* dst, size_t size) {
size_t MemoryRemote::Read(uint64_t addr, void* dst, size_t size) {
return ProcessVmRead(pid_, dst, addr, size);
}
size_t MemoryLocal::ReadPartially(uint64_t addr, void* dst, size_t size) {
size_t MemoryLocal::Read(uint64_t addr, void* dst, size_t size) {
return ProcessVmRead(getpid(), dst, addr, size);
}
@ -210,7 +210,7 @@ MemoryRange::MemoryRange(const std::shared_ptr<Memory>& memory, uint64_t begin,
uint64_t offset)
: memory_(memory), begin_(begin), length_(length), offset_(offset) {}
size_t MemoryRange::ReadPartially(uint64_t addr, void* dst, size_t size) {
size_t MemoryRange::Read(uint64_t addr, void* dst, size_t size) {
if (addr < offset_) {
return 0;
}
@ -226,7 +226,7 @@ size_t MemoryRange::ReadPartially(uint64_t addr, void* dst, size_t size) {
return 0;
}
return memory_->ReadPartially(read_addr, dst, read_length);
return memory_->Read(read_addr, dst, read_length);
}
bool MemoryOffline::Init(const std::string& file, uint64_t offset) {
@ -250,12 +250,12 @@ bool MemoryOffline::Init(const std::string& file, uint64_t offset) {
return true;
}
size_t MemoryOffline::ReadPartially(uint64_t addr, void* dst, size_t size) {
size_t MemoryOffline::Read(uint64_t addr, void* dst, size_t size) {
if (!memory_) {
return 0;
}
return memory_->ReadPartially(addr, dst, size);
return memory_->Read(addr, dst, size);
}
} // namespace unwindstack

View File

@ -36,7 +36,7 @@ class Memory {
virtual bool ReadString(uint64_t addr, std::string* string, uint64_t max_read = UINT64_MAX);
virtual size_t ReadPartially(uint64_t addr, void* dst, size_t size) = 0;
virtual size_t Read(uint64_t addr, void* dst, size_t size) = 0;
bool ReadFully(uint64_t addr, void* dst, size_t size);
@ -66,7 +66,7 @@ class MemoryBuffer : public Memory {
MemoryBuffer() = default;
virtual ~MemoryBuffer() = default;
size_t ReadPartially(uint64_t addr, void* dst, size_t size) override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
uint8_t* GetPtr(size_t offset);
@ -85,7 +85,7 @@ class MemoryFileAtOffset : public Memory {
bool Init(const std::string& file, uint64_t offset, uint64_t size = UINT64_MAX);
size_t ReadPartially(uint64_t addr, void* dst, size_t size) override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
size_t Size() { return size_; }
@ -102,7 +102,7 @@ class MemoryRemote : public Memory {
MemoryRemote(pid_t pid) : pid_(pid) {}
virtual ~MemoryRemote() = default;
size_t ReadPartially(uint64_t addr, void* dst, size_t size) override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
pid_t pid() { return pid_; }
@ -115,7 +115,7 @@ class MemoryLocal : public Memory {
MemoryLocal() = default;
virtual ~MemoryLocal() = default;
size_t ReadPartially(uint64_t addr, void* dst, size_t size) override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
};
// MemoryRange maps one address range onto another.
@ -127,7 +127,7 @@ class MemoryRange : public Memory {
uint64_t offset);
virtual ~MemoryRange() = default;
size_t ReadPartially(uint64_t addr, void* dst, size_t size) override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
private:
std::shared_ptr<Memory> memory_;
@ -143,7 +143,7 @@ class MemoryOffline : public Memory {
bool Init(const std::string& file, uint64_t offset);
size_t ReadPartially(uint64_t addr, void* dst, size_t size) override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
private:
std::unique_ptr<MemoryRange> memory_;

View File

@ -78,7 +78,7 @@ TEST_F(MemoryBufferTest, read_failure_overflow) {
ASSERT_FALSE(memory_->ReadFully(UINT64_MAX - 100, buffer.data(), 200));
}
TEST_F(MemoryBufferTest, ReadPartially) {
TEST_F(MemoryBufferTest, Read) {
memory_->Resize(256);
ASSERT_EQ(256U, memory_->Size());
ASSERT_TRUE(memory_->GetPtr(0) != nullptr);
@ -92,7 +92,7 @@ TEST_F(MemoryBufferTest, ReadPartially) {
}
std::vector<uint8_t> buffer(memory_->Size());
ASSERT_EQ(128U, memory_->ReadPartially(128, buffer.data(), buffer.size()));
ASSERT_EQ(128U, memory_->Read(128, buffer.data(), buffer.size()));
for (size_t i = 0; i < 128; i++) {
ASSERT_EQ(128 + i, buffer[i]) << "Failed at byte " << i;
}

View File

@ -35,7 +35,7 @@ void MemoryFake::SetMemory(uint64_t addr, const void* memory, size_t length) {
}
}
size_t MemoryFake::ReadPartially(uint64_t addr, void* memory, size_t size) {
size_t MemoryFake::Read(uint64_t addr, void* memory, size_t size) {
uint8_t* dst = reinterpret_cast<uint8_t*>(memory);
for (size_t i = 0; i < size; i++, addr++) {
auto value = data_.find(addr);

View File

@ -32,7 +32,7 @@ class MemoryFake : public Memory {
MemoryFake() = default;
virtual ~MemoryFake() = default;
size_t ReadPartially(uint64_t addr, void* buffer, size_t size) override;
size_t Read(uint64_t addr, void* buffer, size_t size) override;
void SetMemory(uint64_t addr, const void* memory, size_t length);
@ -71,7 +71,7 @@ class MemoryFakeAlwaysReadZero : public Memory {
MemoryFakeAlwaysReadZero() = default;
virtual ~MemoryFakeAlwaysReadZero() = default;
size_t ReadPartially(uint64_t, void* buffer, size_t size) override {
size_t Read(uint64_t, void* buffer, size_t size) override {
memset(buffer, 0, size);
return size;
}

View File

@ -68,7 +68,7 @@ TEST(MemoryLocalTest, read_overflow) {
ASSERT_FALSE(local.ReadFully(reinterpret_cast<uint64_t>(&value), dst.data(), SIZE_MAX));
}
TEST(MemoryLocalTest, ReadPartially) {
TEST(MemoryLocalTest, Read) {
char* mapping = static_cast<char*>(
mmap(nullptr, 2 * getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
@ -80,8 +80,8 @@ TEST(MemoryLocalTest, ReadPartially) {
MemoryLocal local;
std::vector<uint8_t> dst(4096);
ASSERT_EQ(1024U, local.ReadPartially(reinterpret_cast<uint64_t>(mapping + getpagesize() - 1024),
dst.data(), 4096));
ASSERT_EQ(1024U, local.Read(reinterpret_cast<uint64_t>(mapping + getpagesize() - 1024),
dst.data(), 4096));
for (size_t i = 0; i < 1024; i++) {
ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
}
@ -98,7 +98,7 @@ TEST(MemoryLocalTest, read_hole) {
MemoryLocal local;
std::vector<uint8_t> dst(4096 * 3, 0xCC);
ASSERT_EQ(4096U, local.ReadPartially(reinterpret_cast<uintptr_t>(mapping), dst.data(), 4096 * 3));
ASSERT_EQ(4096U, local.Read(reinterpret_cast<uintptr_t>(mapping), dst.data(), 4096 * 3));
for (size_t i = 0; i < 4096; ++i) {
ASSERT_EQ(0xFF, dst[i]);
}

View File

@ -76,7 +76,7 @@ TEST(MemoryRangeTest, read_overflow) {
ASSERT_FALSE(overflow->ReadFully(UINT64_MAX - 10, buffer.data(), 100));
}
TEST(MemoryRangeTest, ReadPartially) {
TEST(MemoryRangeTest, Read) {
std::vector<uint8_t> src(4096);
memset(src.data(), 0x4c, 4096);
MemoryFake* memory_fake = new MemoryFake;
@ -85,7 +85,7 @@ TEST(MemoryRangeTest, ReadPartially) {
MemoryRange range(process_memory, 1000, 1024, 0);
std::vector<uint8_t> dst(1024);
ASSERT_EQ(4U, range.ReadPartially(1020, dst.data(), 1024));
ASSERT_EQ(4U, range.Read(1020, dst.data(), 1024));
for (size_t i = 0; i < 4; i++) {
ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
}

View File

@ -79,7 +79,7 @@ TEST_F(MemoryRemoteTest, read) {
ASSERT_TRUE(Detach(pid));
}
TEST_F(MemoryRemoteTest, ReadPartially) {
TEST_F(MemoryRemoteTest, Read) {
char* mapping = static_cast<char*>(
mmap(nullptr, 2 * getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
@ -102,8 +102,8 @@ TEST_F(MemoryRemoteTest, ReadPartially) {
MemoryRemote remote(pid);
std::vector<uint8_t> dst(4096);
ASSERT_EQ(1024U, remote.ReadPartially(reinterpret_cast<uint64_t>(mapping + getpagesize() - 1024),
dst.data(), 4096));
ASSERT_EQ(1024U, remote.Read(reinterpret_cast<uint64_t>(mapping + getpagesize() - 1024),
dst.data(), 4096));
for (size_t i = 0; i < 1024; i++) {
ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
}
@ -211,7 +211,7 @@ TEST_F(MemoryRemoteTest, read_hole) {
MemoryRemote remote(pid);
std::vector<uint8_t> dst(4096 * 3, 0xCC);
ASSERT_EQ(4096U, remote.ReadPartially(reinterpret_cast<uintptr_t>(mapping), dst.data(), 4096 * 3));
ASSERT_EQ(4096U, remote.Read(reinterpret_cast<uintptr_t>(mapping), dst.data(), 4096 * 3));
for (size_t i = 0; i < 4096; ++i) {
ASSERT_EQ(0xFF, dst[i]);
}