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