| Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -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 | #ifndef _LIBUNWINDSTACK_DWARF_EH_FRAME_H | 
|  | 18 | #define _LIBUNWINDSTACK_DWARF_EH_FRAME_H | 
|  | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 22 | #include <unwindstack/DwarfSection.h> | 
|  | 23 |  | 
|  | 24 | namespace unwindstack { | 
| Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | // Forward declarations. | 
|  | 27 | class Memory; | 
|  | 28 |  | 
|  | 29 | template <typename AddressType> | 
|  | 30 | class DwarfEhFrame : public DwarfSectionImpl<AddressType> { | 
|  | 31 | public: | 
|  | 32 | // Add these so that the protected members of DwarfSectionImpl | 
|  | 33 | // can be accessed without needing a this->. | 
|  | 34 | using DwarfSectionImpl<AddressType>::memory_; | 
|  | 35 | using DwarfSectionImpl<AddressType>::fde_count_; | 
|  | 36 | using DwarfSectionImpl<AddressType>::last_error_; | 
|  | 37 |  | 
|  | 38 | struct FdeInfo { | 
|  | 39 | AddressType pc; | 
|  | 40 | uint64_t offset; | 
|  | 41 | }; | 
|  | 42 |  | 
|  | 43 | DwarfEhFrame(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {} | 
|  | 44 | virtual ~DwarfEhFrame() = default; | 
|  | 45 |  | 
|  | 46 | bool Init(uint64_t offset, uint64_t size) override; | 
|  | 47 |  | 
|  | 48 | bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) override; | 
|  | 49 |  | 
|  | 50 | const DwarfFde* GetFdeFromIndex(size_t index) override; | 
|  | 51 |  | 
|  | 52 | bool IsCie32(uint32_t value32) override { return value32 == 0; } | 
|  | 53 |  | 
|  | 54 | bool IsCie64(uint64_t value64) override { return value64 == 0; } | 
|  | 55 |  | 
|  | 56 | uint64_t GetCieOffsetFromFde32(uint32_t pointer) override { | 
|  | 57 | return memory_.cur_offset() - pointer - 4; | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | uint64_t GetCieOffsetFromFde64(uint64_t pointer) override { | 
|  | 61 | return memory_.cur_offset() - pointer - 8; | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | uint64_t AdjustPcFromFde(uint64_t pc) override { | 
|  | 65 | // The eh_frame uses relative pcs. | 
|  | 66 | return pc + memory_.cur_offset(); | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | const FdeInfo* GetFdeInfoFromIndex(size_t index); | 
|  | 70 |  | 
|  | 71 | bool GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset); | 
|  | 72 |  | 
|  | 73 | bool GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset, uint64_t total_entries); | 
|  | 74 |  | 
|  | 75 | protected: | 
|  | 76 | uint8_t version_; | 
|  | 77 | uint8_t ptr_encoding_; | 
|  | 78 | uint8_t table_encoding_; | 
|  | 79 | size_t table_entry_size_; | 
|  | 80 |  | 
|  | 81 | uint64_t ptr_offset_; | 
|  | 82 |  | 
|  | 83 | uint64_t entries_offset_; | 
|  | 84 | uint64_t entries_end_; | 
|  | 85 | uint64_t entries_data_offset_; | 
|  | 86 | uint64_t cur_entries_offset_ = 0; | 
|  | 87 |  | 
|  | 88 | std::unordered_map<uint64_t, FdeInfo> fde_info_; | 
|  | 89 | }; | 
|  | 90 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 91 | }  // namespace unwindstack | 
|  | 92 |  | 
| Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 93 | #endif  // _LIBUNWINDSTACK_DWARF_EH_FRAME_H |