| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 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 | #ifndef _LIBUNWINDSTACK_ELF_H | 
|  | 18 | #define _LIBUNWINDSTACK_ELF_H | 
|  | 19 |  | 
|  | 20 | #include <stddef.h> | 
|  | 21 |  | 
|  | 22 | #include <memory> | 
|  | 23 | #include <string> | 
|  | 24 |  | 
|  | 25 | #include "ElfInterface.h" | 
|  | 26 | #include "Memory.h" | 
|  | 27 |  | 
|  | 28 | #if !defined(EM_AARCH64) | 
|  | 29 | #define EM_AARCH64 183 | 
|  | 30 | #endif | 
|  | 31 |  | 
|  | 32 | // Forward declaration. | 
|  | 33 | class Regs; | 
|  | 34 |  | 
|  | 35 | class Elf { | 
|  | 36 | public: | 
|  | 37 | Elf(Memory* memory) : memory_(memory) {} | 
|  | 38 | virtual ~Elf() = default; | 
|  | 39 |  | 
|  | 40 | bool Init(); | 
|  | 41 |  | 
|  | 42 | void InitGnuDebugdata(); | 
|  | 43 |  | 
|  | 44 | bool GetSoname(std::string* name) { | 
|  | 45 | return valid_ && interface_->GetSoname(name); | 
|  | 46 | } | 
|  | 47 |  | 
| Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 48 | bool GetFunctionName(uint64_t addr, std::string* name, uint64_t* func_offset) { | 
| Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 49 | return valid_ && (interface_->GetFunctionName(addr, name, func_offset) || | 
|  | 50 | (gnu_debugdata_interface_ && | 
|  | 51 | gnu_debugdata_interface_->GetFunctionName(addr, name, func_offset))); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
|  | 54 | bool Step(uint64_t rel_pc, Regs* regs, Memory* process_memory) { | 
| Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 55 | return valid_ && (interface_->Step(rel_pc, regs, process_memory) || | 
|  | 56 | (gnu_debugdata_interface_ && | 
|  | 57 | gnu_debugdata_interface_->Step(rel_pc, regs, process_memory))); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 58 | } | 
|  | 59 |  | 
|  | 60 | ElfInterface* CreateInterfaceFromMemory(Memory* memory); | 
|  | 61 |  | 
|  | 62 | bool valid() { return valid_; } | 
|  | 63 |  | 
|  | 64 | uint32_t machine_type() { return machine_type_; } | 
|  | 65 |  | 
|  | 66 | uint8_t class_type() { return class_type_; } | 
|  | 67 |  | 
|  | 68 | Memory* memory() { return memory_.get(); } | 
|  | 69 |  | 
|  | 70 | ElfInterface* interface() { return interface_.get(); } | 
|  | 71 |  | 
| Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 72 | ElfInterface* gnu_debugdata_interface() { return gnu_debugdata_interface_.get(); } | 
|  | 73 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 74 | static bool IsValidElf(Memory* memory); | 
|  | 75 |  | 
|  | 76 | protected: | 
|  | 77 | bool valid_ = false; | 
|  | 78 | std::unique_ptr<ElfInterface> interface_; | 
|  | 79 | std::unique_ptr<Memory> memory_; | 
|  | 80 | uint32_t machine_type_; | 
|  | 81 | uint8_t class_type_; | 
| Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | std::unique_ptr<Memory> gnu_debugdata_memory_; | 
|  | 84 | std::unique_ptr<ElfInterface> gnu_debugdata_interface_; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 85 | }; | 
|  | 86 |  | 
|  | 87 | #endif  // _LIBUNWINDSTACK_ELF_H |