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