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 | #ifndef _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H |
| 18 | #define _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <unordered_map> |
| 23 | |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 24 | #include <unwindstack/DwarfSection.h> |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 25 | |
| 26 | namespace unwindstack { |
| 27 | |
| 28 | // Forward declarations. |
| 29 | class Memory; |
| 30 | |
| 31 | template <typename AddressType> |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 32 | class DwarfEhFrameWithHdr : public DwarfSectionImpl<AddressType> { |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 33 | public: |
| 34 | // Add these so that the protected members of DwarfSectionImpl |
| 35 | // can be accessed without needing a this->. |
| 36 | using DwarfSectionImpl<AddressType>::memory_; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 37 | using DwarfSectionImpl<AddressType>::last_error_; |
| 38 | |
| 39 | struct FdeInfo { |
| 40 | AddressType pc; |
| 41 | uint64_t offset; |
| 42 | }; |
| 43 | |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 44 | DwarfEhFrameWithHdr(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {} |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 45 | virtual ~DwarfEhFrameWithHdr() = default; |
| 46 | |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 47 | uint64_t GetCieOffsetFromFde32(uint32_t pointer) override { |
Christopher Ferris | 4ca98e1 | 2019-10-29 10:21:11 -0700 | [diff] [blame] | 48 | return memory_.cur_offset() - pointer - 4; |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | uint64_t GetCieOffsetFromFde64(uint64_t pointer) override { |
Christopher Ferris | 4ca98e1 | 2019-10-29 10:21:11 -0700 | [diff] [blame] | 52 | return memory_.cur_offset() - pointer - 8; |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | uint64_t AdjustPcFromFde(uint64_t pc) override { |
| 56 | // The eh_frame uses relative pcs. |
Christopher Ferris | 4ca98e1 | 2019-10-29 10:21:11 -0700 | [diff] [blame] | 57 | return pc + memory_.cur_offset() - 4; |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Christopher Ferris | 4ca98e1 | 2019-10-29 10:21:11 -0700 | [diff] [blame] | 60 | bool EhFrameInit(uint64_t offset, uint64_t size, int64_t section_bias); |
Christopher Ferris | 819f131 | 2019-10-03 13:35:48 -0700 | [diff] [blame] | 61 | bool Init(uint64_t offset, uint64_t size, int64_t section_bias) override; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 62 | |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 63 | const DwarfFde* GetFdeFromPc(uint64_t pc) override; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 64 | |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 65 | bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset); |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 66 | |
| 67 | const FdeInfo* GetFdeInfoFromIndex(size_t index); |
| 68 | |
Christopher Ferris | 92acaac | 2018-06-21 10:44:02 -0700 | [diff] [blame] | 69 | void GetFdes(std::vector<const DwarfFde*>* fdes) override; |
| 70 | |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 71 | protected: |
Christopher Ferris | 4ca98e1 | 2019-10-29 10:21:11 -0700 | [diff] [blame] | 72 | uint8_t version_ = 0; |
| 73 | uint8_t table_encoding_ = 0; |
| 74 | size_t table_entry_size_ = 0; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 75 | |
Christopher Ferris | 4ca98e1 | 2019-10-29 10:21:11 -0700 | [diff] [blame] | 76 | uint64_t hdr_entries_offset_ = 0; |
| 77 | uint64_t hdr_entries_data_offset_ = 0; |
| 78 | uint64_t hdr_section_bias_ = 0; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 79 | |
Christopher Ferris | 4ca98e1 | 2019-10-29 10:21:11 -0700 | [diff] [blame] | 80 | uint64_t fde_count_ = 0; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 81 | std::unordered_map<uint64_t, FdeInfo> fde_info_; |
| 82 | }; |
| 83 | |
| 84 | } // namespace unwindstack |
| 85 | |
| 86 | #endif // _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H |