• 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 "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:
Elf(Memory * memory)37   Elf(Memory* memory) : memory_(memory) {}
38   virtual ~Elf() = default;
39 
40   bool Init();
41 
42   void InitGnuDebugdata();
43 
GetSoname(std::string * name)44   bool GetSoname(std::string* name) {
45     return valid_ && interface_->GetSoname(name);
46   }
47 
GetFunctionName(uint64_t,std::string *,uint64_t *)48   bool GetFunctionName(uint64_t, std::string*, uint64_t*) {
49     return false;
50   }
51 
Step(uint64_t rel_pc,Regs * regs,Memory * process_memory)52   bool Step(uint64_t rel_pc, Regs* regs, Memory* process_memory) {
53     return valid_ && interface_->Step(rel_pc, regs, process_memory);
54   }
55 
56   ElfInterface* CreateInterfaceFromMemory(Memory* memory);
57 
valid()58   bool valid() { return valid_; }
59 
machine_type()60   uint32_t machine_type() { return machine_type_; }
61 
class_type()62   uint8_t class_type() { return class_type_; }
63 
memory()64   Memory* memory() { return memory_.get(); }
65 
interface()66   ElfInterface* interface() { return interface_.get(); }
67 
68   static bool IsValidElf(Memory* memory);
69 
70  protected:
71   bool valid_ = false;
72   std::unique_ptr<ElfInterface> interface_;
73   std::unique_ptr<Memory> memory_;
74   uint32_t machine_type_;
75   uint8_t class_type_;
76 };
77 
78 #endif  // _LIBUNWINDSTACK_ELF_H
79