blob: 4359bca4e30adf31258395415962f379ac44810e [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
30namespace unwindstack {
31
32struct StepData {
33 StepData(uint64_t pc, uint64_t sp, bool finished) : pc(pc), sp(sp), finished(finished) {}
34 uint64_t pc;
35 uint64_t sp;
36 bool finished;
37};
38
39struct FunctionData {
40 FunctionData(std::string name, uint64_t offset) : name(name), offset(offset) {}
41
42 std::string name;
43 uint64_t offset;
44};
45
46class ElfFake : public Elf {
47 public:
48 ElfFake(Memory* memory) : Elf(memory) { valid_ = true; }
49 virtual ~ElfFake() = default;
50
51 void FakeSetInterface(ElfInterface* interface) { interface_.reset(interface); }
52};
53
54class ElfInterfaceFake : public ElfInterface {
55 public:
56 ElfInterfaceFake(Memory* memory) : ElfInterface(memory) {}
57 virtual ~ElfInterfaceFake() = default;
58
59 bool Init() override { return false; }
60 void InitHeaders() override {}
61 bool GetSoname(std::string*) override { return false; }
62
63 bool GetFunctionName(uint64_t, std::string*, uint64_t*) override;
64
65 bool Step(uint64_t, Regs*, Memory*, bool*) override;
66
67 void FakeSetLoadBias(uint64_t load_bias) { load_bias_ = load_bias; }
68
69 static void FakePushFunctionData(const FunctionData data) { functions_.push_back(data); }
70 static void FakePushStepData(const StepData data) { steps_.push_back(data); }
71
72 static void FakeClear() {
73 functions_.clear();
74 steps_.clear();
75 }
76
77 private:
78 static std::deque<FunctionData> functions_;
79 static std::deque<StepData> steps_;
80};
81
82} // namespace unwindstack
83
84#endif // _LIBUNWINDSTACK_TESTS_ELF_FAKE_H