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
diff --git a/libunwindstack/tests/MapInfoTest.cpp b/libunwindstack/tests/MapInfoTest.cpp
index ef76b1b..98edc0e 100644
--- a/libunwindstack/tests/MapInfoTest.cpp
+++ b/libunwindstack/tests/MapInfoTest.cpp
@@ -26,8 +26,8 @@
namespace unwindstack {
TEST(MapInfoTest, maps_constructor_const_char) {
- MapInfo prev_map(nullptr, 0, 0, 0, 0, "");
- MapInfo map_info(&prev_map, 1, 2, 3, 4, "map");
+ MapInfo prev_map(nullptr, nullptr, 0, 0, 0, 0, "");
+ MapInfo map_info(&prev_map, &prev_map, 1, 2, 3, 4, "map");
EXPECT_EQ(&prev_map, map_info.prev_map);
EXPECT_EQ(1UL, map_info.start);
@@ -42,8 +42,8 @@
TEST(MapInfoTest, maps_constructor_string) {
std::string name("string_map");
- MapInfo prev_map(nullptr, 0, 0, 0, 0, "");
- MapInfo map_info(&prev_map, 1, 2, 3, 4, name);
+ MapInfo prev_map(nullptr, nullptr, 0, 0, 0, 0, "");
+ MapInfo map_info(&prev_map, &prev_map, 1, 2, 3, 4, name);
EXPECT_EQ(&prev_map, map_info.prev_map);
EXPECT_EQ(1UL, map_info.start);
@@ -62,7 +62,7 @@
elf->FakeSetInterface(interface);
interface->FakePushFunctionData(FunctionData("function", 1000));
- MapInfo map_info(nullptr, 1, 2, 3, 4, "");
+ MapInfo map_info(nullptr, nullptr, 1, 2, 3, 4, "");
map_info.elf.reset(elf);
std::string name;