2017-06-13 04:14:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2018-01-24 02:52:23 +01:00
|
|
|
#include <unwindstack/DwarfError.h>
|
|
|
|
|
2017-06-13 04:14:20 +02:00
|
|
|
#include "DwarfEhFrame.h"
|
|
|
|
#include "DwarfEncoding.h"
|
|
|
|
|
|
|
|
#include "LogFake.h"
|
|
|
|
#include "MemoryFake.h"
|
|
|
|
|
2017-07-14 19:37:19 +02:00
|
|
|
namespace unwindstack {
|
|
|
|
|
2017-06-13 04:14:20 +02:00
|
|
|
template <typename TypeParam>
|
|
|
|
class DwarfEhFrameTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
|
|
|
memory_.Clear();
|
2018-06-21 19:44:02 +02:00
|
|
|
eh_frame_ = new DwarfEhFrame<TypeParam>(&memory_);
|
2017-06-13 04:14:20 +02:00
|
|
|
ResetLogs();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override { delete eh_frame_; }
|
|
|
|
|
|
|
|
MemoryFake memory_;
|
2018-06-21 19:44:02 +02:00
|
|
|
DwarfEhFrame<TypeParam>* eh_frame_ = nullptr;
|
2017-06-13 04:14:20 +02:00
|
|
|
};
|
2019-06-21 01:16:42 +02:00
|
|
|
TYPED_TEST_SUITE_P(DwarfEhFrameTest);
|
2017-06-13 04:14:20 +02:00
|
|
|
|
|
|
|
// NOTE: All test class variables need to be referenced as this->.
|
|
|
|
|
2018-06-21 19:44:02 +02:00
|
|
|
// Only verify different cie/fde format. All other DwarfSection corner
|
|
|
|
// cases are tested in DwarfDebugFrameTest.cpp.
|
|
|
|
|
|
|
|
TYPED_TEST_P(DwarfEhFrameTest, GetFdeCieFromOffset32) {
|
2017-11-03 22:50:27 +01:00
|
|
|
// CIE 32 information.
|
|
|
|
this->memory_.SetData32(0x5000, 0xfc);
|
2018-06-21 19:44:02 +02:00
|
|
|
// Indicates this is a cie for eh_frame.
|
2017-11-03 22:50:27 +01:00
|
|
|
this->memory_.SetData32(0x5004, 0);
|
2018-06-21 19:44:02 +02:00
|
|
|
this->memory_.SetMemory(0x5008, std::vector<uint8_t>{1, '\0', 16, 32, 1});
|
2017-06-13 04:14:20 +02:00
|
|
|
|
2017-11-03 22:50:27 +01:00
|
|
|
// FDE 32 information.
|
|
|
|
this->memory_.SetData32(0x5100, 0xfc);
|
|
|
|
this->memory_.SetData32(0x5104, 0x104);
|
|
|
|
this->memory_.SetData32(0x5108, 0x1500);
|
|
|
|
this->memory_.SetData32(0x510c, 0x200);
|
2017-06-13 04:14:20 +02:00
|
|
|
|
2018-06-21 19:44:02 +02:00
|
|
|
const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x5100);
|
|
|
|
ASSERT_TRUE(fde != nullptr);
|
|
|
|
EXPECT_EQ(0x5000U, fde->cie_offset);
|
|
|
|
EXPECT_EQ(0x5110U, fde->cfa_instructions_offset);
|
|
|
|
EXPECT_EQ(0x5200U, fde->cfa_instructions_end);
|
|
|
|
EXPECT_EQ(0x6608U, fde->pc_start);
|
|
|
|
EXPECT_EQ(0x6808U, fde->pc_end);
|
|
|
|
EXPECT_EQ(0U, fde->lsda_address);
|
2017-06-13 04:14:20 +02:00
|
|
|
|
2018-06-21 19:44:02 +02:00
|
|
|
const DwarfCie* cie = fde->cie;
|
|
|
|
ASSERT_TRUE(cie != nullptr);
|
|
|
|
EXPECT_EQ(1U, cie->version);
|
|
|
|
EXPECT_EQ(DW_EH_PE_sdata4, cie->fde_address_encoding);
|
|
|
|
EXPECT_EQ(DW_EH_PE_omit, cie->lsda_encoding);
|
|
|
|
EXPECT_EQ(0U, cie->segment_size);
|
|
|
|
EXPECT_EQ('\0', cie->augmentation_string[0]);
|
|
|
|
EXPECT_EQ(0U, cie->personality_handler);
|
|
|
|
EXPECT_EQ(0x500dU, cie->cfa_instructions_offset);
|
|
|
|
EXPECT_EQ(0x5100U, cie->cfa_instructions_end);
|
|
|
|
EXPECT_EQ(16U, cie->code_alignment_factor);
|
|
|
|
EXPECT_EQ(32U, cie->data_alignment_factor);
|
|
|
|
EXPECT_EQ(1U, cie->return_address_register);
|
2017-06-13 04:14:20 +02:00
|
|
|
}
|
|
|
|
|
2018-06-21 19:44:02 +02:00
|
|
|
TYPED_TEST_P(DwarfEhFrameTest, GetFdeCieFromOffset64) {
|
2017-11-03 22:50:27 +01:00
|
|
|
// CIE 64 information.
|
|
|
|
this->memory_.SetData32(0x5000, 0xffffffff);
|
2018-06-21 19:44:02 +02:00
|
|
|
this->memory_.SetData64(0x5004, 0xfc);
|
|
|
|
// Indicates this is a cie for eh_frame.
|
2017-11-03 22:50:27 +01:00
|
|
|
this->memory_.SetData64(0x500c, 0);
|
2018-06-21 19:44:02 +02:00
|
|
|
this->memory_.SetMemory(0x5014, std::vector<uint8_t>{1, '\0', 16, 32, 1});
|
2017-11-03 22:50:27 +01:00
|
|
|
|
|
|
|
// FDE 64 information.
|
|
|
|
this->memory_.SetData32(0x5100, 0xffffffff);
|
2018-06-21 19:44:02 +02:00
|
|
|
this->memory_.SetData64(0x5104, 0xfc);
|
2017-11-03 22:50:27 +01:00
|
|
|
this->memory_.SetData64(0x510c, 0x10c);
|
|
|
|
this->memory_.SetData64(0x5114, 0x1500);
|
|
|
|
this->memory_.SetData64(0x511c, 0x200);
|
|
|
|
|
2018-06-21 19:44:02 +02:00
|
|
|
const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x5100);
|
2017-06-13 04:14:20 +02:00
|
|
|
ASSERT_TRUE(fde != nullptr);
|
2018-06-21 19:44:02 +02:00
|
|
|
EXPECT_EQ(0x5000U, fde->cie_offset);
|
|
|
|
EXPECT_EQ(0x5124U, fde->cfa_instructions_offset);
|
|
|
|
EXPECT_EQ(0x5208U, fde->cfa_instructions_end);
|
|
|
|
EXPECT_EQ(0x6618U, fde->pc_start);
|
|
|
|
EXPECT_EQ(0x6818U, fde->pc_end);
|
2017-06-13 04:14:20 +02:00
|
|
|
EXPECT_EQ(0U, fde->lsda_address);
|
|
|
|
|
2018-06-21 19:44:02 +02:00
|
|
|
const DwarfCie* cie = fde->cie;
|
|
|
|
ASSERT_TRUE(cie != nullptr);
|
|
|
|
EXPECT_EQ(1U, cie->version);
|
|
|
|
EXPECT_EQ(DW_EH_PE_sdata8, cie->fde_address_encoding);
|
|
|
|
EXPECT_EQ(DW_EH_PE_omit, cie->lsda_encoding);
|
|
|
|
EXPECT_EQ(0U, cie->segment_size);
|
|
|
|
EXPECT_EQ('\0', cie->augmentation_string[0]);
|
|
|
|
EXPECT_EQ(0U, cie->personality_handler);
|
|
|
|
EXPECT_EQ(0x5019U, cie->cfa_instructions_offset);
|
|
|
|
EXPECT_EQ(0x5108U, cie->cfa_instructions_end);
|
|
|
|
EXPECT_EQ(16U, cie->code_alignment_factor);
|
|
|
|
EXPECT_EQ(32U, cie->data_alignment_factor);
|
|
|
|
EXPECT_EQ(1U, cie->return_address_register);
|
2017-06-13 04:14:20 +02:00
|
|
|
}
|
|
|
|
|
2019-06-21 01:16:42 +02:00
|
|
|
REGISTER_TYPED_TEST_SUITE_P(DwarfEhFrameTest, GetFdeCieFromOffset32, GetFdeCieFromOffset64);
|
2017-06-13 04:14:20 +02:00
|
|
|
|
|
|
|
typedef ::testing::Types<uint32_t, uint64_t> DwarfEhFrameTestTypes;
|
2019-12-11 21:46:20 +01:00
|
|
|
INSTANTIATE_TYPED_TEST_SUITE_P(Libunwindstack, DwarfEhFrameTest, DwarfEhFrameTestTypes);
|
2017-07-14 19:37:19 +02:00
|
|
|
|
|
|
|
} // namespace unwindstack
|