ElfInterfaceArm.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_ELF_INTERFACE_ARM_H
  17. #define _LIBUNWINDSTACK_ELF_INTERFACE_ARM_H
  18. #include <elf.h>
  19. #include <stdint.h>
  20. #include <iterator>
  21. #include <unordered_map>
  22. #include <unwindstack/ElfInterface.h>
  23. #include <unwindstack/Memory.h>
  24. namespace unwindstack {
  25. class ElfInterfaceArm : public ElfInterface32 {
  26. public:
  27. ElfInterfaceArm(Memory* memory) : ElfInterface32(memory) {}
  28. virtual ~ElfInterfaceArm() = default;
  29. class iterator : public std::iterator<std::bidirectional_iterator_tag, uint32_t> {
  30. public:
  31. iterator(ElfInterfaceArm* interface, size_t index) : interface_(interface), index_(index) { }
  32. iterator& operator++() { index_++; return *this; }
  33. iterator& operator++(int increment) { index_ += increment; return *this; }
  34. iterator& operator--() { index_--; return *this; }
  35. iterator& operator--(int decrement) { index_ -= decrement; return *this; }
  36. bool operator==(const iterator& rhs) { return this->index_ == rhs.index_; }
  37. bool operator!=(const iterator& rhs) { return this->index_ != rhs.index_; }
  38. uint32_t operator*() {
  39. uint32_t addr = interface_->addrs_[index_];
  40. if (addr == 0) {
  41. if (!interface_->GetPrel31Addr(interface_->start_offset_ + index_ * 8, &addr)) {
  42. return 0;
  43. }
  44. interface_->addrs_[index_] = addr;
  45. }
  46. return addr;
  47. }
  48. private:
  49. ElfInterfaceArm* interface_ = nullptr;
  50. size_t index_ = 0;
  51. };
  52. iterator begin() { return iterator(this, 0); }
  53. iterator end() { return iterator(this, total_entries_); }
  54. bool Init(uint64_t* load_bias) override;
  55. bool GetPrel31Addr(uint32_t offset, uint32_t* addr);
  56. bool FindEntry(uint32_t pc, uint64_t* entry_offset);
  57. void HandleUnknownType(uint32_t type, uint64_t ph_offset, uint64_t ph_filesz) override;
  58. bool Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished) override;
  59. bool StepExidx(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished);
  60. bool GetFunctionName(uint64_t addr, std::string* name, uint64_t* offset) override;
  61. uint64_t start_offset() { return start_offset_; }
  62. size_t total_entries() { return total_entries_; }
  63. void set_load_bias(uint64_t load_bias) { load_bias_ = load_bias; }
  64. protected:
  65. uint64_t start_offset_ = 0;
  66. size_t total_entries_ = 0;
  67. uint64_t load_bias_ = 0;
  68. std::unordered_map<size_t, uint32_t> addrs_;
  69. };
  70. } // namespace unwindstack
  71. #endif // _LIBUNWINDSTACK_ELF_INTERFACE_ARM_H