| Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [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 <stdint.h> | 
|  | 18 |  | 
|  | 19 | #include <gmock/gmock.h> | 
|  | 20 | #include <gtest/gtest.h> | 
|  | 21 |  | 
|  | 22 | #include "DwarfEhFrameWithHdr.h" | 
|  | 23 | #include "DwarfEncoding.h" | 
|  | 24 | #include "DwarfError.h" | 
|  | 25 |  | 
|  | 26 | #include "LogFake.h" | 
|  | 27 | #include "MemoryFake.h" | 
|  | 28 |  | 
|  | 29 | namespace unwindstack { | 
|  | 30 |  | 
|  | 31 | template <typename TypeParam> | 
|  | 32 | class MockDwarfEhFrameWithHdr : public DwarfEhFrameWithHdr<TypeParam> { | 
|  | 33 | public: | 
|  | 34 | MockDwarfEhFrameWithHdr(Memory* memory) : DwarfEhFrameWithHdr<TypeParam>(memory) {} | 
|  | 35 | ~MockDwarfEhFrameWithHdr() = default; | 
|  | 36 |  | 
|  | 37 | void TestSetTableEncoding(uint8_t encoding) { this->table_encoding_ = encoding; } | 
|  | 38 | void TestSetEntriesOffset(uint64_t offset) { this->entries_offset_ = offset; } | 
|  | 39 | void TestSetEntriesEnd(uint64_t end) { this->entries_end_ = end; } | 
|  | 40 | void TestSetEntriesDataOffset(uint64_t offset) { this->entries_data_offset_ = offset; } | 
|  | 41 | void TestSetCurEntriesOffset(uint64_t offset) { this->cur_entries_offset_ = offset; } | 
|  | 42 | void TestSetTableEntrySize(size_t size) { this->table_entry_size_ = size; } | 
|  | 43 |  | 
|  | 44 | void TestSetFdeCount(uint64_t count) { this->fde_count_ = count; } | 
|  | 45 | void TestSetFdeInfo(uint64_t index, const typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo& info) { | 
|  | 46 | this->fde_info_[index] = info; | 
|  | 47 | } | 
|  | 48 |  | 
|  | 49 | uint8_t TestGetVersion() { return this->version_; } | 
|  | 50 | uint8_t TestGetPtrEncoding() { return this->ptr_encoding_; } | 
|  | 51 | uint64_t TestGetPtrOffset() { return this->ptr_offset_; } | 
|  | 52 | uint8_t TestGetTableEncoding() { return this->table_encoding_; } | 
|  | 53 | uint64_t TestGetTableEntrySize() { return this->table_entry_size_; } | 
|  | 54 | uint64_t TestGetFdeCount() { return this->fde_count_; } | 
|  | 55 | uint64_t TestGetEntriesOffset() { return this->entries_offset_; } | 
|  | 56 | uint64_t TestGetEntriesEnd() { return this->entries_end_; } | 
|  | 57 | uint64_t TestGetEntriesDataOffset() { return this->entries_data_offset_; } | 
|  | 58 | uint64_t TestGetCurEntriesOffset() { return this->cur_entries_offset_; } | 
|  | 59 | }; | 
|  | 60 |  | 
|  | 61 | template <typename TypeParam> | 
|  | 62 | class DwarfEhFrameWithHdrTest : public ::testing::Test { | 
|  | 63 | protected: | 
|  | 64 | void SetUp() override { | 
|  | 65 | memory_.Clear(); | 
|  | 66 | eh_frame_ = new MockDwarfEhFrameWithHdr<TypeParam>(&memory_); | 
|  | 67 | ResetLogs(); | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | void TearDown() override { delete eh_frame_; } | 
|  | 71 |  | 
|  | 72 | MemoryFake memory_; | 
|  | 73 | MockDwarfEhFrameWithHdr<TypeParam>* eh_frame_ = nullptr; | 
|  | 74 | }; | 
|  | 75 | TYPED_TEST_CASE_P(DwarfEhFrameWithHdrTest); | 
|  | 76 |  | 
|  | 77 | // NOTE: All test class variables need to be referenced as this->. | 
|  | 78 |  | 
|  | 79 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init) { | 
|  | 80 | this->memory_.SetMemory( | 
|  | 81 | 0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4, DW_EH_PE_sdata4}); | 
|  | 82 | this->memory_.SetData16(0x1004, 0x500); | 
|  | 83 | this->memory_.SetData32(0x1006, 126); | 
|  | 84 |  | 
|  | 85 | ASSERT_TRUE(this->eh_frame_->Init(0x1000, 0x100)); | 
|  | 86 | EXPECT_EQ(1U, this->eh_frame_->TestGetVersion()); | 
|  | 87 | EXPECT_EQ(DW_EH_PE_udata2, this->eh_frame_->TestGetPtrEncoding()); | 
|  | 88 | EXPECT_EQ(DW_EH_PE_sdata4, this->eh_frame_->TestGetTableEncoding()); | 
|  | 89 | EXPECT_EQ(4U, this->eh_frame_->TestGetTableEntrySize()); | 
|  | 90 | EXPECT_EQ(126U, this->eh_frame_->TestGetFdeCount()); | 
|  | 91 | EXPECT_EQ(0x500U, this->eh_frame_->TestGetPtrOffset()); | 
|  | 92 | EXPECT_EQ(0x100aU, this->eh_frame_->TestGetEntriesOffset()); | 
|  | 93 | EXPECT_EQ(0x1100U, this->eh_frame_->TestGetEntriesEnd()); | 
|  | 94 | EXPECT_EQ(0x1000U, this->eh_frame_->TestGetEntriesDataOffset()); | 
|  | 95 | EXPECT_EQ(0x100aU, this->eh_frame_->TestGetCurEntriesOffset()); | 
|  | 96 |  | 
|  | 97 | // Verify an unexpected version will cause a fail. | 
|  | 98 | this->memory_.SetData8(0x1000, 0); | 
|  | 99 | ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100)); | 
|  | 100 | ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error()); | 
|  | 101 | this->memory_.SetData8(0x1000, 2); | 
|  | 102 | ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100)); | 
|  | 103 | ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error()); | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_expect_cache_fail) { | 
|  | 107 | this->eh_frame_->TestSetTableEntrySize(0x10); | 
|  | 108 | this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4); | 
|  | 109 | ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr); | 
|  | 110 | ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error()); | 
|  | 111 | ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr); | 
|  | 112 | ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error()); | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_read_pcrel) { | 
|  | 116 | this->eh_frame_->TestSetTableEncoding(DW_EH_PE_pcrel | DW_EH_PE_udata4); | 
|  | 117 | this->eh_frame_->TestSetEntriesOffset(0x1000); | 
|  | 118 | this->eh_frame_->TestSetEntriesDataOffset(0x3000); | 
|  | 119 | this->eh_frame_->TestSetTableEntrySize(0x10); | 
|  | 120 |  | 
|  | 121 | this->memory_.SetData32(0x1040, 0x340); | 
|  | 122 | this->memory_.SetData32(0x1044, 0x500); | 
|  | 123 |  | 
|  | 124 | auto info = this->eh_frame_->GetFdeInfoFromIndex(2); | 
|  | 125 | ASSERT_TRUE(info != nullptr); | 
|  | 126 | EXPECT_EQ(0x1384U, info->pc); | 
|  | 127 | EXPECT_EQ(0x1540U, info->offset); | 
|  | 128 | } | 
|  | 129 |  | 
|  | 130 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_read_datarel) { | 
|  | 131 | this->eh_frame_->TestSetTableEncoding(DW_EH_PE_datarel | DW_EH_PE_udata4); | 
|  | 132 | this->eh_frame_->TestSetEntriesOffset(0x1000); | 
|  | 133 | this->eh_frame_->TestSetEntriesDataOffset(0x3000); | 
|  | 134 | this->eh_frame_->TestSetTableEntrySize(0x10); | 
|  | 135 |  | 
|  | 136 | this->memory_.SetData32(0x1040, 0x340); | 
|  | 137 | this->memory_.SetData32(0x1044, 0x500); | 
|  | 138 |  | 
|  | 139 | auto info = this->eh_frame_->GetFdeInfoFromIndex(2); | 
|  | 140 | ASSERT_TRUE(info != nullptr); | 
|  | 141 | EXPECT_EQ(0x3344U, info->pc); | 
|  | 142 | EXPECT_EQ(0x3500U, info->offset); | 
|  | 143 | } | 
|  | 144 |  | 
|  | 145 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_cached) { | 
|  | 146 | this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4); | 
|  | 147 | this->eh_frame_->TestSetEntriesOffset(0x1000); | 
|  | 148 | this->eh_frame_->TestSetTableEntrySize(0x10); | 
|  | 149 |  | 
|  | 150 | this->memory_.SetData32(0x1040, 0x340); | 
|  | 151 | this->memory_.SetData32(0x1044, 0x500); | 
|  | 152 |  | 
|  | 153 | auto info = this->eh_frame_->GetFdeInfoFromIndex(2); | 
|  | 154 | ASSERT_TRUE(info != nullptr); | 
|  | 155 | EXPECT_EQ(0x344U, info->pc); | 
|  | 156 | EXPECT_EQ(0x500U, info->offset); | 
|  | 157 |  | 
|  | 158 | // Clear the memory so that this will fail if it doesn't read cached data. | 
|  | 159 | this->memory_.Clear(); | 
|  | 160 |  | 
|  | 161 | info = this->eh_frame_->GetFdeInfoFromIndex(2); | 
|  | 162 | ASSERT_TRUE(info != nullptr); | 
|  | 163 | EXPECT_EQ(0x344U, info->pc); | 
|  | 164 | EXPECT_EQ(0x500U, info->offset); | 
|  | 165 | } | 
|  | 166 |  | 
|  | 167 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetBinary_verify) { | 
|  | 168 | this->eh_frame_->TestSetTableEntrySize(0x10); | 
|  | 169 | this->eh_frame_->TestSetFdeCount(10); | 
|  | 170 |  | 
|  | 171 | typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info; | 
|  | 172 | for (size_t i = 0; i < 10; i++) { | 
|  | 173 | info.pc = 0x1000 * (i + 1); | 
|  | 174 | info.offset = 0x5000 + i * 0x20; | 
|  | 175 | this->eh_frame_->TestSetFdeInfo(i, info); | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | uint64_t fde_offset; | 
|  | 179 | EXPECT_FALSE(this->eh_frame_->GetFdeOffsetBinary(0x100, &fde_offset, 10)); | 
|  | 180 | // Not an error, just not found. | 
|  | 181 | ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error()); | 
|  | 182 | // Even number of elements. | 
|  | 183 | for (size_t i = 0; i < 10; i++) { | 
|  | 184 | TypeParam pc = 0x1000 * (i + 1); | 
|  | 185 | EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc, &fde_offset, 10)) << "Failed at index " << i; | 
|  | 186 | EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i; | 
|  | 187 | EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 1, &fde_offset, 10)) | 
|  | 188 | << "Failed at index " << i; | 
|  | 189 | EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i; | 
|  | 190 | EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 0xfff, &fde_offset, 10)) | 
|  | 191 | << "Failed at index " << i; | 
|  | 192 | EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i; | 
|  | 193 | } | 
|  | 194 | // Odd number of elements. | 
|  | 195 | for (size_t i = 0; i < 9; i++) { | 
|  | 196 | TypeParam pc = 0x1000 * (i + 1); | 
|  | 197 | EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc, &fde_offset, 9)) << "Failed at index " << i; | 
|  | 198 | EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i; | 
|  | 199 | EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 1, &fde_offset, 9)) | 
|  | 200 | << "Failed at index " << i; | 
|  | 201 | EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i; | 
|  | 202 | EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 0xfff, &fde_offset, 9)) | 
|  | 203 | << "Failed at index " << i; | 
|  | 204 | EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i; | 
|  | 205 | } | 
|  | 206 | } | 
|  | 207 |  | 
| Christopher Ferris | d96cbae | 2017-11-08 11:01:18 -0800 | [diff] [blame] | 208 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetBinary_index_fail) { | 
|  | 209 | this->eh_frame_->TestSetTableEntrySize(0x10); | 
|  | 210 | this->eh_frame_->TestSetFdeCount(10); | 
|  | 211 |  | 
|  | 212 | uint64_t fde_offset; | 
|  | 213 | EXPECT_FALSE(this->eh_frame_->GetFdeOffsetBinary(0x1000, &fde_offset, 10)); | 
|  | 214 | } | 
|  | 215 |  | 
| Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 216 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetSequential) { | 
|  | 217 | this->eh_frame_->TestSetFdeCount(10); | 
|  | 218 | this->eh_frame_->TestSetEntriesDataOffset(0x100); | 
|  | 219 | this->eh_frame_->TestSetEntriesEnd(0x2000); | 
|  | 220 | this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4); | 
|  | 221 |  | 
|  | 222 | this->memory_.SetData32(0x1040, 0x340); | 
|  | 223 | this->memory_.SetData32(0x1044, 0x500); | 
|  | 224 |  | 
|  | 225 | this->memory_.SetData32(0x1048, 0x440); | 
|  | 226 | this->memory_.SetData32(0x104c, 0x600); | 
|  | 227 |  | 
|  | 228 | // Verify that if entries is zero, that it fails. | 
|  | 229 | uint64_t fde_offset; | 
|  | 230 | ASSERT_FALSE(this->eh_frame_->GetFdeOffsetSequential(0x344, &fde_offset)); | 
|  | 231 | this->eh_frame_->TestSetCurEntriesOffset(0x1040); | 
|  | 232 |  | 
|  | 233 | ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x344, &fde_offset)); | 
|  | 234 | EXPECT_EQ(0x500U, fde_offset); | 
|  | 235 |  | 
|  | 236 | ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x444, &fde_offset)); | 
|  | 237 | EXPECT_EQ(0x600U, fde_offset); | 
|  | 238 |  | 
|  | 239 | // Expect that the data is cached so no more memory reads will occur. | 
|  | 240 | this->memory_.Clear(); | 
|  | 241 | ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x444, &fde_offset)); | 
|  | 242 | EXPECT_EQ(0x600U, fde_offset); | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetSequential_last_element) { | 
|  | 246 | this->eh_frame_->TestSetFdeCount(2); | 
|  | 247 | this->eh_frame_->TestSetEntriesDataOffset(0x100); | 
|  | 248 | this->eh_frame_->TestSetEntriesEnd(0x2000); | 
|  | 249 | this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4); | 
|  | 250 | this->eh_frame_->TestSetCurEntriesOffset(0x1040); | 
|  | 251 |  | 
|  | 252 | this->memory_.SetData32(0x1040, 0x340); | 
|  | 253 | this->memory_.SetData32(0x1044, 0x500); | 
|  | 254 |  | 
|  | 255 | this->memory_.SetData32(0x1048, 0x440); | 
|  | 256 | this->memory_.SetData32(0x104c, 0x600); | 
|  | 257 |  | 
|  | 258 | uint64_t fde_offset; | 
|  | 259 | ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x540, &fde_offset)); | 
|  | 260 | EXPECT_EQ(0x600U, fde_offset); | 
|  | 261 | } | 
|  | 262 |  | 
|  | 263 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetSequential_end_check) { | 
|  | 264 | this->eh_frame_->TestSetFdeCount(2); | 
|  | 265 | this->eh_frame_->TestSetEntriesDataOffset(0x100); | 
|  | 266 | this->eh_frame_->TestSetEntriesEnd(0x1048); | 
|  | 267 | this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4); | 
|  | 268 |  | 
|  | 269 | this->memory_.SetData32(0x1040, 0x340); | 
|  | 270 | this->memory_.SetData32(0x1044, 0x500); | 
|  | 271 |  | 
|  | 272 | this->memory_.SetData32(0x1048, 0x440); | 
|  | 273 | this->memory_.SetData32(0x104c, 0x600); | 
|  | 274 |  | 
|  | 275 | uint64_t fde_offset; | 
|  | 276 | ASSERT_FALSE(this->eh_frame_->GetFdeOffsetSequential(0x540, &fde_offset)); | 
|  | 277 | ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error()); | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_fail_fde_count) { | 
|  | 281 | this->eh_frame_->TestSetFdeCount(0); | 
|  | 282 |  | 
|  | 283 | uint64_t fde_offset; | 
|  | 284 | ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x100, &fde_offset)); | 
|  | 285 | ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error()); | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_binary_search) { | 
|  | 289 | this->eh_frame_->TestSetTableEntrySize(16); | 
|  | 290 | this->eh_frame_->TestSetFdeCount(10); | 
|  | 291 |  | 
|  | 292 | typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info; | 
|  | 293 | info.pc = 0x550; | 
|  | 294 | info.offset = 0x10500; | 
|  | 295 | this->eh_frame_->TestSetFdeInfo(5, info); | 
|  | 296 | info.pc = 0x750; | 
|  | 297 | info.offset = 0x10700; | 
|  | 298 | this->eh_frame_->TestSetFdeInfo(7, info); | 
|  | 299 | info.pc = 0x850; | 
|  | 300 | info.offset = 0x10800; | 
|  | 301 | this->eh_frame_->TestSetFdeInfo(8, info); | 
|  | 302 |  | 
|  | 303 | uint64_t fde_offset; | 
|  | 304 | ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(0x800, &fde_offset)); | 
|  | 305 | EXPECT_EQ(0x10700U, fde_offset); | 
|  | 306 | } | 
|  | 307 |  | 
|  | 308 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_sequential_search) { | 
|  | 309 | this->eh_frame_->TestSetFdeCount(10); | 
|  | 310 | this->eh_frame_->TestSetTableEntrySize(0); | 
|  | 311 |  | 
|  | 312 | typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info; | 
|  | 313 | info.pc = 0x50; | 
|  | 314 | info.offset = 0x10000; | 
|  | 315 | this->eh_frame_->TestSetFdeInfo(0, info); | 
|  | 316 | info.pc = 0x150; | 
|  | 317 | info.offset = 0x10100; | 
|  | 318 | this->eh_frame_->TestSetFdeInfo(1, info); | 
|  | 319 | info.pc = 0x250; | 
|  | 320 | info.offset = 0x10200; | 
|  | 321 | this->eh_frame_->TestSetFdeInfo(2, info); | 
|  | 322 |  | 
|  | 323 | uint64_t fde_offset; | 
|  | 324 | ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(0x200, &fde_offset)); | 
|  | 325 | EXPECT_EQ(0x10100U, fde_offset); | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetCieFde32) { | 
|  | 329 | // CIE 32 information. | 
|  | 330 | this->memory_.SetData32(0xf000, 0x100); | 
|  | 331 | this->memory_.SetData32(0xf004, 0); | 
|  | 332 | this->memory_.SetData8(0xf008, 0x1); | 
|  | 333 | this->memory_.SetData8(0xf009, '\0'); | 
|  | 334 | this->memory_.SetData8(0xf00a, 4); | 
|  | 335 | this->memory_.SetData8(0xf00b, 8); | 
|  | 336 | this->memory_.SetData8(0xf00c, 0x20); | 
|  | 337 |  | 
|  | 338 | // FDE 32 information. | 
|  | 339 | this->memory_.SetData32(0x14000, 0x20); | 
|  | 340 | this->memory_.SetData32(0x14004, 0x5004); | 
|  | 341 | this->memory_.SetData32(0x14008, 0x9000); | 
|  | 342 | this->memory_.SetData32(0x1400c, 0x100); | 
|  | 343 |  | 
|  | 344 | const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x14000); | 
|  | 345 | ASSERT_TRUE(fde != nullptr); | 
|  | 346 | EXPECT_EQ(0x14010U, fde->cfa_instructions_offset); | 
|  | 347 | EXPECT_EQ(0x14024U, fde->cfa_instructions_end); | 
| Christopher Ferris | c3d79f7 | 2017-11-28 19:14:54 -0800 | [diff] [blame] | 348 | EXPECT_EQ(0x1d008U, fde->pc_start); | 
|  | 349 | EXPECT_EQ(0x1d108U, fde->pc_end); | 
| Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 350 | EXPECT_EQ(0xf000U, fde->cie_offset); | 
|  | 351 | EXPECT_EQ(0U, fde->lsda_address); | 
|  | 352 |  | 
|  | 353 | ASSERT_TRUE(fde->cie != nullptr); | 
|  | 354 | EXPECT_EQ(1U, fde->cie->version); | 
|  | 355 | EXPECT_EQ(DW_EH_PE_sdata4, fde->cie->fde_address_encoding); | 
|  | 356 | EXPECT_EQ(DW_EH_PE_omit, fde->cie->lsda_encoding); | 
|  | 357 | EXPECT_EQ(0U, fde->cie->segment_size); | 
|  | 358 | EXPECT_EQ(1U, fde->cie->augmentation_string.size()); | 
|  | 359 | EXPECT_EQ('\0', fde->cie->augmentation_string[0]); | 
|  | 360 | EXPECT_EQ(0U, fde->cie->personality_handler); | 
|  | 361 | EXPECT_EQ(0xf00dU, fde->cie->cfa_instructions_offset); | 
|  | 362 | EXPECT_EQ(0xf104U, fde->cie->cfa_instructions_end); | 
|  | 363 | EXPECT_EQ(4U, fde->cie->code_alignment_factor); | 
|  | 364 | EXPECT_EQ(8, fde->cie->data_alignment_factor); | 
|  | 365 | EXPECT_EQ(0x20U, fde->cie->return_address_register); | 
|  | 366 | } | 
|  | 367 |  | 
|  | 368 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetCieFde64) { | 
|  | 369 | // CIE 64 information. | 
|  | 370 | this->memory_.SetData32(0x6000, 0xffffffff); | 
|  | 371 | this->memory_.SetData64(0x6004, 0x100); | 
|  | 372 | this->memory_.SetData64(0x600c, 0); | 
|  | 373 | this->memory_.SetData8(0x6014, 0x1); | 
|  | 374 | this->memory_.SetData8(0x6015, '\0'); | 
|  | 375 | this->memory_.SetData8(0x6016, 4); | 
|  | 376 | this->memory_.SetData8(0x6017, 8); | 
|  | 377 | this->memory_.SetData8(0x6018, 0x20); | 
|  | 378 |  | 
|  | 379 | // FDE 64 information. | 
|  | 380 | this->memory_.SetData32(0x8000, 0xffffffff); | 
|  | 381 | this->memory_.SetData64(0x8004, 0x200); | 
|  | 382 | this->memory_.SetData64(0x800c, 0x200c); | 
|  | 383 | this->memory_.SetData64(0x8014, 0x5000); | 
|  | 384 | this->memory_.SetData64(0x801c, 0x300); | 
|  | 385 |  | 
|  | 386 | const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x8000); | 
|  | 387 | ASSERT_TRUE(fde != nullptr); | 
|  | 388 | EXPECT_EQ(0x8024U, fde->cfa_instructions_offset); | 
|  | 389 | EXPECT_EQ(0x820cU, fde->cfa_instructions_end); | 
| Christopher Ferris | c3d79f7 | 2017-11-28 19:14:54 -0800 | [diff] [blame] | 390 | EXPECT_EQ(0xd018U, fde->pc_start); | 
|  | 391 | EXPECT_EQ(0xd318U, fde->pc_end); | 
| Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 392 | EXPECT_EQ(0x6000U, fde->cie_offset); | 
|  | 393 | EXPECT_EQ(0U, fde->lsda_address); | 
|  | 394 |  | 
|  | 395 | ASSERT_TRUE(fde->cie != nullptr); | 
|  | 396 | EXPECT_EQ(1U, fde->cie->version); | 
|  | 397 | EXPECT_EQ(DW_EH_PE_sdata8, fde->cie->fde_address_encoding); | 
|  | 398 | EXPECT_EQ(DW_EH_PE_omit, fde->cie->lsda_encoding); | 
|  | 399 | EXPECT_EQ(0U, fde->cie->segment_size); | 
|  | 400 | EXPECT_EQ(1U, fde->cie->augmentation_string.size()); | 
|  | 401 | EXPECT_EQ('\0', fde->cie->augmentation_string[0]); | 
|  | 402 | EXPECT_EQ(0U, fde->cie->personality_handler); | 
|  | 403 | EXPECT_EQ(0x6019U, fde->cie->cfa_instructions_offset); | 
|  | 404 | EXPECT_EQ(0x610cU, fde->cie->cfa_instructions_end); | 
|  | 405 | EXPECT_EQ(4U, fde->cie->code_alignment_factor); | 
|  | 406 | EXPECT_EQ(8, fde->cie->data_alignment_factor); | 
|  | 407 | EXPECT_EQ(0x20U, fde->cie->return_address_register); | 
|  | 408 | } | 
|  | 409 |  | 
|  | 410 | TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeFromPc_fde_not_found) { | 
|  | 411 | this->eh_frame_->TestSetTableEntrySize(16); | 
|  | 412 | this->eh_frame_->TestSetFdeCount(1); | 
|  | 413 |  | 
|  | 414 | typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info; | 
|  | 415 | info.pc = 0x550; | 
|  | 416 | info.offset = 0x10500; | 
|  | 417 | this->eh_frame_->TestSetFdeInfo(0, info); | 
|  | 418 |  | 
|  | 419 | ASSERT_EQ(nullptr, this->eh_frame_->GetFdeFromPc(0x800)); | 
|  | 420 | } | 
|  | 421 |  | 
|  | 422 | REGISTER_TYPED_TEST_CASE_P(DwarfEhFrameWithHdrTest, Init, GetFdeInfoFromIndex_expect_cache_fail, | 
|  | 423 | GetFdeInfoFromIndex_read_pcrel, GetFdeInfoFromIndex_read_datarel, | 
|  | 424 | GetFdeInfoFromIndex_cached, GetFdeOffsetBinary_verify, | 
| Christopher Ferris | d96cbae | 2017-11-08 11:01:18 -0800 | [diff] [blame] | 425 | GetFdeOffsetBinary_index_fail, GetFdeOffsetSequential, | 
|  | 426 | GetFdeOffsetSequential_last_element, GetFdeOffsetSequential_end_check, | 
|  | 427 | GetFdeOffsetFromPc_fail_fde_count, GetFdeOffsetFromPc_binary_search, | 
|  | 428 | GetFdeOffsetFromPc_sequential_search, GetCieFde32, GetCieFde64, | 
|  | 429 | GetFdeFromPc_fde_not_found); | 
| Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 430 |  | 
|  | 431 | typedef ::testing::Types<uint32_t, uint64_t> DwarfEhFrameWithHdrTestTypes; | 
|  | 432 | INSTANTIATE_TYPED_TEST_CASE_P(, DwarfEhFrameWithHdrTest, DwarfEhFrameWithHdrTestTypes); | 
|  | 433 |  | 
|  | 434 | }  // namespace unwindstack |