blob: 477cf8efe3694c6cd1e2668226e2d3a7ef4e3600 [file] [log] [blame]
Christopher Ferris7747b602018-01-31 19:05:19 -08001/*
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
David Srbeckyb9cc4fb2019-04-05 18:23:32 +000025#include <unwindstack/DexFiles.h>
Christopher Ferris7747b602018-01-31 19:05:19 -080026#include <unwindstack/Elf.h>
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
35namespace unwindstack {
36
37class DexFilesTest : public ::testing::Test {
38 protected:
Christopher Ferrisdf683b72019-12-03 17:13:49 -080039 void CreateFakeElf(MapInfo* map_info, uint64_t global_offset, uint64_t data_offset,
40 uint64_t data_vaddr, uint64_t data_size) {
Christopher Ferris4568f4b2018-10-23 17:42:41 -070041 MemoryFake* memory = new MemoryFake;
42 ElfFake* elf = new ElfFake(memory);
43 elf->FakeSetValid(true);
44 ElfInterfaceFake* interface = new ElfInterfaceFake(memory);
45 elf->FakeSetInterface(interface);
Christopher Ferris7747b602018-01-31 19:05:19 -080046
Christopher Ferrisdf683b72019-12-03 17:13:49 -080047 interface->FakeSetGlobalVariable("__dex_debug_descriptor", global_offset);
48 interface->FakeSetDataOffset(data_offset);
49 interface->FakeSetDataVaddrStart(data_vaddr);
50 interface->FakeSetDataVaddrEnd(data_vaddr + data_size);
Christopher Ferris4568f4b2018-10-23 17:42:41 -070051 map_info->elf.reset(elf);
52 }
53
54 void Init(ArchEnum arch) {
David Srbeckyb9cc4fb2019-04-05 18:23:32 +000055 dex_files_.reset(new DexFiles(process_memory_));
56 dex_files_->SetArch(arch);
Christopher Ferris7747b602018-01-31 19:05:19 -080057
58 maps_.reset(
Christopher Ferris56d0e072018-10-17 10:57:53 -070059 new BufferMaps("1000-4000 ---s 00000000 00:00 0 /fake/elf\n"
60 "4000-6000 r--s 00000000 00:00 0 /fake/elf\n"
Christopher Ferrisdf683b72019-12-03 17:13:49 -080061 "6000-8000 -wxs 00002000 00:00 0 /fake/elf\n"
Christopher Ferris56d0e072018-10-17 10:57:53 -070062 "a000-c000 r--p 00000000 00:00 0 /fake/elf2\n"
Christopher Ferrisdf683b72019-12-03 17:13:49 -080063 "c000-f000 rw-p 00002000 00:00 0 /fake/elf2\n"
Christopher Ferris56d0e072018-10-17 10:57:53 -070064 "f000-11000 r--p 00000000 00:00 0 /fake/elf3\n"
Christopher Ferrisdf683b72019-12-03 17:13:49 -080065 "100000-110000 rw-p 00f1000 00:00 0 /fake/elf3\n"
Christopher Ferris56d0e072018-10-17 10:57:53 -070066 "200000-210000 rw-p 0002000 00:00 0 /fake/elf3\n"
Christopher Ferrisde5cd8c2020-01-21 17:56:25 -080067 "300000-400000 rw-p 0003000 00:00 0 /fake/elf3\n"
68 "500000-501000 r--p 0000000 00:00 0 /fake/elf4\n"
69 "501000-502000 ---p 0000000 00:00 0\n"
70 "503000-510000 rw-p 0003000 00:00 0 /fake/elf4\n"
71 "510000-520000 rw-p 0010000 00:00 0 /fake/elf4\n"));
Christopher Ferris7747b602018-01-31 19:05:19 -080072 ASSERT_TRUE(maps_->Parse());
73
Christopher Ferris1f34c0e2018-10-08 17:39:39 -070074 // Global variable in a section that is not readable.
75 MapInfo* map_info = maps_->Get(kMapGlobalNonReadable);
Christopher Ferris7747b602018-01-31 19:05:19 -080076 ASSERT_TRUE(map_info != nullptr);
Christopher Ferrisdf683b72019-12-03 17:13:49 -080077 CreateFakeElf(map_info, 0x2800, 0x2000, 0x2000, 0x3000);
Christopher Ferris7747b602018-01-31 19:05:19 -080078
79 // Global variable not set by default.
80 map_info = maps_->Get(kMapGlobalSetToZero);
81 ASSERT_TRUE(map_info != nullptr);
Christopher Ferrisdf683b72019-12-03 17:13:49 -080082 CreateFakeElf(map_info, 0x2800, 0x2000, 0x2000, 0x3000);
Christopher Ferris7747b602018-01-31 19:05:19 -080083
84 // Global variable set in this map.
85 map_info = maps_->Get(kMapGlobal);
86 ASSERT_TRUE(map_info != nullptr);
Christopher Ferrisdf683b72019-12-03 17:13:49 -080087 CreateFakeElf(map_info, 0xf1800, 0xf1000, 0xf1000, 0x10000);
Christopher Ferrisde5cd8c2020-01-21 17:56:25 -080088
89 // Global variable set in this map, but there is an empty map before rw map.
90 map_info = maps_->Get(kMapGlobalAfterEmpty);
91 ASSERT_TRUE(map_info != nullptr);
92 CreateFakeElf(map_info, 0x3800, 0x3000, 0x3000, 0xd000);
Christopher Ferris4568f4b2018-10-23 17:42:41 -070093 }
94
95 void SetUp() override {
96 memory_ = new MemoryFake;
97 process_memory_.reset(memory_);
98
99 Init(ARCH_ARM);
Christopher Ferris7747b602018-01-31 19:05:19 -0800100 }
101
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000102 void WriteDescriptor32(uint64_t addr, uint32_t head);
103 void WriteDescriptor64(uint64_t addr, uint64_t head);
104 void WriteEntry32(uint64_t entry_addr, uint32_t next, uint32_t prev, uint32_t dex_file);
105 void WriteEntry64(uint64_t entry_addr, uint64_t next, uint64_t prev, uint64_t dex_file);
Christopher Ferris7747b602018-01-31 19:05:19 -0800106 void WriteDex(uint64_t dex_file);
107
Christopher Ferris1f34c0e2018-10-08 17:39:39 -0700108 static constexpr size_t kMapGlobalNonReadable = 2;
Christopher Ferris56d0e072018-10-17 10:57:53 -0700109 static constexpr size_t kMapGlobalSetToZero = 3;
Christopher Ferris7747b602018-01-31 19:05:19 -0800110 static constexpr size_t kMapGlobal = 5;
Christopher Ferris56d0e072018-10-17 10:57:53 -0700111 static constexpr size_t kMapGlobalRw = 6;
Christopher Ferris7747b602018-01-31 19:05:19 -0800112 static constexpr size_t kMapDexFileEntries = 7;
113 static constexpr size_t kMapDexFiles = 8;
Christopher Ferrisde5cd8c2020-01-21 17:56:25 -0800114 static constexpr size_t kMapGlobalAfterEmpty = 9;
115 static constexpr size_t kMapDexFilesAfterEmpty = 12;
Christopher Ferris7747b602018-01-31 19:05:19 -0800116
117 std::shared_ptr<Memory> process_memory_;
118 MemoryFake* memory_;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000119 std::unique_ptr<DexFiles> dex_files_;
Christopher Ferris7747b602018-01-31 19:05:19 -0800120 std::unique_ptr<BufferMaps> maps_;
121};
122
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000123void DexFilesTest::WriteDescriptor32(uint64_t addr, uint32_t head) {
124 // void* first_entry_
125 memory_->SetData32(addr + 12, head);
David Srbecky4015ef42018-02-15 17:57:16 +0000126}
127
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000128void DexFilesTest::WriteDescriptor64(uint64_t addr, uint64_t head) {
129 // void* first_entry_
130 memory_->SetData64(addr + 16, head);
David Srbecky4015ef42018-02-15 17:57:16 +0000131}
132
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000133void DexFilesTest::WriteEntry32(uint64_t entry_addr, uint32_t next, uint32_t prev,
134 uint32_t dex_file) {
135 // Format of the 32 bit DEXFileEntry structure:
Christopher Ferris7747b602018-01-31 19:05:19 -0800136 // uint32_t next
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000137 memory_->SetData32(entry_addr, next);
Christopher Ferris7747b602018-01-31 19:05:19 -0800138 // uint32_t prev
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000139 memory_->SetData32(entry_addr + 4, prev);
140 // uint32_t dex_file
141 memory_->SetData32(entry_addr + 8, dex_file);
Christopher Ferris7747b602018-01-31 19:05:19 -0800142}
143
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000144void DexFilesTest::WriteEntry64(uint64_t entry_addr, uint64_t next, uint64_t prev,
145 uint64_t dex_file) {
146 // Format of the 64 bit DEXFileEntry structure:
Christopher Ferris7747b602018-01-31 19:05:19 -0800147 // uint64_t next
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000148 memory_->SetData64(entry_addr, next);
Christopher Ferris7747b602018-01-31 19:05:19 -0800149 // uint64_t prev
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000150 memory_->SetData64(entry_addr + 8, prev);
151 // uint64_t dex_file
152 memory_->SetData64(entry_addr + 16, dex_file);
Christopher Ferris7747b602018-01-31 19:05:19 -0800153}
154
155void DexFilesTest::WriteDex(uint64_t dex_file) {
156 memory_->SetMemory(dex_file, kDexData, sizeof(kDexData) * sizeof(uint32_t));
157}
158
159TEST_F(DexFilesTest, get_method_information_invalid) {
160 std::string method_name = "nothing";
161 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000162 MapInfo* info = maps_->Get(kMapDexFileEntries);
Christopher Ferris7747b602018-01-31 19:05:19 -0800163
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000164 dex_files_->GetMethodInformation(maps_.get(), info, 0, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800165 EXPECT_EQ("nothing", method_name);
166 EXPECT_EQ(0x124U, method_offset);
167}
168
169TEST_F(DexFilesTest, get_method_information_32) {
170 std::string method_name = "nothing";
171 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000172 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800173
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800174 WriteDescriptor32(0x100800, 0x200000);
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000175 WriteEntry32(0x200000, 0, 0, 0x300000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800176 WriteDex(0x300000);
177
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000178 dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800179 EXPECT_EQ("Main.<init>", method_name);
180 EXPECT_EQ(0U, method_offset);
181}
182
183TEST_F(DexFilesTest, get_method_information_64) {
Christopher Ferris4568f4b2018-10-23 17:42:41 -0700184 Init(ARCH_ARM64);
185
Christopher Ferris7747b602018-01-31 19:05:19 -0800186 std::string method_name = "nothing";
187 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000188 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800189
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800190 WriteDescriptor64(0x100800, 0x200000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800191 WriteEntry64(0x200000, 0, 0, 0x301000);
192 WriteDex(0x301000);
193
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000194 dex_files_->GetMethodInformation(maps_.get(), info, 0x301102, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800195 EXPECT_EQ("Main.<init>", method_name);
196 EXPECT_EQ(2U, method_offset);
197}
198
199TEST_F(DexFilesTest, get_method_information_not_first_entry_32) {
200 std::string method_name = "nothing";
201 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000202 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800203
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800204 WriteDescriptor32(0x100800, 0x200000);
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000205 WriteEntry32(0x200000, 0x200100, 0, 0x100000);
206 WriteEntry32(0x200100, 0, 0x200000, 0x300000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800207 WriteDex(0x300000);
208
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000209 dex_files_->GetMethodInformation(maps_.get(), info, 0x300104, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800210 EXPECT_EQ("Main.<init>", method_name);
211 EXPECT_EQ(4U, method_offset);
212}
213
214TEST_F(DexFilesTest, get_method_information_not_first_entry_64) {
Christopher Ferris4568f4b2018-10-23 17:42:41 -0700215 Init(ARCH_ARM64);
216
Christopher Ferris7747b602018-01-31 19:05:19 -0800217 std::string method_name = "nothing";
218 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000219 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800220
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800221 WriteDescriptor64(0x100800, 0x200000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800222 WriteEntry64(0x200000, 0x200100, 0, 0x100000);
223 WriteEntry64(0x200100, 0, 0x200000, 0x300000);
224 WriteDex(0x300000);
225
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000226 dex_files_->GetMethodInformation(maps_.get(), info, 0x300106, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800227 EXPECT_EQ("Main.<init>", method_name);
228 EXPECT_EQ(6U, method_offset);
229}
230
231TEST_F(DexFilesTest, get_method_information_cached) {
232 std::string method_name = "nothing";
233 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000234 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800235
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800236 WriteDescriptor32(0x100800, 0x200000);
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000237 WriteEntry32(0x200000, 0, 0, 0x300000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800238 WriteDex(0x300000);
239
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000240 dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800241 EXPECT_EQ("Main.<init>", method_name);
242 EXPECT_EQ(0U, method_offset);
243
244 // Clear all memory and make sure that data is acquired from the cache.
245 memory_->Clear();
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000246 dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800247 EXPECT_EQ("Main.<init>", method_name);
248 EXPECT_EQ(0U, method_offset);
249}
250
251TEST_F(DexFilesTest, get_method_information_search_libs) {
252 std::string method_name = "nothing";
253 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000254 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800255
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800256 WriteDescriptor32(0x100800, 0x200000);
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000257 WriteEntry32(0x200000, 0x200100, 0, 0x100000);
258 WriteEntry32(0x200100, 0, 0x200000, 0x300000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800259 WriteDex(0x300000);
260
261 // Only search a given named list of libs.
262 std::vector<std::string> libs{"libart.so"};
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000263 dex_files_.reset(new DexFiles(process_memory_, libs));
264 dex_files_->SetArch(ARCH_ARM);
Christopher Ferris7747b602018-01-31 19:05:19 -0800265
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000266 dex_files_->GetMethodInformation(maps_.get(), info, 0x300104, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800267 EXPECT_EQ("nothing", method_name);
268 EXPECT_EQ(0x124U, method_offset);
269
270 MapInfo* map_info = maps_->Get(kMapGlobal);
271 map_info->name = "/system/lib/libart.so";
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000272 dex_files_.reset(new DexFiles(process_memory_, libs));
273 dex_files_->SetArch(ARCH_ARM);
Christopher Ferris56d0e072018-10-17 10:57:53 -0700274 // Set the rw map to the same name or this will not scan this entry.
275 map_info = maps_->Get(kMapGlobalRw);
276 map_info->name = "/system/lib/libart.so";
Christopher Ferris7747b602018-01-31 19:05:19 -0800277 // Make sure that clearing out copy of the libs doesn't affect the
278 // DexFiles object.
279 libs.clear();
280
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000281 dex_files_->GetMethodInformation(maps_.get(), info, 0x300104, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800282 EXPECT_EQ("Main.<init>", method_name);
283 EXPECT_EQ(4U, method_offset);
284}
285
286TEST_F(DexFilesTest, get_method_information_global_skip_zero_32) {
287 std::string method_name = "nothing";
288 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000289 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800290
291 // First global variable found, but value is zero.
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800292 WriteDescriptor32(0xc800, 0);
Christopher Ferris7747b602018-01-31 19:05:19 -0800293
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800294 WriteDescriptor32(0x100800, 0x200000);
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000295 WriteEntry32(0x200000, 0, 0, 0x300000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800296 WriteDex(0x300000);
297
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000298 dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800299 EXPECT_EQ("Main.<init>", method_name);
300 EXPECT_EQ(0U, method_offset);
301
302 // Verify that second is ignored when first is set to non-zero
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000303 dex_files_.reset(new DexFiles(process_memory_));
304 dex_files_->SetArch(ARCH_ARM);
Christopher Ferris7747b602018-01-31 19:05:19 -0800305 method_name = "fail";
306 method_offset = 0x123;
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800307 WriteDescriptor32(0xc800, 0x100000);
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000308 dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800309 EXPECT_EQ("fail", method_name);
310 EXPECT_EQ(0x123U, method_offset);
311}
312
313TEST_F(DexFilesTest, get_method_information_global_skip_zero_64) {
Christopher Ferris4568f4b2018-10-23 17:42:41 -0700314 Init(ARCH_ARM64);
315
Christopher Ferris7747b602018-01-31 19:05:19 -0800316 std::string method_name = "nothing";
317 uint64_t method_offset = 0x124;
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000318 MapInfo* info = maps_->Get(kMapDexFiles);
Christopher Ferris7747b602018-01-31 19:05:19 -0800319
320 // First global variable found, but value is zero.
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800321 WriteDescriptor64(0xc800, 0);
Christopher Ferris7747b602018-01-31 19:05:19 -0800322
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800323 WriteDescriptor64(0x100800, 0x200000);
Christopher Ferris7747b602018-01-31 19:05:19 -0800324 WriteEntry64(0x200000, 0, 0, 0x300000);
325 WriteDex(0x300000);
326
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000327 dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800328 EXPECT_EQ("Main.<init>", method_name);
329 EXPECT_EQ(0U, method_offset);
330
331 // Verify that second is ignored when first is set to non-zero
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000332 dex_files_.reset(new DexFiles(process_memory_));
333 dex_files_->SetArch(ARCH_ARM64);
Christopher Ferris7747b602018-01-31 19:05:19 -0800334 method_name = "fail";
335 method_offset = 0x123;
Christopher Ferrisdf683b72019-12-03 17:13:49 -0800336 WriteDescriptor64(0xc800, 0x100000);
David Srbeckyb9cc4fb2019-04-05 18:23:32 +0000337 dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
Christopher Ferris7747b602018-01-31 19:05:19 -0800338 EXPECT_EQ("fail", method_name);
339 EXPECT_EQ(0x123U, method_offset);
340}
341
Christopher Ferrisde5cd8c2020-01-21 17:56:25 -0800342TEST_F(DexFilesTest, get_method_information_with_empty_map) {
343 std::string method_name = "nothing";
344 uint64_t method_offset = 0x124;
345 MapInfo* info = maps_->Get(kMapDexFilesAfterEmpty);
346
347 WriteDescriptor32(0x503800, 0x506000);
348 WriteEntry32(0x506000, 0, 0, 0x510000);
349 WriteDex(0x510000);
350
351 dex_files_->GetMethodInformation(maps_.get(), info, 0x510100, &method_name, &method_offset);
352 EXPECT_EQ("Main.<init>", method_name);
353 EXPECT_EQ(0U, method_offset);
354}
355
Christopher Ferris7747b602018-01-31 19:05:19 -0800356} // namespace unwindstack