blob: be5c59e7461600ec11df421e9e1501bdb6b50215 [file] [log] [blame]
Christopher Ferris6f3981c2017-07-27 09:29:18 -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 _LIBBACKTRACE_UNWINDSTACK_MAP_H
18#define _LIBBACKTRACE_UNWINDSTACK_MAP_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
Christopher Ferris5f118512017-09-01 11:17:16 -070023#include <memory>
Christopher Ferris0b06a592018-01-19 10:26:36 -080024#include <mutex>
25#include <unordered_map>
Christopher Ferrisc8bec5a2017-12-11 17:44:33 -080026#include <vector>
Christopher Ferris5f118512017-09-01 11:17:16 -070027
Christopher Ferrisc8bec5a2017-12-11 17:44:33 -080028#include <backtrace/Backtrace.h>
Christopher Ferris6f3981c2017-07-27 09:29:18 -070029#include <backtrace/BacktraceMap.h>
Christopher Ferris150db122017-12-20 18:49:01 -080030#include <unwindstack/JitDebug.h>
Christopher Ferris6f3981c2017-07-27 09:29:18 -070031#include <unwindstack/Maps.h>
32
Christopher Ferris0b06a592018-01-19 10:26:36 -080033// Forward declarations.
34class UnwindDexFile;
35
Christopher Ferris6f3981c2017-07-27 09:29:18 -070036class UnwindStackMap : public BacktraceMap {
37 public:
38 explicit UnwindStackMap(pid_t pid);
Christopher Ferris0b06a592018-01-19 10:26:36 -080039 ~UnwindStackMap();
Christopher Ferris6f3981c2017-07-27 09:29:18 -070040
41 bool Build() override;
42
Christopher Ferris7937a362018-01-18 11:15:49 -080043 void FillIn(uint64_t addr, backtrace_map_t* map) override;
Christopher Ferris6f3981c2017-07-27 09:29:18 -070044
Christopher Ferris7937a362018-01-18 11:15:49 -080045 virtual std::string GetFunctionName(uint64_t pc, uint64_t* offset) override;
Josh Gaoebea0ef2017-09-06 15:39:14 -070046 virtual std::shared_ptr<unwindstack::Memory> GetProcessMemory() override final;
Josh Gao358de182017-09-06 22:16:09 -070047
Christopher Ferris6f3981c2017-07-27 09:29:18 -070048 unwindstack::Maps* stack_maps() { return stack_maps_.get(); }
49
Christopher Ferris5f118512017-09-01 11:17:16 -070050 const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
51
Christopher Ferris150db122017-12-20 18:49:01 -080052 unwindstack::JitDebug* GetJitDebug() { return jit_debug_.get(); }
53
Christopher Ferris0b06a592018-01-19 10:26:36 -080054 UnwindDexFile* GetDexFile(uint64_t dex_file_offset, unwindstack::MapInfo* info);
55
Christopher Ferris6f3981c2017-07-27 09:29:18 -070056 protected:
Christopher Ferrisb7de5f52017-12-01 21:37:37 -080057 uint64_t GetLoadBias(size_t index) override;
58
Christopher Ferris6f3981c2017-07-27 09:29:18 -070059 std::unique_ptr<unwindstack::Maps> stack_maps_;
Christopher Ferris5f118512017-09-01 11:17:16 -070060 std::shared_ptr<unwindstack::Memory> process_memory_;
Christopher Ferris150db122017-12-20 18:49:01 -080061 std::unique_ptr<unwindstack::JitDebug> jit_debug_;
Christopher Ferris0b06a592018-01-19 10:26:36 -080062#ifndef NO_LIBDEXFILE
63 std::mutex dex_lock_;
64 std::unordered_map<uint64_t, UnwindDexFile*> dex_files_;
65#endif
Christopher Ferris6f3981c2017-07-27 09:29:18 -070066};
67
Christopher Ferrisc8bec5a2017-12-11 17:44:33 -080068class UnwindStackOfflineMap : public UnwindStackMap {
69 public:
70 UnwindStackOfflineMap(pid_t pid);
71 ~UnwindStackOfflineMap() = default;
72
73 bool Build() override;
74
75 bool Build(const std::vector<backtrace_map_t>& maps, const backtrace_stackinfo_t& stack);
76};
77
Christopher Ferris6f3981c2017-07-27 09:29:18 -070078#endif // _LIBBACKTRACE_UNWINDSTACK_MAP_H