DwarfEhFrameWithHdr.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #ifndef _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H
  17. #define _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H
  18. #include <stdint.h>
  19. #include <unordered_map>
  20. #include <unwindstack/DwarfSection.h>
  21. namespace unwindstack {
  22. // Forward declarations.
  23. class Memory;
  24. template <typename AddressType>
  25. class DwarfEhFrameWithHdr : public DwarfSectionImpl<AddressType> {
  26. public:
  27. // Add these so that the protected members of DwarfSectionImpl
  28. // can be accessed without needing a this->.
  29. using DwarfSectionImpl<AddressType>::memory_;
  30. using DwarfSectionImpl<AddressType>::pc_offset_;
  31. using DwarfSectionImpl<AddressType>::entries_offset_;
  32. using DwarfSectionImpl<AddressType>::entries_end_;
  33. using DwarfSectionImpl<AddressType>::last_error_;
  34. using DwarfSectionImpl<AddressType>::load_bias_;
  35. struct FdeInfo {
  36. AddressType pc;
  37. uint64_t offset;
  38. };
  39. DwarfEhFrameWithHdr(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {}
  40. virtual ~DwarfEhFrameWithHdr() = default;
  41. uint64_t GetCieOffsetFromFde32(uint32_t pointer) override {
  42. return this->memory_.cur_offset() - pointer - 4;
  43. }
  44. uint64_t GetCieOffsetFromFde64(uint64_t pointer) override {
  45. return this->memory_.cur_offset() - pointer - 8;
  46. }
  47. uint64_t AdjustPcFromFde(uint64_t pc) override {
  48. // The eh_frame uses relative pcs.
  49. return pc + this->memory_.cur_offset() - 4;
  50. }
  51. bool Init(uint64_t offset, uint64_t size, uint64_t load_bias) override;
  52. const DwarfFde* GetFdeFromPc(uint64_t pc) override;
  53. bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset);
  54. const FdeInfo* GetFdeInfoFromIndex(size_t index);
  55. void GetFdes(std::vector<const DwarfFde*>* fdes) override;
  56. protected:
  57. uint8_t version_;
  58. uint8_t ptr_encoding_;
  59. uint8_t table_encoding_;
  60. size_t table_entry_size_;
  61. uint64_t ptr_offset_;
  62. uint64_t entries_data_offset_;
  63. uint64_t cur_entries_offset_ = 0;
  64. uint64_t fde_count_;
  65. std::unordered_map<uint64_t, FdeInfo> fde_info_;
  66. };
  67. } // namespace unwindstack
  68. #endif // _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H