blob: e19b605655064865824b672ac8abb1cd6010f4b7 [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 Ferrisd70ea5e2018-01-30 19:47:24 -080030#if !defined(NO_LIBDEXFILE_SUPPORT)
31#include <unwindstack/DexFiles.h>
32#endif
Christopher Ferris4568f4b2018-10-23 17:42:41 -070033#include <unwindstack/Elf.h>
Christopher Ferris150db122017-12-20 18:49:01 -080034#include <unwindstack/JitDebug.h>
Christopher Ferris6f3981c2017-07-27 09:29:18 -070035#include <unwindstack/Maps.h>
36
Christopher Ferris0b06a592018-01-19 10:26:36 -080037// Forward declarations.
38class UnwindDexFile;
39
Christopher Ferris6f3981c2017-07-27 09:29:18 -070040class UnwindStackMap : public BacktraceMap {
41 public:
42 explicit UnwindStackMap(pid_t pid);
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080043 ~UnwindStackMap() = default;
Christopher Ferris6f3981c2017-07-27 09:29:18 -070044
45 bool Build() override;
46
Christopher Ferris7937a362018-01-18 11:15:49 -080047 void FillIn(uint64_t addr, backtrace_map_t* map) override;
Christopher Ferris6f3981c2017-07-27 09:29:18 -070048
Christopher Ferris7937a362018-01-18 11:15:49 -080049 virtual std::string GetFunctionName(uint64_t pc, uint64_t* offset) override;
Josh Gaoebea0ef2017-09-06 15:39:14 -070050 virtual std::shared_ptr<unwindstack::Memory> GetProcessMemory() override final;
Josh Gao358de182017-09-06 22:16:09 -070051
Christopher Ferris6f3981c2017-07-27 09:29:18 -070052 unwindstack::Maps* stack_maps() { return stack_maps_.get(); }
53
Christopher Ferris5f118512017-09-01 11:17:16 -070054 const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
55
Christopher Ferris150db122017-12-20 18:49:01 -080056 unwindstack::JitDebug* GetJitDebug() { return jit_debug_.get(); }
57
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080058#if !defined(NO_LIBDEXFILE_SUPPORT)
59 unwindstack::DexFiles* GetDexFiles() { return dex_files_.get(); }
60#endif
Christopher Ferris0b06a592018-01-19 10:26:36 -080061
Christopher Ferris4568f4b2018-10-23 17:42:41 -070062 void SetArch(unwindstack::ArchEnum arch) { arch_ = arch; }
63
Christopher Ferris6f3981c2017-07-27 09:29:18 -070064 protected:
Christopher Ferrisb7de5f52017-12-01 21:37:37 -080065 uint64_t GetLoadBias(size_t index) override;
66
Christopher Ferris6f3981c2017-07-27 09:29:18 -070067 std::unique_ptr<unwindstack::Maps> stack_maps_;
Christopher Ferris5f118512017-09-01 11:17:16 -070068 std::shared_ptr<unwindstack::Memory> process_memory_;
Christopher Ferris150db122017-12-20 18:49:01 -080069 std::unique_ptr<unwindstack::JitDebug> jit_debug_;
Christopher Ferrisd70ea5e2018-01-30 19:47:24 -080070#if !defined(NO_LIBDEXFILE_SUPPORT)
71 std::unique_ptr<unwindstack::DexFiles> dex_files_;
Christopher Ferris0b06a592018-01-19 10:26:36 -080072#endif
Christopher Ferris4568f4b2018-10-23 17:42:41 -070073
74 unwindstack::ArchEnum arch_ = unwindstack::ARCH_UNKNOWN;
Christopher Ferris6f3981c2017-07-27 09:29:18 -070075};
76
Christopher Ferrisc8bec5a2017-12-11 17:44:33 -080077class UnwindStackOfflineMap : public UnwindStackMap {
78 public:
79 UnwindStackOfflineMap(pid_t pid);
80 ~UnwindStackOfflineMap() = default;
81
82 bool Build() override;
83
Christopher Ferris432981b2018-02-22 19:42:53 -080084 bool Build(const std::vector<backtrace_map_t>& maps);
85
86 bool CreateProcessMemory(const backtrace_stackinfo_t& stack);
Christopher Ferris6633b0c2018-04-03 16:03:28 -070087
88 private:
89 unwindstack::MemoryOfflineBuffer* memory_ = nullptr;
Christopher Ferrisc8bec5a2017-12-11 17:44:33 -080090};
91
Christopher Ferris6f3981c2017-07-27 09:29:18 -070092#endif // _LIBBACKTRACE_UNWINDSTACK_MAP_H