| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2016 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 |  | 
|  | 19 | #include <gtest/gtest.h> | 
|  | 20 |  | 
|  | 21 | #include <vector> | 
|  | 22 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 23 | #include <unwindstack/Regs.h> | 
|  | 24 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 25 | #include "ElfInterfaceArm.h" | 
|  | 26 | #include "Machine.h" | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 27 |  | 
|  | 28 | #include "MemoryFake.h" | 
|  | 29 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 30 | namespace unwindstack { | 
|  | 31 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 32 | class ElfInterfaceArmTest : public ::testing::Test { | 
|  | 33 | protected: | 
|  | 34 | void SetUp() override { | 
|  | 35 | memory_.Clear(); | 
|  | 36 | process_memory_.Clear(); | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | MemoryFake memory_; | 
|  | 40 | MemoryFake process_memory_; | 
|  | 41 | }; | 
|  | 42 |  | 
|  | 43 | TEST_F(ElfInterfaceArmTest, GetPrel32Addr) { | 
|  | 44 | ElfInterfaceArm interface(&memory_); | 
|  | 45 | memory_.SetData32(0x1000, 0x230000); | 
|  | 46 |  | 
|  | 47 | uint32_t value; | 
|  | 48 | ASSERT_TRUE(interface.GetPrel31Addr(0x1000, &value)); | 
|  | 49 | ASSERT_EQ(0x231000U, value); | 
|  | 50 |  | 
|  | 51 | memory_.SetData32(0x1000, 0x80001000); | 
|  | 52 | ASSERT_TRUE(interface.GetPrel31Addr(0x1000, &value)); | 
|  | 53 | ASSERT_EQ(0x2000U, value); | 
|  | 54 |  | 
|  | 55 | memory_.SetData32(0x1000, 0x70001000); | 
|  | 56 | ASSERT_TRUE(interface.GetPrel31Addr(0x1000, &value)); | 
|  | 57 | ASSERT_EQ(0xf0002000U, value); | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | TEST_F(ElfInterfaceArmTest, FindEntry_start_zero) { | 
|  | 61 | ElfInterfaceArm interface(&memory_); | 
|  | 62 | interface.set_start_offset(0); | 
|  | 63 | interface.set_total_entries(10); | 
|  | 64 |  | 
|  | 65 | uint64_t entry_offset; | 
|  | 66 | ASSERT_FALSE(interface.FindEntry(0x1000, &entry_offset)); | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | TEST_F(ElfInterfaceArmTest, FindEntry_no_entries) { | 
|  | 70 | ElfInterfaceArm interface(&memory_); | 
|  | 71 | interface.set_start_offset(0x100); | 
|  | 72 | interface.set_total_entries(0); | 
|  | 73 |  | 
|  | 74 | uint64_t entry_offset; | 
|  | 75 | ASSERT_FALSE(interface.FindEntry(0x1000, &entry_offset)); | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | TEST_F(ElfInterfaceArmTest, FindEntry_no_valid_memory) { | 
|  | 79 | ElfInterfaceArm interface(&memory_); | 
|  | 80 | interface.set_start_offset(0x100); | 
|  | 81 | interface.set_total_entries(2); | 
|  | 82 |  | 
|  | 83 | uint64_t entry_offset; | 
|  | 84 | ASSERT_FALSE(interface.FindEntry(0x1000, &entry_offset)); | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | TEST_F(ElfInterfaceArmTest, FindEntry_ip_before_first) { | 
|  | 88 | ElfInterfaceArm interface(&memory_); | 
|  | 89 | interface.set_start_offset(0x1000); | 
|  | 90 | interface.set_total_entries(1); | 
|  | 91 | memory_.SetData32(0x1000, 0x6000); | 
|  | 92 |  | 
|  | 93 | uint64_t entry_offset; | 
|  | 94 | ASSERT_FALSE(interface.FindEntry(0x1000, &entry_offset)); | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | TEST_F(ElfInterfaceArmTest, FindEntry_single_entry_negative_value) { | 
|  | 98 | ElfInterfaceArm interface(&memory_); | 
|  | 99 | interface.set_start_offset(0x8000); | 
|  | 100 | interface.set_total_entries(1); | 
|  | 101 | memory_.SetData32(0x8000, 0x7fffff00); | 
|  | 102 |  | 
|  | 103 | uint64_t entry_offset; | 
|  | 104 | ASSERT_TRUE(interface.FindEntry(0x7ff0, &entry_offset)); | 
|  | 105 | ASSERT_EQ(0x8000U, entry_offset); | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | TEST_F(ElfInterfaceArmTest, FindEntry_two_entries) { | 
|  | 109 | ElfInterfaceArm interface(&memory_); | 
|  | 110 | interface.set_start_offset(0x1000); | 
|  | 111 | interface.set_total_entries(2); | 
|  | 112 | memory_.SetData32(0x1000, 0x6000); | 
|  | 113 | memory_.SetData32(0x1008, 0x7000); | 
|  | 114 |  | 
|  | 115 | uint64_t entry_offset; | 
|  | 116 | ASSERT_TRUE(interface.FindEntry(0x7000, &entry_offset)); | 
|  | 117 | ASSERT_EQ(0x1000U, entry_offset); | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 |  | 
|  | 121 | TEST_F(ElfInterfaceArmTest, FindEntry_last_check_single_entry) { | 
|  | 122 | ElfInterfaceArm interface(&memory_); | 
|  | 123 | interface.set_start_offset(0x1000); | 
|  | 124 | interface.set_total_entries(1); | 
|  | 125 | memory_.SetData32(0x1000, 0x6000); | 
|  | 126 |  | 
|  | 127 | uint64_t entry_offset; | 
|  | 128 | ASSERT_TRUE(interface.FindEntry(0x7000, &entry_offset)); | 
|  | 129 | ASSERT_EQ(0x1000U, entry_offset); | 
|  | 130 |  | 
|  | 131 | // To guarantee that we are using the cache on the second run, | 
|  | 132 | // set the memory to a different value. | 
|  | 133 | memory_.SetData32(0x1000, 0x8000); | 
|  | 134 | ASSERT_TRUE(interface.FindEntry(0x7004, &entry_offset)); | 
|  | 135 | ASSERT_EQ(0x1000U, entry_offset); | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | TEST_F(ElfInterfaceArmTest, FindEntry_last_check_multiple_entries) { | 
|  | 139 | ElfInterfaceArm interface(&memory_); | 
|  | 140 | interface.set_start_offset(0x1000); | 
|  | 141 | interface.set_total_entries(2); | 
|  | 142 | memory_.SetData32(0x1000, 0x6000); | 
|  | 143 | memory_.SetData32(0x1008, 0x8000); | 
|  | 144 |  | 
|  | 145 | uint64_t entry_offset; | 
|  | 146 | ASSERT_TRUE(interface.FindEntry(0x9008, &entry_offset)); | 
|  | 147 | ASSERT_EQ(0x1008U, entry_offset); | 
|  | 148 |  | 
|  | 149 | // To guarantee that we are using the cache on the second run, | 
|  | 150 | // set the memory to a different value. | 
|  | 151 | memory_.SetData32(0x1000, 0x16000); | 
|  | 152 | memory_.SetData32(0x1008, 0x18000); | 
|  | 153 | ASSERT_TRUE(interface.FindEntry(0x9100, &entry_offset)); | 
|  | 154 | ASSERT_EQ(0x1008U, entry_offset); | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | TEST_F(ElfInterfaceArmTest, FindEntry_multiple_entries_even) { | 
|  | 158 | ElfInterfaceArm interface(&memory_); | 
|  | 159 | interface.set_start_offset(0x1000); | 
|  | 160 | interface.set_total_entries(4); | 
|  | 161 | memory_.SetData32(0x1000, 0x6000); | 
|  | 162 | memory_.SetData32(0x1008, 0x7000); | 
|  | 163 | memory_.SetData32(0x1010, 0x8000); | 
|  | 164 | memory_.SetData32(0x1018, 0x9000); | 
|  | 165 |  | 
|  | 166 | uint64_t entry_offset; | 
|  | 167 | ASSERT_TRUE(interface.FindEntry(0x9100, &entry_offset)); | 
|  | 168 | ASSERT_EQ(0x1010U, entry_offset); | 
|  | 169 |  | 
|  | 170 | // To guarantee that we are using the cache on the second run, | 
|  | 171 | // set the memory to a different value. | 
|  | 172 | memory_.SetData32(0x1000, 0x16000); | 
|  | 173 | memory_.SetData32(0x1008, 0x17000); | 
|  | 174 | memory_.SetData32(0x1010, 0x18000); | 
|  | 175 | memory_.SetData32(0x1018, 0x19000); | 
|  | 176 | ASSERT_TRUE(interface.FindEntry(0x9100, &entry_offset)); | 
|  | 177 | ASSERT_EQ(0x1010U, entry_offset); | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | TEST_F(ElfInterfaceArmTest, FindEntry_multiple_entries_odd) { | 
|  | 181 | ElfInterfaceArm interface(&memory_); | 
|  | 182 | interface.set_start_offset(0x1000); | 
|  | 183 | interface.set_total_entries(5); | 
|  | 184 | memory_.SetData32(0x1000, 0x5000); | 
|  | 185 | memory_.SetData32(0x1008, 0x6000); | 
|  | 186 | memory_.SetData32(0x1010, 0x7000); | 
|  | 187 | memory_.SetData32(0x1018, 0x8000); | 
|  | 188 | memory_.SetData32(0x1020, 0x9000); | 
|  | 189 |  | 
|  | 190 | uint64_t entry_offset; | 
|  | 191 | ASSERT_TRUE(interface.FindEntry(0x8100, &entry_offset)); | 
|  | 192 | ASSERT_EQ(0x1010U, entry_offset); | 
|  | 193 |  | 
|  | 194 | // To guarantee that we are using the cache on the second run, | 
|  | 195 | // set the memory to a different value. | 
|  | 196 | memory_.SetData32(0x1000, 0x15000); | 
|  | 197 | memory_.SetData32(0x1008, 0x16000); | 
|  | 198 | memory_.SetData32(0x1010, 0x17000); | 
|  | 199 | memory_.SetData32(0x1018, 0x18000); | 
|  | 200 | memory_.SetData32(0x1020, 0x19000); | 
|  | 201 | ASSERT_TRUE(interface.FindEntry(0x8100, &entry_offset)); | 
|  | 202 | ASSERT_EQ(0x1010U, entry_offset); | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | TEST_F(ElfInterfaceArmTest, iterate) { | 
|  | 206 | ElfInterfaceArm interface(&memory_); | 
|  | 207 | interface.set_start_offset(0x1000); | 
|  | 208 | interface.set_total_entries(5); | 
|  | 209 | memory_.SetData32(0x1000, 0x5000); | 
|  | 210 | memory_.SetData32(0x1008, 0x6000); | 
|  | 211 | memory_.SetData32(0x1010, 0x7000); | 
|  | 212 | memory_.SetData32(0x1018, 0x8000); | 
|  | 213 | memory_.SetData32(0x1020, 0x9000); | 
|  | 214 |  | 
|  | 215 | std::vector<uint32_t> entries; | 
|  | 216 | for (auto addr : interface) { | 
|  | 217 | entries.push_back(addr); | 
|  | 218 | } | 
|  | 219 | ASSERT_EQ(5U, entries.size()); | 
|  | 220 | ASSERT_EQ(0x6000U, entries[0]); | 
|  | 221 | ASSERT_EQ(0x7008U, entries[1]); | 
|  | 222 | ASSERT_EQ(0x8010U, entries[2]); | 
|  | 223 | ASSERT_EQ(0x9018U, entries[3]); | 
|  | 224 | ASSERT_EQ(0xa020U, entries[4]); | 
|  | 225 |  | 
|  | 226 | // Make sure the iterate cached the entries. | 
|  | 227 | memory_.SetData32(0x1000, 0x11000); | 
|  | 228 | memory_.SetData32(0x1008, 0x12000); | 
|  | 229 | memory_.SetData32(0x1010, 0x13000); | 
|  | 230 | memory_.SetData32(0x1018, 0x14000); | 
|  | 231 | memory_.SetData32(0x1020, 0x15000); | 
|  | 232 |  | 
|  | 233 | entries.clear(); | 
|  | 234 | for (auto addr : interface) { | 
|  | 235 | entries.push_back(addr); | 
|  | 236 | } | 
|  | 237 | ASSERT_EQ(5U, entries.size()); | 
|  | 238 | ASSERT_EQ(0x6000U, entries[0]); | 
|  | 239 | ASSERT_EQ(0x7008U, entries[1]); | 
|  | 240 | ASSERT_EQ(0x8010U, entries[2]); | 
|  | 241 | ASSERT_EQ(0x9018U, entries[3]); | 
|  | 242 | ASSERT_EQ(0xa020U, entries[4]); | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | TEST_F(ElfInterfaceArmTest, FindEntry_load_bias) { | 
|  | 246 | ElfInterfaceArm interface(&memory_); | 
|  | 247 | interface.set_start_offset(0x1000); | 
|  | 248 | interface.set_total_entries(2); | 
|  | 249 | memory_.SetData32(0x1000, 0x6000); | 
|  | 250 | memory_.SetData32(0x1008, 0x8000); | 
|  | 251 |  | 
|  | 252 | uint64_t entry_offset; | 
|  | 253 | interface.set_load_bias(0x2000); | 
|  | 254 | ASSERT_FALSE(interface.FindEntry(0x1000, &entry_offset)); | 
|  | 255 | ASSERT_FALSE(interface.FindEntry(0x8000, &entry_offset)); | 
|  | 256 | ASSERT_FALSE(interface.FindEntry(0x8fff, &entry_offset)); | 
|  | 257 | ASSERT_TRUE(interface.FindEntry(0x9000, &entry_offset)); | 
|  | 258 | ASSERT_EQ(0x1000U, entry_offset); | 
|  | 259 | ASSERT_TRUE(interface.FindEntry(0xb007, &entry_offset)); | 
|  | 260 | ASSERT_EQ(0x1000U, entry_offset); | 
|  | 261 | ASSERT_TRUE(interface.FindEntry(0xb008, &entry_offset)); | 
|  | 262 | ASSERT_EQ(0x1008U, entry_offset); | 
|  | 263 | } | 
|  | 264 |  | 
|  | 265 | TEST_F(ElfInterfaceArmTest, HandleType_not_arm_exidx) { | 
|  | 266 | ElfInterfaceArm interface(&memory_); | 
|  | 267 |  | 
|  | 268 | ASSERT_FALSE(interface.HandleType(0x1000, PT_NULL)); | 
|  | 269 | ASSERT_FALSE(interface.HandleType(0x1000, PT_LOAD)); | 
|  | 270 | ASSERT_FALSE(interface.HandleType(0x1000, PT_DYNAMIC)); | 
|  | 271 | ASSERT_FALSE(interface.HandleType(0x1000, PT_INTERP)); | 
|  | 272 | ASSERT_FALSE(interface.HandleType(0x1000, PT_NOTE)); | 
|  | 273 | ASSERT_FALSE(interface.HandleType(0x1000, PT_SHLIB)); | 
|  | 274 | ASSERT_FALSE(interface.HandleType(0x1000, PT_PHDR)); | 
|  | 275 | ASSERT_FALSE(interface.HandleType(0x1000, PT_TLS)); | 
|  | 276 | ASSERT_FALSE(interface.HandleType(0x1000, PT_LOOS)); | 
|  | 277 | ASSERT_FALSE(interface.HandleType(0x1000, PT_HIOS)); | 
|  | 278 | ASSERT_FALSE(interface.HandleType(0x1000, PT_LOPROC)); | 
|  | 279 | ASSERT_FALSE(interface.HandleType(0x1000, PT_HIPROC)); | 
|  | 280 | ASSERT_FALSE(interface.HandleType(0x1000, PT_GNU_EH_FRAME)); | 
|  | 281 | ASSERT_FALSE(interface.HandleType(0x1000, PT_GNU_STACK)); | 
|  | 282 | } | 
|  | 283 |  | 
|  | 284 | TEST_F(ElfInterfaceArmTest, HandleType_arm_exidx) { | 
|  | 285 | ElfInterfaceArm interface(&memory_); | 
|  | 286 |  | 
|  | 287 | Elf32_Phdr phdr; | 
|  | 288 | interface.set_start_offset(0x1000); | 
|  | 289 | interface.set_total_entries(100); | 
|  | 290 | phdr.p_vaddr = 0x2000; | 
|  | 291 | phdr.p_memsz = 0xa00; | 
|  | 292 |  | 
|  | 293 | // Verify that if reads fail, we don't set the values but still get true. | 
|  | 294 | ASSERT_TRUE(interface.HandleType(0x1000, 0x70000001)); | 
|  | 295 | ASSERT_EQ(0x1000U, interface.start_offset()); | 
|  | 296 | ASSERT_EQ(100U, interface.total_entries()); | 
|  | 297 |  | 
|  | 298 | // Verify that if the second read fails, we still don't set the values. | 
|  | 299 | memory_.SetData32( | 
|  | 300 | 0x1000 + reinterpret_cast<uint64_t>(&phdr.p_vaddr) - reinterpret_cast<uint64_t>(&phdr), | 
|  | 301 | phdr.p_vaddr); | 
|  | 302 | ASSERT_TRUE(interface.HandleType(0x1000, 0x70000001)); | 
|  | 303 | ASSERT_EQ(0x1000U, interface.start_offset()); | 
|  | 304 | ASSERT_EQ(100U, interface.total_entries()); | 
|  | 305 |  | 
|  | 306 | // Everything is correct and present. | 
|  | 307 | memory_.SetData32( | 
|  | 308 | 0x1000 + reinterpret_cast<uint64_t>(&phdr.p_memsz) - reinterpret_cast<uint64_t>(&phdr), | 
|  | 309 | phdr.p_memsz); | 
|  | 310 | ASSERT_TRUE(interface.HandleType(0x1000, 0x70000001)); | 
|  | 311 | ASSERT_EQ(0x2000U, interface.start_offset()); | 
|  | 312 | ASSERT_EQ(320U, interface.total_entries()); | 
|  | 313 |  | 
|  | 314 | // Non-zero load bias. | 
|  | 315 | interface.set_load_bias(0x1000); | 
|  | 316 | ASSERT_TRUE(interface.HandleType(0x1000, 0x70000001)); | 
|  | 317 | ASSERT_EQ(0x1000U, interface.start_offset()); | 
|  | 318 | ASSERT_EQ(320U, interface.total_entries()); | 
|  | 319 | } | 
|  | 320 |  | 
|  | 321 | TEST_F(ElfInterfaceArmTest, StepExidx) { | 
|  | 322 | ElfInterfaceArm interface(&memory_); | 
|  | 323 |  | 
|  | 324 | // FindEntry fails. | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 325 | bool finished; | 
|  | 326 | ASSERT_FALSE(interface.StepExidx(0x7000, nullptr, nullptr, &finished)); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 327 |  | 
|  | 328 | // ExtractEntry should fail. | 
|  | 329 | interface.set_start_offset(0x1000); | 
|  | 330 | interface.set_total_entries(2); | 
|  | 331 | memory_.SetData32(0x1000, 0x6000); | 
|  | 332 | memory_.SetData32(0x1008, 0x8000); | 
|  | 333 |  | 
|  | 334 | RegsArm regs; | 
|  | 335 | regs[ARM_REG_SP] = 0x1000; | 
|  | 336 | regs[ARM_REG_LR] = 0x20000; | 
|  | 337 | regs.set_sp(regs[ARM_REG_SP]); | 
|  | 338 | regs.set_pc(0x1234); | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 339 | ASSERT_FALSE(interface.StepExidx(0x7000, ®s, &process_memory_, &finished)); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 340 |  | 
|  | 341 | // Eval should fail. | 
|  | 342 | memory_.SetData32(0x1004, 0x81000000); | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 343 | ASSERT_FALSE(interface.StepExidx(0x7000, ®s, &process_memory_, &finished)); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 344 |  | 
|  | 345 | // Everything should pass. | 
|  | 346 | memory_.SetData32(0x1004, 0x80b0b0b0); | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 347 | ASSERT_TRUE(interface.StepExidx(0x7000, ®s, &process_memory_, &finished)); | 
|  | 348 | ASSERT_FALSE(finished); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 349 | ASSERT_EQ(0x1000U, regs.sp()); | 
|  | 350 | ASSERT_EQ(0x1000U, regs[ARM_REG_SP]); | 
|  | 351 | ASSERT_EQ(0x20000U, regs.pc()); | 
|  | 352 | ASSERT_EQ(0x20000U, regs[ARM_REG_PC]); | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | TEST_F(ElfInterfaceArmTest, StepExidx_pc_set) { | 
|  | 356 | ElfInterfaceArm interface(&memory_); | 
|  | 357 |  | 
|  | 358 | interface.set_start_offset(0x1000); | 
|  | 359 | interface.set_total_entries(2); | 
|  | 360 | memory_.SetData32(0x1000, 0x6000); | 
|  | 361 | memory_.SetData32(0x1004, 0x808800b0); | 
|  | 362 | memory_.SetData32(0x1008, 0x8000); | 
|  | 363 | process_memory_.SetData32(0x10000, 0x10); | 
|  | 364 |  | 
|  | 365 | RegsArm regs; | 
|  | 366 | regs[ARM_REG_SP] = 0x10000; | 
|  | 367 | regs[ARM_REG_LR] = 0x20000; | 
|  | 368 | regs.set_sp(regs[ARM_REG_SP]); | 
|  | 369 | regs.set_pc(0x1234); | 
|  | 370 |  | 
|  | 371 | // Everything should pass. | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 372 | bool finished; | 
|  | 373 | ASSERT_TRUE(interface.StepExidx(0x7000, ®s, &process_memory_, &finished)); | 
|  | 374 | ASSERT_FALSE(finished); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 375 | ASSERT_EQ(0x10004U, regs.sp()); | 
|  | 376 | ASSERT_EQ(0x10004U, regs[ARM_REG_SP]); | 
|  | 377 | ASSERT_EQ(0x10U, regs.pc()); | 
|  | 378 | ASSERT_EQ(0x10U, regs[ARM_REG_PC]); | 
|  | 379 | } | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 380 |  | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 381 | TEST_F(ElfInterfaceArmTest, StepExidx_cant_unwind) { | 
|  | 382 | ElfInterfaceArm interface(&memory_); | 
|  | 383 |  | 
|  | 384 | interface.set_start_offset(0x1000); | 
|  | 385 | interface.set_total_entries(1); | 
|  | 386 | memory_.SetData32(0x1000, 0x6000); | 
|  | 387 | memory_.SetData32(0x1004, 1); | 
|  | 388 |  | 
|  | 389 | RegsArm regs; | 
|  | 390 | regs[ARM_REG_SP] = 0x10000; | 
|  | 391 | regs[ARM_REG_LR] = 0x20000; | 
|  | 392 | regs.set_sp(regs[ARM_REG_SP]); | 
|  | 393 | regs.set_pc(0x1234); | 
|  | 394 |  | 
|  | 395 | bool finished; | 
|  | 396 | ASSERT_TRUE(interface.StepExidx(0x7000, ®s, &process_memory_, &finished)); | 
|  | 397 | ASSERT_TRUE(finished); | 
|  | 398 | ASSERT_EQ(0x10000U, regs.sp()); | 
|  | 399 | ASSERT_EQ(0x10000U, regs[ARM_REG_SP]); | 
|  | 400 | ASSERT_EQ(0x1234U, regs.pc()); | 
|  | 401 | } | 
|  | 402 |  | 
|  | 403 | TEST_F(ElfInterfaceArmTest, StepExidx_refuse_unwind) { | 
|  | 404 | ElfInterfaceArm interface(&memory_); | 
|  | 405 |  | 
|  | 406 | interface.set_start_offset(0x1000); | 
|  | 407 | interface.set_total_entries(1); | 
|  | 408 | memory_.SetData32(0x1000, 0x6000); | 
|  | 409 | memory_.SetData32(0x1004, 0x808000b0); | 
|  | 410 |  | 
|  | 411 | RegsArm regs; | 
|  | 412 | regs[ARM_REG_SP] = 0x10000; | 
|  | 413 | regs[ARM_REG_LR] = 0x20000; | 
|  | 414 | regs.set_sp(regs[ARM_REG_SP]); | 
|  | 415 | regs.set_pc(0x1234); | 
|  | 416 |  | 
|  | 417 | bool finished; | 
|  | 418 | ASSERT_TRUE(interface.StepExidx(0x7000, ®s, &process_memory_, &finished)); | 
|  | 419 | ASSERT_TRUE(finished); | 
|  | 420 | ASSERT_EQ(0x10000U, regs.sp()); | 
|  | 421 | ASSERT_EQ(0x10000U, regs[ARM_REG_SP]); | 
|  | 422 | ASSERT_EQ(0x1234U, regs.pc()); | 
|  | 423 | } | 
|  | 424 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 425 | }  // namespace unwindstack |