blob: e3e9ca885790aac915e6c7205102d22397705b53 [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#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 Ferris92acaac2018-06-21 10:44:02 -070024#include <unwindstack/DwarfSection.h>
Christopher Ferrisc9dee842017-11-03 14:50:27 -070025
26namespace unwindstack {
27
28// Forward declarations.
29class Memory;
30
31template <typename AddressType>
Christopher Ferris92acaac2018-06-21 10:44:02 -070032class DwarfEhFrameWithHdr : public DwarfSectionImpl<AddressType> {
Christopher Ferrisc9dee842017-11-03 14:50:27 -070033 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 Ferris92acaac2018-06-21 10:44:02 -070037 using DwarfSectionImpl<AddressType>::pc_offset_;
Christopher Ferrisc9dee842017-11-03 14:50:27 -070038 using DwarfSectionImpl<AddressType>::entries_offset_;
39 using DwarfSectionImpl<AddressType>::entries_end_;
40 using DwarfSectionImpl<AddressType>::last_error_;
Christopher Ferris4cc36d22018-06-06 14:47:31 -070041 using DwarfSectionImpl<AddressType>::load_bias_;
Christopher Ferrisc9dee842017-11-03 14:50:27 -070042
43 struct FdeInfo {
44 AddressType pc;
45 uint64_t offset;
46 };
47
Christopher Ferris92acaac2018-06-21 10:44:02 -070048 DwarfEhFrameWithHdr(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {}
Christopher Ferrisc9dee842017-11-03 14:50:27 -070049 virtual ~DwarfEhFrameWithHdr() = default;
50
Christopher Ferris92acaac2018-06-21 10:44:02 -070051 uint64_t GetCieOffsetFromFde32(uint32_t pointer) override {
52 return this->memory_.cur_offset() - pointer - 4;
53 }
54
55 uint64_t GetCieOffsetFromFde64(uint64_t pointer) override {
56 return this->memory_.cur_offset() - pointer - 8;
57 }
58
59 uint64_t AdjustPcFromFde(uint64_t pc) override {
60 // The eh_frame uses relative pcs.
61 return pc + this->memory_.cur_offset() - 4;
62 }
63
Christopher Ferris4cc36d22018-06-06 14:47:31 -070064 bool Init(uint64_t offset, uint64_t size, uint64_t load_bias) override;
Christopher Ferrisc9dee842017-11-03 14:50:27 -070065
Christopher Ferris92acaac2018-06-21 10:44:02 -070066 const DwarfFde* GetFdeFromPc(uint64_t pc) override;
Christopher Ferrisc9dee842017-11-03 14:50:27 -070067
Christopher Ferris92acaac2018-06-21 10:44:02 -070068 bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset);
Christopher Ferrisc9dee842017-11-03 14:50:27 -070069
70 const FdeInfo* GetFdeInfoFromIndex(size_t index);
71
72 bool GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset);
73
74 bool GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset, uint64_t total_entries);
75
Christopher Ferris92acaac2018-06-21 10:44:02 -070076 void GetFdes(std::vector<const DwarfFde*>* fdes) override;
77
Christopher Ferrisc9dee842017-11-03 14:50:27 -070078 protected:
79 uint8_t version_;
80 uint8_t ptr_encoding_;
81 uint8_t table_encoding_;
82 size_t table_entry_size_;
83
84 uint64_t ptr_offset_;
85
86 uint64_t entries_data_offset_;
87 uint64_t cur_entries_offset_ = 0;
88
Christopher Ferris92acaac2018-06-21 10:44:02 -070089 uint64_t fde_count_;
Christopher Ferrisc9dee842017-11-03 14:50:27 -070090 std::unordered_map<uint64_t, FdeInfo> fde_info_;
91};
92
93} // namespace unwindstack
94
95#endif // _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H