Add a method to share the process memory object.
New function to create the process memory object. This allows for
a future where different remote process memory objects could be created
depending on the way remote memory can be created. Even different local
memory objects that access memory without doing any checks.
It also allows MemoryRange objects to share one single process memory object
and could help if the process memory object caches data.
Small changes to MapInfo::CreateMemory to when some errors are detected.
- Always check if the map is a device map, instead of only if the name
is not empty.
- Check if a memory map is readable before creating the memory from process
memory.
Bug: 23762183
Test: Ran unit tests, unwound on device using the new code.
Change-Id: I12a93c2dc19639689a528ec41c67bfac74d431b3
diff --git a/libunwindstack/tests/UnwindTest.cpp b/libunwindstack/tests/UnwindTest.cpp
index 2fc3a38..a0c45bd 100644
--- a/libunwindstack/tests/UnwindTest.cpp
+++ b/libunwindstack/tests/UnwindTest.cpp
@@ -85,10 +85,11 @@
function_names[index] + "\n" + "Unwind data:\n" + unwind_stream.str();
}
-static void VerifyUnwind(pid_t pid, Memory* memory, Maps* maps, Regs* regs,
+static void VerifyUnwind(pid_t pid, Maps* maps, Regs* regs,
std::vector<const char*>& function_names) {
size_t function_name_index = 0;
+ auto process_memory = Memory::CreateProcessMemory(pid);
std::stringstream unwind_stream;
unwind_stream << std::hex;
for (size_t frame_num = 0; frame_num < 64; frame_num++) {
@@ -96,7 +97,7 @@
MapInfo* map_info = maps->Find(regs->pc());
ASSERT_TRUE(map_info != nullptr) << ErrorMsg(function_names, function_name_index, unwind_stream);
- Elf* elf = map_info->GetElf(pid, true);
+ Elf* elf = map_info->GetElf(process_memory, true);
uint64_t rel_pc = elf->GetRelPc(regs->pc(), map_info);
uint64_t adjusted_rel_pc = rel_pc;
if (frame_num != 0) {
@@ -122,7 +123,7 @@
unwind_stream << " " << name;
}
unwind_stream << "\n";
- ASSERT_TRUE(elf->Step(rel_pc + map_info->elf_offset, regs, memory))
+ ASSERT_TRUE(elf->Step(rel_pc + map_info->elf_offset, regs, process_memory.get()))
<< ErrorMsg(function_names, function_name_index, unwind_stream);
}
ASSERT_TRUE(false) << ErrorMsg(function_names, function_name_index, unwind_stream);
@@ -137,9 +138,8 @@
ASSERT_TRUE(maps.Parse());
std::unique_ptr<Regs> regs(Regs::CreateFromLocal());
RegsGetLocal(regs.get());
- MemoryLocal memory;
- VerifyUnwind(getpid(), &memory, &maps, regs.get(), kFunctionOrder);
+ VerifyUnwind(getpid(), &maps, regs.get(), kFunctionOrder);
} else {
g_ready_for_remote = true;
g_ready = true;
@@ -205,11 +205,10 @@
RemoteMaps maps(pid);
ASSERT_TRUE(maps.Parse());
- MemoryRemote memory(pid);
std::unique_ptr<Regs> regs(Regs::RemoteGet(pid));
ASSERT_TRUE(regs.get() != nullptr);
- VerifyUnwind(pid, &memory, &maps, regs.get(), kFunctionOrder);
+ VerifyUnwind(pid, &maps, regs.get(), kFunctionOrder);
ASSERT_EQ(0, ptrace(PTRACE_DETACH, pid, 0, 0));
@@ -254,9 +253,8 @@
LocalMaps maps;
ASSERT_TRUE(maps.Parse());
std::unique_ptr<Regs> regs(Regs::CreateFromUcontext(Regs::CurrentMachineType(), ucontext));
- MemoryLocal memory;
- VerifyUnwind(tid.load(), &memory, &maps, regs.get(), kFunctionOrder);
+ VerifyUnwind(getpid(), &maps, regs.get(), kFunctionOrder);
ASSERT_EQ(0, sigaction(SIGUSR1, &oldact, nullptr));
@@ -291,11 +289,10 @@
RemoteMaps maps(pid);
ASSERT_TRUE(maps.Parse());
- MemoryRemote memory(pid);
std::unique_ptr<Regs> regs(Regs::RemoteGet(pid));
ASSERT_TRUE(regs.get() != nullptr);
- VerifyUnwind(pid, &memory, &maps, regs.get(), kFunctionSignalOrder);
+ VerifyUnwind(pid, &maps, regs.get(), kFunctionSignalOrder);
ASSERT_EQ(0, ptrace(PTRACE_DETACH, pid, 0, 0));