From 3dfd2aea7a28faa5240cb308b9cdcca8b4025f83 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 15 Dec 2017 20:00:59 -0800 Subject: Add tool to save information from a process. Also, modify the ProcessVmRead function to allow arbitrarily large reads and add a test for it. Test: Run tool and verify the output can be used to do an offline Test: unwind. Test: Ran unit tests. Change-Id: I0974ddca4f5cf72b4c9fa29b597a0a669e223828 --- libunwindstack/tests/MemoryRemoteTest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libunwindstack/tests/MemoryRemoteTest.cpp') diff --git a/libunwindstack/tests/MemoryRemoteTest.cpp b/libunwindstack/tests/MemoryRemoteTest.cpp index f5492a267..fb56e8afb 100644 --- a/libunwindstack/tests/MemoryRemoteTest.cpp +++ b/libunwindstack/tests/MemoryRemoteTest.cpp @@ -79,6 +79,35 @@ TEST_F(MemoryRemoteTest, read) { ASSERT_TRUE(Detach(pid)); } +TEST_F(MemoryRemoteTest, read_large) { + static constexpr size_t kTotalPages = 245; + std::vector src(kTotalPages * getpagesize()); + for (size_t i = 0; i < kTotalPages; i++) { + memset(&src[i * getpagesize()], i, getpagesize()); + } + + pid_t pid; + if ((pid = fork()) == 0) { + while (true) + ; + exit(1); + } + ASSERT_LT(0, pid); + TestScopedPidReaper reap(pid); + + ASSERT_TRUE(Attach(pid)); + + MemoryRemote remote(pid); + + std::vector dst(kTotalPages * getpagesize()); + ASSERT_TRUE(remote.ReadFully(reinterpret_cast(src.data()), dst.data(), src.size())); + for (size_t i = 0; i < kTotalPages * getpagesize(); i++) { + ASSERT_EQ(i / getpagesize(), dst[i]) << "Failed at byte " << i; + } + + ASSERT_TRUE(Detach(pid)); +} + TEST_F(MemoryRemoteTest, read_partial) { char* mapping = static_cast( mmap(nullptr, 4 * getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); -- cgit v1.2.3