Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <elf.h> |
| 18 | #include <string.h> |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <gtest/gtest.h> |
| 24 | |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 25 | #include <unwindstack/Elf.h> |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 26 | #include <unwindstack/JitDebug.h> |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 27 | #include <unwindstack/MapInfo.h> |
| 28 | #include <unwindstack/Maps.h> |
| 29 | #include <unwindstack/Memory.h> |
| 30 | |
| 31 | #include "DexFileData.h" |
| 32 | #include "ElfFake.h" |
| 33 | #include "MemoryFake.h" |
| 34 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 35 | #if !defined(NO_LIBDEXFILE_SUPPORT) |
| 36 | #include <DexFile.h> |
| 37 | #endif |
| 38 | |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 39 | namespace unwindstack { |
| 40 | |
| 41 | class DexFilesTest : public ::testing::Test { |
| 42 | protected: |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 43 | void CreateFakeElf(MapInfo* map_info) { |
| 44 | MemoryFake* memory = new MemoryFake; |
| 45 | ElfFake* elf = new ElfFake(memory); |
| 46 | elf->FakeSetValid(true); |
| 47 | ElfInterfaceFake* interface = new ElfInterfaceFake(memory); |
| 48 | elf->FakeSetInterface(interface); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 49 | |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 50 | interface->FakeSetGlobalVariable("__dex_debug_descriptor", 0x800); |
| 51 | map_info->elf.reset(elf); |
| 52 | } |
| 53 | |
| 54 | void Init(ArchEnum arch) { |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 55 | dex_files_ = JitDebug<DexFile>::Create(arch, process_memory_); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 56 | |
| 57 | maps_.reset( |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 58 | new BufferMaps("1000-4000 ---s 00000000 00:00 0 /fake/elf\n" |
| 59 | "4000-6000 r--s 00000000 00:00 0 /fake/elf\n" |
| 60 | "6000-8000 -wxs 00000000 00:00 0 /fake/elf\n" |
| 61 | "a000-c000 r--p 00000000 00:00 0 /fake/elf2\n" |
| 62 | "c000-f000 rw-p 00001000 00:00 0 /fake/elf2\n" |
| 63 | "f000-11000 r--p 00000000 00:00 0 /fake/elf3\n" |
| 64 | "100000-110000 rw-p 0001000 00:00 0 /fake/elf3\n" |
| 65 | "200000-210000 rw-p 0002000 00:00 0 /fake/elf3\n" |
| 66 | "300000-400000 rw-p 0003000 00:00 0 /fake/elf3\n")); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 67 | ASSERT_TRUE(maps_->Parse()); |
| 68 | |
Christopher Ferris | 1f34c0e | 2018-10-08 17:39:39 -0700 | [diff] [blame] | 69 | // Global variable in a section that is not readable. |
| 70 | MapInfo* map_info = maps_->Get(kMapGlobalNonReadable); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 71 | ASSERT_TRUE(map_info != nullptr); |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 72 | CreateFakeElf(map_info); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 73 | |
| 74 | // Global variable not set by default. |
| 75 | map_info = maps_->Get(kMapGlobalSetToZero); |
| 76 | ASSERT_TRUE(map_info != nullptr); |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 77 | CreateFakeElf(map_info); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 78 | |
| 79 | // Global variable set in this map. |
| 80 | map_info = maps_->Get(kMapGlobal); |
| 81 | ASSERT_TRUE(map_info != nullptr); |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 82 | CreateFakeElf(map_info); |
| 83 | } |
| 84 | |
| 85 | void SetUp() override { |
| 86 | memory_ = new MemoryFake; |
| 87 | process_memory_.reset(memory_); |
| 88 | |
| 89 | Init(ARCH_ARM); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 90 | } |
| 91 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 92 | void WriteDescriptor32(uint64_t addr, uint32_t entry); |
| 93 | void WriteDescriptor64(uint64_t addr, uint64_t entry); |
| 94 | void WriteEntry32Pack(uint64_t addr, uint32_t next, uint32_t prev, uint32_t dex); |
| 95 | void WriteEntry32Pad(uint64_t addr, uint32_t next, uint32_t prev, uint32_t dex); |
| 96 | void WriteEntry64(uint64_t addr, uint64_t next, uint64_t prev, uint64_t dex); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 97 | void WriteDex(uint64_t dex_file); |
| 98 | |
Christopher Ferris | 1f34c0e | 2018-10-08 17:39:39 -0700 | [diff] [blame] | 99 | static constexpr size_t kMapGlobalNonReadable = 2; |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 100 | static constexpr size_t kMapGlobalSetToZero = 3; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 101 | static constexpr size_t kMapGlobal = 5; |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 102 | static constexpr size_t kMapGlobalRw = 6; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 103 | static constexpr size_t kMapDexFileEntries = 7; |
| 104 | static constexpr size_t kMapDexFiles = 8; |
| 105 | |
| 106 | std::shared_ptr<Memory> process_memory_; |
| 107 | MemoryFake* memory_; |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 108 | std::unique_ptr<JitDebug<DexFile>> dex_files_; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 109 | std::unique_ptr<BufferMaps> maps_; |
| 110 | }; |
| 111 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 112 | void DexFilesTest::WriteDescriptor32(uint64_t addr, uint32_t entry) { |
| 113 | // Format of the 32 bit JITDescriptor structure: |
| 114 | // uint32_t version |
| 115 | memory_->SetData32(addr, 1); |
| 116 | // uint32_t action_flag |
| 117 | memory_->SetData32(addr + 4, 0); |
| 118 | // uint32_t relevant_entry |
| 119 | memory_->SetData32(addr + 8, 0); |
| 120 | // uint32_t first_entry |
| 121 | memory_->SetData32(addr + 12, entry); |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 122 | } |
| 123 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 124 | void DexFilesTest::WriteDescriptor64(uint64_t addr, uint64_t entry) { |
| 125 | // Format of the 64 bit JITDescriptor structure: |
| 126 | // uint32_t version |
| 127 | memory_->SetData32(addr, 1); |
| 128 | // uint32_t action_flag |
| 129 | memory_->SetData32(addr + 4, 0); |
| 130 | // uint64_t relevant_entry |
| 131 | memory_->SetData64(addr + 8, 0); |
| 132 | // uint64_t first_entry |
| 133 | memory_->SetData64(addr + 16, entry); |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 134 | } |
| 135 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 136 | void DexFilesTest::WriteEntry32Pack(uint64_t addr, uint32_t next, uint32_t prev, uint32_t dex) { |
| 137 | // Format of the 32 bit JITCodeEntry structure: |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 138 | // uint32_t next |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 139 | memory_->SetData32(addr, next); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 140 | // uint32_t prev |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 141 | memory_->SetData32(addr + 4, prev); |
| 142 | // uint32_t dex |
| 143 | memory_->SetData32(addr + 8, dex); |
| 144 | // uint64_t symfile_size |
| 145 | memory_->SetData64(addr + 12, sizeof(kDexData) * sizeof(uint32_t)); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 146 | } |
| 147 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 148 | void DexFilesTest::WriteEntry32Pad(uint64_t addr, uint32_t next, uint32_t prev, uint32_t dex) { |
| 149 | // Format of the 32 bit JITCodeEntry structure: |
| 150 | // uint32_t next |
| 151 | memory_->SetData32(addr, next); |
| 152 | // uint32_t prev |
| 153 | memory_->SetData32(addr + 4, prev); |
| 154 | // uint32_t dex |
| 155 | memory_->SetData32(addr + 8, dex); |
| 156 | // uint32_t pad |
| 157 | memory_->SetData32(addr + 12, 0); |
| 158 | // uint64_t symfile_size |
| 159 | memory_->SetData64(addr + 16, sizeof(kDexData) * sizeof(uint32_t)); |
| 160 | } |
| 161 | |
| 162 | void DexFilesTest::WriteEntry64(uint64_t addr, uint64_t next, uint64_t prev, uint64_t dex) { |
| 163 | // Format of the 64 bit JITCodeEntry structure: |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 164 | // uint64_t next |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 165 | memory_->SetData64(addr, next); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 166 | // uint64_t prev |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 167 | memory_->SetData64(addr + 8, prev); |
| 168 | // uint64_t dex |
| 169 | memory_->SetData64(addr + 16, dex); |
| 170 | // uint64_t symfile_size |
| 171 | memory_->SetData64(addr + 24, sizeof(kDexData) * sizeof(uint32_t)); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void DexFilesTest::WriteDex(uint64_t dex_file) { |
| 175 | memory_->SetMemory(dex_file, kDexData, sizeof(kDexData) * sizeof(uint32_t)); |
| 176 | } |
| 177 | |
| 178 | TEST_F(DexFilesTest, get_method_information_invalid) { |
| 179 | std::string method_name = "nothing"; |
| 180 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 181 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 182 | dex_files_->GetFunctionName(maps_.get(), 0, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 183 | EXPECT_EQ("nothing", method_name); |
| 184 | EXPECT_EQ(0x124U, method_offset); |
| 185 | } |
| 186 | |
| 187 | TEST_F(DexFilesTest, get_method_information_32) { |
| 188 | std::string method_name = "nothing"; |
| 189 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 190 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 191 | WriteDescriptor32(0xf800, 0x200000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 192 | WriteEntry32Pad(0x200000, 0, 0, 0x300000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 193 | WriteDex(0x300000); |
| 194 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 195 | dex_files_->GetFunctionName(maps_.get(), 0x300100, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 196 | EXPECT_EQ("Main.<init>", method_name); |
| 197 | EXPECT_EQ(0U, method_offset); |
| 198 | } |
| 199 | |
| 200 | TEST_F(DexFilesTest, get_method_information_64) { |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 201 | Init(ARCH_ARM64); |
| 202 | |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 203 | std::string method_name = "nothing"; |
| 204 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 205 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 206 | WriteDescriptor64(0xf800, 0x200000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 207 | WriteEntry64(0x200000, 0, 0, 0x301000); |
| 208 | WriteDex(0x301000); |
| 209 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 210 | dex_files_->GetFunctionName(maps_.get(), 0x301102, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 211 | EXPECT_EQ("Main.<init>", method_name); |
| 212 | EXPECT_EQ(2U, method_offset); |
| 213 | } |
| 214 | |
| 215 | TEST_F(DexFilesTest, get_method_information_not_first_entry_32) { |
| 216 | std::string method_name = "nothing"; |
| 217 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 218 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 219 | WriteDescriptor32(0xf800, 0x200000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 220 | WriteEntry32Pad(0x200000, 0x200100, 0, 0x100000); |
| 221 | WriteDex(0x100000); |
| 222 | WriteEntry32Pad(0x200100, 0, 0x200000, 0x300000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 223 | WriteDex(0x300000); |
| 224 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 225 | dex_files_->GetFunctionName(maps_.get(), 0x300104, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 226 | EXPECT_EQ("Main.<init>", method_name); |
| 227 | EXPECT_EQ(4U, method_offset); |
| 228 | } |
| 229 | |
| 230 | TEST_F(DexFilesTest, get_method_information_not_first_entry_64) { |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 231 | Init(ARCH_ARM64); |
| 232 | |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 233 | std::string method_name = "nothing"; |
| 234 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 235 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 236 | WriteDescriptor64(0xf800, 0x200000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 237 | WriteEntry64(0x200000, 0x200100, 0, 0x100000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 238 | WriteDex(0x100000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 239 | WriteEntry64(0x200100, 0, 0x200000, 0x300000); |
| 240 | WriteDex(0x300000); |
| 241 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 242 | dex_files_->GetFunctionName(maps_.get(), 0x300106, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 243 | EXPECT_EQ("Main.<init>", method_name); |
| 244 | EXPECT_EQ(6U, method_offset); |
| 245 | } |
| 246 | |
| 247 | TEST_F(DexFilesTest, get_method_information_cached) { |
| 248 | std::string method_name = "nothing"; |
| 249 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 250 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 251 | WriteDescriptor32(0xf800, 0x200000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 252 | WriteEntry32Pad(0x200000, 0, 0, 0x300000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 253 | WriteDex(0x300000); |
| 254 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 255 | dex_files_->GetFunctionName(maps_.get(), 0x300100, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 256 | EXPECT_EQ("Main.<init>", method_name); |
| 257 | EXPECT_EQ(0U, method_offset); |
| 258 | |
| 259 | // Clear all memory and make sure that data is acquired from the cache. |
| 260 | memory_->Clear(); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 261 | dex_files_->GetFunctionName(maps_.get(), 0x300100, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 262 | EXPECT_EQ("Main.<init>", method_name); |
| 263 | EXPECT_EQ(0U, method_offset); |
| 264 | } |
| 265 | |
| 266 | TEST_F(DexFilesTest, get_method_information_search_libs) { |
| 267 | std::string method_name = "nothing"; |
| 268 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 269 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 270 | WriteDescriptor32(0xf800, 0x200000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 271 | WriteEntry32Pad(0x200000, 0x200100, 0, 0x100000); |
| 272 | WriteDex(0x100000); |
| 273 | WriteEntry32Pad(0x200100, 0, 0x200000, 0x300000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 274 | WriteDex(0x300000); |
| 275 | |
| 276 | // Only search a given named list of libs. |
| 277 | std::vector<std::string> libs{"libart.so"}; |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 278 | dex_files_ = JitDebug<DexFile>::Create(ARCH_ARM, process_memory_, libs); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 279 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 280 | dex_files_->GetFunctionName(maps_.get(), 0x300104, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 281 | EXPECT_EQ("nothing", method_name); |
| 282 | EXPECT_EQ(0x124U, method_offset); |
| 283 | |
| 284 | MapInfo* map_info = maps_->Get(kMapGlobal); |
| 285 | map_info->name = "/system/lib/libart.so"; |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 286 | dex_files_ = JitDebug<DexFile>::Create(ARCH_ARM, process_memory_, libs); |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 287 | // Set the rw map to the same name or this will not scan this entry. |
| 288 | map_info = maps_->Get(kMapGlobalRw); |
| 289 | map_info->name = "/system/lib/libart.so"; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 290 | // Make sure that clearing out copy of the libs doesn't affect the |
| 291 | // DexFiles object. |
| 292 | libs.clear(); |
| 293 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 294 | dex_files_->GetFunctionName(maps_.get(), 0x300104, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 295 | EXPECT_EQ("Main.<init>", method_name); |
| 296 | EXPECT_EQ(4U, method_offset); |
| 297 | } |
| 298 | |
| 299 | TEST_F(DexFilesTest, get_method_information_global_skip_zero_32) { |
| 300 | std::string method_name = "nothing"; |
| 301 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 302 | |
| 303 | // First global variable found, but value is zero. |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 304 | WriteDescriptor32(0xa800, 0); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 305 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 306 | WriteDescriptor32(0xf800, 0x200000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 307 | WriteEntry32Pad(0x200000, 0, 0, 0x300000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 308 | WriteDex(0x300000); |
| 309 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 310 | dex_files_->GetFunctionName(maps_.get(), 0x300100, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 311 | EXPECT_EQ("Main.<init>", method_name); |
| 312 | EXPECT_EQ(0U, method_offset); |
| 313 | |
| 314 | // Verify that second is ignored when first is set to non-zero |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 315 | dex_files_ = JitDebug<DexFile>::Create(ARCH_ARM, process_memory_); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 316 | method_name = "fail"; |
| 317 | method_offset = 0x123; |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 318 | WriteDescriptor32(0xa800, 0x100000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 319 | dex_files_->GetFunctionName(maps_.get(), 0x300100, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 320 | EXPECT_EQ("fail", method_name); |
| 321 | EXPECT_EQ(0x123U, method_offset); |
| 322 | } |
| 323 | |
| 324 | TEST_F(DexFilesTest, get_method_information_global_skip_zero_64) { |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 325 | Init(ARCH_ARM64); |
| 326 | |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 327 | std::string method_name = "nothing"; |
| 328 | uint64_t method_offset = 0x124; |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 329 | |
| 330 | // First global variable found, but value is zero. |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 331 | WriteDescriptor64(0xa800, 0); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 332 | |
David Srbecky | 4015ef4 | 2018-02-15 17:57:16 +0000 | [diff] [blame] | 333 | WriteDescriptor64(0xf800, 0x200000); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 334 | WriteEntry64(0x200000, 0, 0, 0x300000); |
| 335 | WriteDex(0x300000); |
| 336 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 337 | dex_files_->GetFunctionName(maps_.get(), 0x300100, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 338 | EXPECT_EQ("Main.<init>", method_name); |
| 339 | EXPECT_EQ(0U, method_offset); |
| 340 | |
| 341 | // Verify that second is ignored when first is set to non-zero |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 342 | dex_files_ = JitDebug<DexFile>::Create(ARCH_ARM64, process_memory_); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 343 | method_name = "fail"; |
| 344 | method_offset = 0x123; |
Christopher Ferris | 56d0e07 | 2018-10-17 10:57:53 -0700 | [diff] [blame] | 345 | WriteDescriptor64(0xa800, 0x100000); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame^] | 346 | dex_files_->GetFunctionName(maps_.get(), 0x300100, &method_name, &method_offset); |
Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 347 | EXPECT_EQ("fail", method_name); |
| 348 | EXPECT_EQ(0x123U, method_offset); |
| 349 | } |
| 350 | |
| 351 | } // namespace unwindstack |