blob: ad16c021152e19dcbf7fc763c5d0f298c3e58749 [file] [log] [blame]
Christopher Ferris63860cb2015-11-16 17:30:32 -08001/*
2 * Copyright (C) 2015 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 <vector>
21#include <utility>
22
Christopher Ferris93bdd6a2018-04-05 11:12:38 -070023#include <unwindstack/LocalUnwinder.h>
24
Christopher Ferris63860cb2015-11-16 17:30:32 -080025#include "backtrace.h"
26#include "backtrace_fake.h"
27#include "debug_log.h"
28
29static std::deque<std::vector<uintptr_t>> g_fake_backtrace;
30
31void backtrace_fake_clear_all() {
32 g_fake_backtrace.clear();
33}
34
35void backtrace_fake_add(const std::vector<uintptr_t>& ips) {
36 g_fake_backtrace.push_back(ips);
37}
38
39void backtrace_startup() {
40}
41
42void backtrace_shutdown() {
43}
44
45size_t backtrace_get(uintptr_t* frames, size_t frame_num) {
46 if (frame_num == 0 || g_fake_backtrace.size() == 0) {
47 return 0;
48 }
49
50 size_t ips_size = g_fake_backtrace[0].size();
51 size_t total_frames = (frame_num < ips_size) ? frame_num : ips_size;
52 memcpy(frames, g_fake_backtrace[0].data(), sizeof(uintptr_t) * total_frames);
53 g_fake_backtrace.pop_front();
54 return total_frames;
55}
56
Christopher Ferris7993b802016-01-28 18:35:05 -080057void backtrace_log(const uintptr_t* frames, size_t frame_count) {
Christopher Ferris63860cb2015-11-16 17:30:32 -080058 for (size_t i = 0; i < frame_count; i++) {
59 error_log(" #%02zd pc %p", i, reinterpret_cast<void*>(frames[i]));
60 }
61}
Christopher Ferris93bdd6a2018-04-05 11:12:38 -070062
63static std::deque<std::vector<unwindstack::LocalFrameData>> g_fake_local_frame_data;
64
65void BacktraceUnwindFakeClearAll() {
66 g_fake_local_frame_data.clear();
67}
68
69void BacktraceUnwindFake(const std::vector<unwindstack::LocalFrameData>& frames) {
70 g_fake_local_frame_data.push_back(frames);
71}
72
73bool Unwind(std::vector<uintptr_t>* frames, std::vector<unwindstack::LocalFrameData>* info, size_t) {
74 if (g_fake_local_frame_data.empty()) {
75 return false;
76 }
77
78 *info = g_fake_local_frame_data.front();
79 g_fake_local_frame_data.pop_front();
80 frames->clear();
81 for (const auto& frame : *info) {
82 frames->push_back(frame.pc);
83 }
84
85 return true;
86}
87
88void UnwindLog(const std::vector<unwindstack::LocalFrameData>& /*frame_info*/) {
89}