blob: 68de797f5168ac5a2d7fa9fac99f6164ea3aa79c [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#include <stdint.h>
18
19#include <deque>
20#include <string>
21
22#include <unwindstack/Elf.h>
23#include <unwindstack/ElfInterface.h>
24#include <unwindstack/Memory.h>
25#include <unwindstack/Regs.h>
26
27#include "ElfFake.h"
28#include "RegsFake.h"
29
30namespace unwindstack {
31
32std::deque<FunctionData> ElfInterfaceFake::functions_;
33std::deque<StepData> ElfInterfaceFake::steps_;
34
Christopher Ferrise69f4702017-10-19 16:08:58 -070035bool ElfInterfaceFake::GetFunctionName(uint64_t, uint64_t, std::string* name, uint64_t* offset) {
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070036 if (functions_.empty()) {
37 return false;
38 }
39 auto entry = functions_.front();
40 functions_.pop_front();
41 *name = entry.name;
42 *offset = entry.offset;
43 return true;
44}
45
Christopher Ferrise7b66242017-12-15 11:17:45 -080046bool ElfInterfaceFake::Step(uint64_t, uint64_t, Regs* regs, Memory*, bool* finished) {
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070047 if (steps_.empty()) {
48 return false;
49 }
50 auto entry = steps_.front();
51 steps_.pop_front();
52
53 if (entry.pc == 0 && entry.sp == 0 && !entry.finished) {
54 // Pretend as though there is no frame.
55 return false;
56 }
57
58 RegsFake* fake_regs = reinterpret_cast<RegsFake*>(regs);
59 fake_regs->FakeSetPc(entry.pc);
60 fake_regs->FakeSetSp(entry.sp);
61 *finished = entry.finished;
62 return true;
63}
64
65} // namespace unwindstack