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