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