blob: 565b13f1de5cc957a174021bd9841fd58e0e73a1 [file] [log] [blame]
Christopher Ferrisf6f691b2017-09-25 19:23:07 -07001/*
2 * Copyright (C) 2017 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_TESTS_ELF_FAKE_H
18#define _LIBUNWINDSTACK_TESTS_ELF_FAKE_H
19
20#include <stdint.h>
21
22#include <deque>
23#include <string>
24
25#include <unwindstack/Elf.h>
26#include <unwindstack/ElfInterface.h>
27#include <unwindstack/Memory.h>
28#include <unwindstack/Regs.h>
29
Christopher Ferrise69f4702017-10-19 16:08:58 -070030#include "ElfInterfaceArm.h"
31
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070032namespace unwindstack {
33
34struct StepData {
35 StepData(uint64_t pc, uint64_t sp, bool finished) : pc(pc), sp(sp), finished(finished) {}
36 uint64_t pc;
37 uint64_t sp;
38 bool finished;
39};
40
41struct FunctionData {
42 FunctionData(std::string name, uint64_t offset) : name(name), offset(offset) {}
43
44 std::string name;
45 uint64_t offset;
46};
47
48class ElfFake : public Elf {
49 public:
50 ElfFake(Memory* memory) : Elf(memory) { valid_ = true; }
51 virtual ~ElfFake() = default;
52
Christopher Ferrise69f4702017-10-19 16:08:58 -070053 void FakeSetValid(bool valid) { valid_ = valid; }
54
55 void FakeSetLoadBias(uint64_t load_bias) { load_bias_ = load_bias; }
56
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070057 void FakeSetInterface(ElfInterface* interface) { interface_.reset(interface); }
58};
59
60class ElfInterfaceFake : public ElfInterface {
61 public:
62 ElfInterfaceFake(Memory* memory) : ElfInterface(memory) {}
63 virtual ~ElfInterfaceFake() = default;
64
Christopher Ferrise69f4702017-10-19 16:08:58 -070065 bool Init(uint64_t*) override { return false; }
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070066 void InitHeaders() override {}
67 bool GetSoname(std::string*) override { return false; }
68
Christopher Ferrise69f4702017-10-19 16:08:58 -070069 bool GetFunctionName(uint64_t, uint64_t, std::string*, uint64_t*) override;
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070070
71 bool Step(uint64_t, Regs*, Memory*, bool*) override;
72
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070073
74 static void FakePushFunctionData(const FunctionData data) { functions_.push_back(data); }
75 static void FakePushStepData(const StepData data) { steps_.push_back(data); }
76
77 static void FakeClear() {
78 functions_.clear();
79 steps_.clear();
80 }
81
82 private:
83 static std::deque<FunctionData> functions_;
84 static std::deque<StepData> steps_;
85};
86
Christopher Ferrise69f4702017-10-19 16:08:58 -070087class ElfInterface32Fake : public ElfInterface32 {
88 public:
89 ElfInterface32Fake(Memory* memory) : ElfInterface32(memory) {}
90 virtual ~ElfInterface32Fake() = default;
91
92 void FakeSetEhFrameOffset(uint64_t offset) { eh_frame_offset_ = offset; }
93 void FakeSetEhFrameSize(uint64_t size) { eh_frame_size_ = size; }
94 void FakeSetDebugFrameOffset(uint64_t offset) { debug_frame_offset_ = offset; }
95 void FakeSetDebugFrameSize(uint64_t size) { debug_frame_size_ = size; }
96};
97
98class ElfInterface64Fake : public ElfInterface64 {
99 public:
100 ElfInterface64Fake(Memory* memory) : ElfInterface64(memory) {}
101 virtual ~ElfInterface64Fake() = default;
102
103 void FakeSetEhFrameOffset(uint64_t offset) { eh_frame_offset_ = offset; }
104 void FakeSetEhFrameSize(uint64_t size) { eh_frame_size_ = size; }
105 void FakeSetDebugFrameOffset(uint64_t offset) { debug_frame_offset_ = offset; }
106 void FakeSetDebugFrameSize(uint64_t size) { debug_frame_size_ = size; }
107};
108
109class ElfInterfaceArmFake : public ElfInterfaceArm {
110 public:
111 ElfInterfaceArmFake(Memory* memory) : ElfInterfaceArm(memory) {}
112 virtual ~ElfInterfaceArmFake() = default;
113
114 void FakeSetStartOffset(uint64_t offset) { start_offset_ = offset; }
115 void FakeSetTotalEntries(size_t entries) { total_entries_ = entries; }
116};
117
Christopher Ferrisf6f691b2017-09-25 19:23:07 -0700118} // namespace unwindstack
119
120#endif // _LIBUNWINDSTACK_TESTS_ELF_FAKE_H