blob: 4240419a553847bf77badd59bdf053b8663b75fb [file] [log] [blame]
Christopher Ferrisc9dee842017-11-03 14:50:27 -07001/*
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
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -080022#include <unwindstack/DwarfError.h>
23
Christopher Ferrisc9dee842017-11-03 14:50:27 -070024#include "DwarfEhFrameWithHdr.h"
25#include "DwarfEncoding.h"
Christopher Ferrisc9dee842017-11-03 14:50:27 -070026
27#include "LogFake.h"
28#include "MemoryFake.h"
29
30namespace unwindstack {
31
32template <typename TypeParam>
33class MockDwarfEhFrameWithHdr : public DwarfEhFrameWithHdr<TypeParam> {
34 public:
35 MockDwarfEhFrameWithHdr(Memory* memory) : DwarfEhFrameWithHdr<TypeParam>(memory) {}
36 ~MockDwarfEhFrameWithHdr() = default;
37
38 void TestSetTableEncoding(uint8_t encoding) { this->table_encoding_ = encoding; }
39 void TestSetEntriesOffset(uint64_t offset) { this->entries_offset_ = offset; }
40 void TestSetEntriesEnd(uint64_t end) { this->entries_end_ = end; }
41 void TestSetEntriesDataOffset(uint64_t offset) { this->entries_data_offset_ = offset; }
42 void TestSetCurEntriesOffset(uint64_t offset) { this->cur_entries_offset_ = offset; }
43 void TestSetTableEntrySize(size_t size) { this->table_entry_size_ = size; }
44
45 void TestSetFdeCount(uint64_t count) { this->fde_count_ = count; }
46 void TestSetFdeInfo(uint64_t index, const typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo& info) {
47 this->fde_info_[index] = info;
48 }
49
50 uint8_t TestGetVersion() { return this->version_; }
51 uint8_t TestGetPtrEncoding() { return this->ptr_encoding_; }
52 uint64_t TestGetPtrOffset() { return this->ptr_offset_; }
53 uint8_t TestGetTableEncoding() { return this->table_encoding_; }
54 uint64_t TestGetTableEntrySize() { return this->table_entry_size_; }
55 uint64_t TestGetFdeCount() { return this->fde_count_; }
56 uint64_t TestGetEntriesOffset() { return this->entries_offset_; }
57 uint64_t TestGetEntriesEnd() { return this->entries_end_; }
58 uint64_t TestGetEntriesDataOffset() { return this->entries_data_offset_; }
59 uint64_t TestGetCurEntriesOffset() { return this->cur_entries_offset_; }
60};
61
62template <typename TypeParam>
63class DwarfEhFrameWithHdrTest : public ::testing::Test {
64 protected:
65 void SetUp() override {
66 memory_.Clear();
67 eh_frame_ = new MockDwarfEhFrameWithHdr<TypeParam>(&memory_);
68 ResetLogs();
69 }
70
71 void TearDown() override { delete eh_frame_; }
72
73 MemoryFake memory_;
74 MockDwarfEhFrameWithHdr<TypeParam>* eh_frame_ = nullptr;
75};
76TYPED_TEST_CASE_P(DwarfEhFrameWithHdrTest);
77
78// NOTE: All test class variables need to be referenced as this->.
79
80TYPED_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
Christopher Ferris1a141a02018-01-24 08:52:47 -080098 // Verify a zero fde count fails to init.
99 this->memory_.SetData32(0x1006, 0);
100 ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800101 ASSERT_EQ(DWARF_ERROR_NO_FDES, this->eh_frame_->LastErrorCode());
Christopher Ferris1a141a02018-01-24 08:52:47 -0800102
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700103 // Verify an unexpected version will cause a fail.
Christopher Ferris1a141a02018-01-24 08:52:47 -0800104 this->memory_.SetData32(0x1006, 126);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700105 this->memory_.SetData8(0x1000, 0);
106 ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800107 ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->LastErrorCode());
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700108 this->memory_.SetData8(0x1000, 2);
109 ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800110 ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->LastErrorCode());
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700111}
112
113TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_expect_cache_fail) {
114 this->eh_frame_->TestSetTableEntrySize(0x10);
115 this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800116 this->eh_frame_->TestSetEntriesOffset(0x1000);
117
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700118 ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800119 ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->LastErrorCode());
120 EXPECT_EQ(0x1000U, this->eh_frame_->LastErrorAddress());
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700121 ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800122 ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->LastErrorCode());
123 EXPECT_EQ(0x1000U, this->eh_frame_->LastErrorAddress());
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700124}
125
126TYPED_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);
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800137 EXPECT_EQ(0x1380U, info->pc);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700138 EXPECT_EQ(0x1540U, info->offset);
139}
140
141TYPED_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);
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800152 EXPECT_EQ(0x3340U, info->pc);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700153 EXPECT_EQ(0x3500U, info->offset);
154}
155
156TYPED_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);
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800166 EXPECT_EQ(0x340U, info->pc);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700167 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);
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800174 EXPECT_EQ(0x340U, info->pc);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700175 EXPECT_EQ(0x500U, info->offset);
176}
177
178TYPED_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.
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800192 ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700193 // 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
Christopher Ferrisd96cbae2017-11-08 11:01:18 -0800219TYPED_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
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700227TYPED_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
256TYPED_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
274TYPED_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));
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800288 ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700289}
290
291TYPED_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));
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -0800296 ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->LastErrorCode());
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700297}
298
299TYPED_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
319TYPED_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
339TYPED_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);
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800359 EXPECT_EQ(0x1d008U, fde->pc_start);
360 EXPECT_EQ(0x1d108U, fde->pc_end);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700361 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
379TYPED_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);
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800401 EXPECT_EQ(0xd018U, fde->pc_start);
402 EXPECT_EQ(0xd318U, fde->pc_end);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700403 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
421TYPED_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
433REGISTER_TYPED_TEST_CASE_P(DwarfEhFrameWithHdrTest, Init, GetFdeInfoFromIndex_expect_cache_fail,
434 GetFdeInfoFromIndex_read_pcrel, GetFdeInfoFromIndex_read_datarel,
435 GetFdeInfoFromIndex_cached, GetFdeOffsetBinary_verify,
Christopher Ferrisd96cbae2017-11-08 11:01:18 -0800436 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);
Christopher Ferrisc9dee842017-11-03 14:50:27 -0700441
442typedef ::testing::Types<uint32_t, uint64_t> DwarfEhFrameWithHdrTestTypes;
443INSTANTIATE_TYPED_TEST_CASE_P(, DwarfEhFrameWithHdrTest, DwarfEhFrameWithHdrTestTypes);
444
445} // namespace unwindstack