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 <elf.h> 20 #include <stdint.h> 21 22 #include <iterator> 23 #include <unordered_map> 24 25 #include <unwindstack/ElfInterface.h> 26 #include <unwindstack/Memory.h> 27 28 namespace unwindstack { 29 30 class ElfInterfaceArm : public ElfInterface32 { 31 public: ElfInterfaceArm(Memory * memory)32 ElfInterfaceArm(Memory* memory) : ElfInterface32(memory) {} 33 virtual ~ElfInterfaceArm() = default; 34 35 class iterator : public std::iterator<std::bidirectional_iterator_tag, uint32_t> { 36 public: iterator(ElfInterfaceArm * interface,size_t index)37 iterator(ElfInterfaceArm* interface, size_t index) : interface_(interface), index_(index) { } 38 39 iterator& operator++() { index_++; return *this; } 40 iterator& operator++(int increment) { index_ += increment; return *this; } 41 iterator& operator--() { index_--; return *this; } 42 iterator& operator--(int decrement) { index_ -= decrement; return *this; } 43 44 bool operator==(const iterator& rhs) { return this->index_ == rhs.index_; } 45 bool operator!=(const iterator& rhs) { return this->index_ != rhs.index_; } 46 47 uint32_t operator*() { 48 uint32_t addr = interface_->addrs_[index_]; 49 if (addr == 0) { 50 if (!interface_->GetPrel31Addr(interface_->start_offset_ + index_ * 8, &addr)) { 51 return 0; 52 } 53 interface_->addrs_[index_] = addr; 54 } 55 return addr; 56 } 57 58 private: 59 ElfInterfaceArm* interface_ = nullptr; 60 size_t index_ = 0; 61 }; 62 begin()63 iterator begin() { return iterator(this, 0); } end()64 iterator end() { return iterator(this, total_entries_); } 65 66 bool Init(int64_t* section_bias) override; 67 68 bool GetPrel31Addr(uint32_t offset, uint32_t* addr); 69 70 bool FindEntry(uint32_t pc, uint64_t* entry_offset); 71 72 void HandleUnknownType(uint32_t type, uint64_t ph_offset, uint64_t ph_filesz) override; 73 74 bool Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished, 75 bool* is_signal_frame) override; 76 77 bool StepExidx(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished); 78 79 bool GetFunctionName(uint64_t addr, SharedString* name, uint64_t* offset) override; 80 start_offset()81 uint64_t start_offset() { return start_offset_; } 82 total_entries()83 size_t total_entries() { return total_entries_; } 84 set_load_bias(uint64_t load_bias)85 void set_load_bias(uint64_t load_bias) { load_bias_ = load_bias; } 86 87 protected: 88 uint64_t start_offset_ = 0; 89 size_t total_entries_ = 0; 90 uint64_t load_bias_ = 0; 91 92 std::unordered_map<size_t, uint32_t> addrs_; 93 }; 94 95 } // namespace unwindstack 96