blob: 66207dbd1be6456e50d041c20b4cc7786944e707 [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 Ferris150db122017-12-20 18:49:01 -080046bool ElfInterfaceFake::GetGlobalVariable(const std::string& global, uint64_t* offset) {
47 auto entry = globals_.find(global);
48 if (entry == globals_.end()) {
49 return false;
50 }
51 *offset = entry->second;
52 return true;
53}
54
Christopher Ferrise7b66242017-12-15 11:17:45 -080055bool ElfInterfaceFake::Step(uint64_t, uint64_t, Regs* regs, Memory*, bool* finished) {
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070056 if (steps_.empty()) {
57 return false;
58 }
59 auto entry = steps_.front();
60 steps_.pop_front();
61
62 if (entry.pc == 0 && entry.sp == 0 && !entry.finished) {
63 // Pretend as though there is no frame.
64 return false;
65 }
66
67 RegsFake* fake_regs = reinterpret_cast<RegsFake*>(regs);
Yabin Cui414df3e2018-03-14 18:16:22 -070068 fake_regs->set_pc(entry.pc);
69 fake_regs->set_sp(entry.sp);
Christopher Ferrisf6f691b2017-09-25 19:23:07 -070070 *finished = entry.finished;
71 return true;
72}
73
74} // namespace unwindstack