summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/DexFileTest.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2020-01-22 12:17:06 -0800
committerChristopher Ferris <cferris@google.com>2020-01-22 18:30:12 -0800
commit0f40a0530976bc7fe2213944d69851821eb402c7 (patch)
tree515b7c5168a6b3e58e5c73ebea9f0a7db38922e5 /libunwindstack/tests/DexFileTest.cpp
parent929c9e8b40fe6adb23a140a8584d69edb2cab636 (diff)
Properly handle empty map after read-only map.
Recently, the maps for an elf in memory might show up looking like: f0000-f1000 0 r-- /system/lib/libc.so f1000-f2000 0 --- f2000-f3000 1000 r-x /system/lib/libc.so f3000-f4000 2000 rw- /system/lib/libc.so The problem is that there is logic in the code that assumed that the map before the execute map must be the read-only map. In the case above, this is not true. Add a new prev_real_map that will point to the previous map that is not one of these empty maps. This will fix the backtraces that look like this: #00 pc 0000000000050d58 /apex/com.android.runtime/lib64/bionic/libc.so!libc.so (offset 0x50000) (syscall+24) (BuildId: 5252408bf30e395d49ee270b54c77ca4) To get rid of the !libc.so and the offset value, which is not correct. Added new unit tests to verify this. Added new offline test which an empty map between read-only and execute map. Before this change, the backtraces had lines like libc.so!libc.so (offset XXX) would be present. Bug: 148075852 Test: Ran unit tests. Change-Id: Ie04bfc96b8f91ed885cb1e655cf1e346efe48a45
Diffstat (limited to 'libunwindstack/tests/DexFileTest.cpp')
-rw-r--r--libunwindstack/tests/DexFileTest.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/libunwindstack/tests/DexFileTest.cpp b/libunwindstack/tests/DexFileTest.cpp
index 0149a42c7..1b54da6fb 100644
--- a/libunwindstack/tests/DexFileTest.cpp
+++ b/libunwindstack/tests/DexFileTest.cpp
@@ -105,7 +105,7 @@ TEST(DexFileTest, create_using_file) {
static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
MemoryFake memory;
- MapInfo info(nullptr, 0, 0x10000, 0, 0x5, tf.path);
+ MapInfo info(nullptr, nullptr, 0, 0x10000, 0, 0x5, tf.path);
EXPECT_TRUE(DexFile::Create(0x500, &memory, &info) != nullptr);
}
@@ -118,7 +118,7 @@ TEST(DexFileTest, create_using_file_non_zero_start) {
static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
MemoryFake memory;
- MapInfo info(nullptr, 0x100, 0x10000, 0, 0x5, tf.path);
+ MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0, 0x5, tf.path);
EXPECT_TRUE(DexFile::Create(0x600, &memory, &info) != nullptr);
}
@@ -131,21 +131,21 @@ TEST(DexFileTest, create_using_file_non_zero_offset) {
static_cast<size_t>(TEMP_FAILURE_RETRY(write(tf.fd, kDexData, sizeof(kDexData)))));
MemoryFake memory;
- MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, tf.path);
+ MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0x200, 0x5, tf.path);
EXPECT_TRUE(DexFile::Create(0x400, &memory, &info) != nullptr);
}
TEST(DexFileTest, create_using_memory_empty_file) {
MemoryFake memory;
memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
- MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, "");
+ MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0x200, 0x5, "");
EXPECT_TRUE(DexFile::Create(0x4000, &memory, &info) != nullptr);
}
TEST(DexFileTest, create_using_memory_file_does_not_exist) {
MemoryFake memory;
memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
- MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, "/does/not/exist");
+ MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0x200, 0x5, "/does/not/exist");
EXPECT_TRUE(DexFile::Create(0x4000, &memory, &info) != nullptr);
}
@@ -158,7 +158,7 @@ TEST(DexFileTest, create_using_memory_file_is_malformed) {
MemoryFake memory;
memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
- MapInfo info(nullptr, 0x4000, 0x10000, 0x200, 0x5, "/does/not/exist");
+ MapInfo info(nullptr, nullptr, 0x4000, 0x10000, 0x200, 0x5, "/does/not/exist");
std::unique_ptr<DexFile> dex_file = DexFile::Create(0x4000, &memory, &info);
ASSERT_TRUE(dex_file != nullptr);
@@ -171,7 +171,7 @@ TEST(DexFileTest, create_using_memory_file_is_malformed) {
TEST(DexFileTest, get_method) {
MemoryFake memory;
memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
- MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, "");
+ MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0x200, 0x5, "");
std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, &memory, &info));
ASSERT_TRUE(dex_file != nullptr);
@@ -189,7 +189,7 @@ TEST(DexFileTest, get_method) {
TEST(DexFileTest, get_method_empty) {
MemoryFake memory;
memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
- MapInfo info(nullptr, 0x100, 0x10000, 0x200, 0x5, "");
+ MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0x200, 0x5, "");
std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, &memory, &info));
ASSERT_TRUE(dex_file != nullptr);