Revert "Check for data races when reading JIT/DEX entries."
This reverts commit 85b5fecec920208ec43b42488f08d4c2e5aaeda2.
Reason for revert: Breaks ART tests, reverting to investigate.
Change-Id: I1bb905407e87cbd4f832646651133a9caf6fcfc8
diff --git a/libunwindstack/tests/JitDebugTest.cpp b/libunwindstack/tests/JitDebugTest.cpp
index 438194a..b1ca111 100644
--- a/libunwindstack/tests/JitDebugTest.cpp
+++ b/libunwindstack/tests/JitDebugTest.cpp
@@ -46,7 +46,8 @@
}
void Init(ArchEnum arch) {
- jit_debug_ = JitDebug<Elf>::Create(arch, process_memory_);
+ jit_debug_.reset(new JitDebug(process_memory_));
+ jit_debug_->SetArch(arch);
maps_.reset(
new BufferMaps("1000-4000 ---s 00000000 00:00 0 /fake/elf1\n"
@@ -61,12 +62,6 @@
"200000-210000 rw-p 0002000 00:00 0 /fake/elf4\n"));
ASSERT_TRUE(maps_->Parse());
- // Ensure all memory of the ELF file is initialized,
- // otherwise reads within it may fail.
- for (uint64_t addr = 0x4000; addr < 0x6000; addr += 8) {
- memory_->SetData64(addr, 0);
- }
-
MapInfo* map_info = maps_->Get(3);
ASSERT_TRUE(map_info != nullptr);
CreateFakeElf(map_info);
@@ -99,7 +94,7 @@
ehdr.e_shstrndx = 1;
ehdr.e_shoff = sh_offset;
ehdr.e_shentsize = sizeof(ShdrType);
- ehdr.e_shnum = 4;
+ ehdr.e_shnum = 3;
memory_->SetMemory(offset, &ehdr, sizeof(ehdr));
ShdrType shdr;
@@ -115,7 +110,6 @@
shdr.sh_size = 0x100;
memory_->SetMemory(offset + sh_offset, &shdr, sizeof(shdr));
memory_->SetMemory(offset + 0x500, ".debug_frame");
- memory_->SetMemory(offset + 0x550, ".text");
sh_offset += sizeof(shdr);
memset(&shdr, 0, sizeof(shdr));
@@ -126,15 +120,6 @@
shdr.sh_size = 0x200;
memory_->SetMemory(offset + sh_offset, &shdr, sizeof(shdr));
- sh_offset += sizeof(shdr);
- memset(&shdr, 0, sizeof(shdr));
- shdr.sh_type = SHT_NOBITS;
- shdr.sh_name = 0x50;
- shdr.sh_addr = pc;
- shdr.sh_offset = 0;
- shdr.sh_size = size;
- memory_->SetMemory(offset + sh_offset, &shdr, sizeof(shdr));
-
// Now add a single cie/fde.
uint64_t dwarf_offset = offset + 0x600;
if (class_type == ELFCLASS32) {
@@ -183,7 +168,7 @@
std::shared_ptr<Memory> process_memory_;
MemoryFake* memory_;
- std::unique_ptr<JitDebug<Elf>> jit_debug_;
+ std::unique_ptr<JitDebug> jit_debug_;
std::unique_ptr<BufferMaps> maps_;
};
@@ -253,20 +238,20 @@
}
TEST_F(JitDebugTest, get_elf_invalid) {
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf == nullptr);
}
TEST_F(JitDebugTest, get_elf_no_global_variable) {
maps_.reset(new BufferMaps(""));
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf == nullptr);
}
TEST_F(JitDebugTest, get_elf_no_valid_descriptor_in_memory) {
CreateElf<Elf32_Ehdr, Elf32_Shdr>(0x4000, ELFCLASS32, EM_ARM, 0x1500, 0x200);
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf == nullptr);
}
@@ -275,7 +260,7 @@
WriteDescriptor32(0xf800, 0x200000);
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf == nullptr);
}
@@ -284,7 +269,7 @@
WriteDescriptor32(0xf800, 0);
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf == nullptr);
}
@@ -295,7 +280,7 @@
// Set the version to an invalid value.
memory_->SetData32(0xf800, 2);
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf == nullptr);
}
@@ -305,18 +290,12 @@
WriteDescriptor32(0xf800, 0x200000);
WriteEntry32Pad(0x200000, 0, 0, 0x4000, 0x1000);
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf != nullptr);
- uint64_t text_addr;
- uint64_t text_size;
- ASSERT_TRUE(elf->GetTextRange(&text_addr, &text_size));
- ASSERT_EQ(text_addr, 0x1500u);
- ASSERT_EQ(text_size, 0x200u);
// Clear the memory and verify all of the data is cached.
memory_->Clear();
- WriteDescriptor32(0xf800, 0x200000);
- Elf* elf2 = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf2 = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf2 != nullptr);
EXPECT_EQ(elf, elf2);
}
@@ -330,15 +309,16 @@
WriteDescriptor32(0x12800, 0x201000);
WriteEntry32Pad(0x201000, 0, 0, 0x5000, 0x1000);
- ASSERT_TRUE(jit_debug_->Get(maps_.get(), 0x1500) != nullptr);
- ASSERT_TRUE(jit_debug_->Get(maps_.get(), 0x2000) == nullptr);
+ ASSERT_TRUE(jit_debug_->GetElf(maps_.get(), 0x1500) != nullptr);
+ ASSERT_TRUE(jit_debug_->GetElf(maps_.get(), 0x2000) == nullptr);
// Now clear the descriptor entry for the first one.
WriteDescriptor32(0xf800, 0);
- jit_debug_ = JitDebug<Elf>::Create(ARCH_ARM, process_memory_);
+ jit_debug_.reset(new JitDebug(process_memory_));
+ jit_debug_->SetArch(ARCH_ARM);
- ASSERT_TRUE(jit_debug_->Get(maps_.get(), 0x1500) == nullptr);
- ASSERT_TRUE(jit_debug_->Get(maps_.get(), 0x2000) != nullptr);
+ ASSERT_TRUE(jit_debug_->GetElf(maps_.get(), 0x1500) == nullptr);
+ ASSERT_TRUE(jit_debug_->GetElf(maps_.get(), 0x2000) != nullptr);
}
TEST_F(JitDebugTest, get_elf_x86) {
@@ -349,14 +329,13 @@
WriteDescriptor32(0xf800, 0x200000);
WriteEntry32Pack(0x200000, 0, 0, 0x4000, 0x1000);
- jit_debug_ = JitDebug<Elf>::Create(ARCH_X86, process_memory_);
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ jit_debug_->SetArch(ARCH_X86);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf != nullptr);
// Clear the memory and verify all of the data is cached.
memory_->Clear();
- WriteDescriptor32(0xf800, 0x200000);
- Elf* elf2 = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf2 = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf2 != nullptr);
EXPECT_EQ(elf, elf2);
}
@@ -369,13 +348,12 @@
WriteDescriptor64(0xf800, 0x200000);
WriteEntry64(0x200000, 0, 0, 0x4000, 0x1000);
- Elf* elf = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf != nullptr);
// Clear the memory and verify all of the data is cached.
memory_->Clear();
- WriteDescriptor64(0xf800, 0x200000);
- Elf* elf2 = jit_debug_->Get(maps_.get(), 0x1500);
+ Elf* elf2 = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf2 != nullptr);
EXPECT_EQ(elf, elf2);
}
@@ -388,21 +366,20 @@
WriteEntry32Pad(0x200000, 0, 0x200100, 0x4000, 0x1000);
WriteEntry32Pad(0x200100, 0x200100, 0, 0x5000, 0x1000);
- Elf* elf_2 = jit_debug_->Get(maps_.get(), 0x2400);
+ Elf* elf_2 = jit_debug_->GetElf(maps_.get(), 0x2400);
ASSERT_TRUE(elf_2 != nullptr);
- Elf* elf_1 = jit_debug_->Get(maps_.get(), 0x1600);
+ Elf* elf_1 = jit_debug_->GetElf(maps_.get(), 0x1600);
ASSERT_TRUE(elf_1 != nullptr);
// Clear the memory and verify all of the data is cached.
memory_->Clear();
- WriteDescriptor32(0xf800, 0x200000);
- EXPECT_EQ(elf_1, jit_debug_->Get(maps_.get(), 0x1500));
- EXPECT_EQ(elf_1, jit_debug_->Get(maps_.get(), 0x16ff));
- EXPECT_EQ(elf_2, jit_debug_->Get(maps_.get(), 0x2300));
- EXPECT_EQ(elf_2, jit_debug_->Get(maps_.get(), 0x26ff));
- EXPECT_EQ(nullptr, jit_debug_->Get(maps_.get(), 0x1700));
- EXPECT_EQ(nullptr, jit_debug_->Get(maps_.get(), 0x2700));
+ EXPECT_EQ(elf_1, jit_debug_->GetElf(maps_.get(), 0x1500));
+ EXPECT_EQ(elf_1, jit_debug_->GetElf(maps_.get(), 0x16ff));
+ EXPECT_EQ(elf_2, jit_debug_->GetElf(maps_.get(), 0x2300));
+ EXPECT_EQ(elf_2, jit_debug_->GetElf(maps_.get(), 0x26ff));
+ EXPECT_EQ(nullptr, jit_debug_->GetElf(maps_.get(), 0x1700));
+ EXPECT_EQ(nullptr, jit_debug_->GetElf(maps_.get(), 0x2700));
}
TEST_F(JitDebugTest, get_elf_search_libs) {
@@ -413,19 +390,21 @@
// Only search a given named list of libs.
std::vector<std::string> libs{"libart.so"};
- jit_debug_ = JitDebug<Elf>::Create(ARCH_ARM, process_memory_, libs);
- EXPECT_TRUE(jit_debug_->Get(maps_.get(), 0x1500) == nullptr);
+ jit_debug_.reset(new JitDebug(process_memory_, libs));
+ jit_debug_->SetArch(ARCH_ARM);
+ EXPECT_TRUE(jit_debug_->GetElf(maps_.get(), 0x1500) == nullptr);
// Change the name of the map that includes the value and verify this works.
MapInfo* map_info = maps_->Get(5);
map_info->name = "/system/lib/libart.so";
map_info = maps_->Get(6);
map_info->name = "/system/lib/libart.so";
- jit_debug_ = JitDebug<Elf>::Create(ARCH_ARM, process_memory_);
+ jit_debug_.reset(new JitDebug(process_memory_, libs));
// Make sure that clearing our copy of the libs doesn't affect the
// JitDebug object.
libs.clear();
- EXPECT_TRUE(jit_debug_->Get(maps_.get(), 0x1500) != nullptr);
+ jit_debug_->SetArch(ARCH_ARM);
+ EXPECT_TRUE(jit_debug_->GetElf(maps_.get(), 0x1500) != nullptr);
}
} // namespace unwindstack