| Christopher Ferris | f6f691b | 2017-09-25 19:23:07 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 30 | namespace unwindstack { | 
|  | 31 |  | 
|  | 32 | std::deque<FunctionData> ElfInterfaceFake::functions_; | 
|  | 33 | std::deque<StepData> ElfInterfaceFake::steps_; | 
|  | 34 |  | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 35 | bool ElfInterfaceFake::GetFunctionName(uint64_t, uint64_t, std::string* name, uint64_t* offset) { | 
| Christopher Ferris | f6f691b | 2017-09-25 19:23:07 -0700 | [diff] [blame] | 36 | 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 Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 46 | bool 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 Ferris | e7b6624 | 2017-12-15 11:17:45 -0800 | [diff] [blame] | 55 | bool ElfInterfaceFake::Step(uint64_t, uint64_t, Regs* regs, Memory*, bool* finished) { | 
| Christopher Ferris | f6f691b | 2017-09-25 19:23:07 -0700 | [diff] [blame] | 56 | 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); | 
|  | 68 | fake_regs->FakeSetPc(entry.pc); | 
|  | 69 | fake_regs->FakeSetSp(entry.sp); | 
|  | 70 | *finished = entry.finished; | 
|  | 71 | return true; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | }  // namespace unwindstack |