blob: 7bf45b842b437a9f92e7303a4f2b11ab6349607c [file] [log] [blame]
Christopher Ferris3958f802017-02-01 15:44:40 -08001/*
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.
33class Regs;
34
35class Elf {
36 public:
37 Elf(Memory* memory) : memory_(memory) {}
38 virtual ~Elf() = default;
39
40 bool Init();
41
42 void InitGnuDebugdata();
43
44 bool GetSoname(std::string* name) {
45 return valid_ && interface_->GetSoname(name);
46 }
47
48 bool GetFunctionName(uint64_t, std::string*, uint64_t*) {
49 return false;
50 }
51
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
58 bool valid() { return valid_; }
59
60 uint32_t machine_type() { return machine_type_; }
61
62 uint8_t class_type() { return class_type_; }
63
64 Memory* memory() { return memory_.get(); }
65
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