| Christopher Ferris | 72a6fa6 | 2017-03-21 12:41:17 -0700 | [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_DWARF_MEMORY_H | 
|  | 18 | #define _LIBUNWINDSTACK_DWARF_MEMORY_H | 
|  | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 |  | 
|  | 22 | // Forward declarations. | 
|  | 23 | class Memory; | 
|  | 24 |  | 
|  | 25 | class DwarfMemory { | 
|  | 26 | public: | 
|  | 27 | DwarfMemory(Memory* memory) : memory_(memory) {} | 
|  | 28 | virtual ~DwarfMemory() = default; | 
|  | 29 |  | 
|  | 30 | bool ReadBytes(void* dst, size_t num_bytes); | 
|  | 31 |  | 
|  | 32 | template <typename SignedType> | 
|  | 33 | bool ReadSigned(uint64_t* value); | 
|  | 34 |  | 
|  | 35 | bool ReadULEB128(uint64_t* value); | 
|  | 36 |  | 
|  | 37 | bool ReadSLEB128(int64_t* value); | 
|  | 38 |  | 
|  | 39 | template <typename AddressType> | 
|  | 40 | size_t GetEncodedSize(uint8_t encoding); | 
|  | 41 |  | 
|  | 42 | bool AdjustEncodedValue(uint8_t encoding, uint64_t* value); | 
|  | 43 |  | 
|  | 44 | template <typename AddressType> | 
|  | 45 | bool ReadEncodedValue(uint8_t encoding, uint64_t* value); | 
|  | 46 |  | 
|  | 47 | uint64_t cur_offset() { return cur_offset_; } | 
|  | 48 | void set_cur_offset(uint64_t cur_offset) { cur_offset_ = cur_offset; } | 
|  | 49 |  | 
|  | 50 | void set_pc_offset(uint64_t offset) { pc_offset_ = offset; } | 
|  | 51 | void clear_pc_offset() { pc_offset_ = static_cast<uint64_t>(-1); } | 
|  | 52 |  | 
|  | 53 | void set_data_offset(uint64_t offset) { data_offset_ = offset; } | 
|  | 54 | void clear_data_offset() { data_offset_ = static_cast<uint64_t>(-1); } | 
|  | 55 |  | 
|  | 56 | void set_func_offset(uint64_t offset) { func_offset_ = offset; } | 
|  | 57 | void clear_func_offset() { func_offset_ = static_cast<uint64_t>(-1); } | 
|  | 58 |  | 
|  | 59 | void set_text_offset(uint64_t offset) { text_offset_ = offset; } | 
|  | 60 | void clear_text_offset() { text_offset_ = static_cast<uint64_t>(-1); } | 
|  | 61 |  | 
|  | 62 | private: | 
|  | 63 | Memory* memory_; | 
|  | 64 | uint64_t cur_offset_ = 0; | 
|  | 65 |  | 
|  | 66 | uint64_t pc_offset_ = static_cast<uint64_t>(-1); | 
|  | 67 | uint64_t data_offset_ = static_cast<uint64_t>(-1); | 
|  | 68 | uint64_t func_offset_ = static_cast<uint64_t>(-1); | 
|  | 69 | uint64_t text_offset_ = static_cast<uint64_t>(-1); | 
|  | 70 | }; | 
|  | 71 |  | 
|  | 72 | #endif  // _LIBUNWINDSTACK_DWARF_MEMORY_H |