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