Home | History | Annotate | Download | only in unwindstack
      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 namespace unwindstack {
     23 
     24 // Forward declarations.
     25 class Memory;
     26 
     27 class DwarfMemory {
     28  public:
     29   DwarfMemory(Memory* memory) : memory_(memory) {}
     30   virtual ~DwarfMemory() = default;
     31 
     32   bool ReadBytes(void* dst, size_t num_bytes);
     33 
     34   template <typename SignedType>
     35   bool ReadSigned(uint64_t* value);
     36 
     37   bool ReadULEB128(uint64_t* value);
     38 
     39   bool ReadSLEB128(int64_t* value);
     40 
     41   template <typename AddressType>
     42   size_t GetEncodedSize(uint8_t encoding);
     43 
     44   bool AdjustEncodedValue(uint8_t encoding, uint64_t* value);
     45 
     46   template <typename AddressType>
     47   bool ReadEncodedValue(uint8_t encoding, uint64_t* value);
     48 
     49   uint64_t cur_offset() { return cur_offset_; }
     50   void set_cur_offset(uint64_t cur_offset) { cur_offset_ = cur_offset; }
     51 
     52   void set_pc_offset(uint64_t offset) { pc_offset_ = offset; }
     53   void clear_pc_offset() { pc_offset_ = static_cast<uint64_t>(-1); }
     54 
     55   void set_data_offset(uint64_t offset) { data_offset_ = offset; }
     56   void clear_data_offset() { data_offset_ = static_cast<uint64_t>(-1); }
     57 
     58   void set_func_offset(uint64_t offset) { func_offset_ = offset; }
     59   void clear_func_offset() { func_offset_ = static_cast<uint64_t>(-1); }
     60 
     61   void set_text_offset(uint64_t offset) { text_offset_ = offset; }
     62   void clear_text_offset() { text_offset_ = static_cast<uint64_t>(-1); }
     63 
     64  private:
     65   Memory* memory_;
     66   uint64_t cur_offset_ = 0;
     67 
     68   uint64_t pc_offset_ = static_cast<uint64_t>(-1);
     69   uint64_t data_offset_ = static_cast<uint64_t>(-1);
     70   uint64_t func_offset_ = static_cast<uint64_t>(-1);
     71   uint64_t text_offset_ = static_cast<uint64_t>(-1);
     72 };
     73 
     74 }  // namespace unwindstack
     75 
     76 #endif  // _LIBUNWINDSTACK_DWARF_MEMORY_H
     77