Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -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 | #ifndef _LIBBACKTRACE_UNWINDSTACK_MAP_H |
| 18 | #define _LIBBACKTRACE_UNWINDSTACK_MAP_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Christopher Ferris | 5f11851 | 2017-09-01 11:17:16 -0700 | [diff] [blame] | 23 | #include <memory> |
Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 24 | #include <mutex> |
| 25 | #include <unordered_map> |
Christopher Ferris | c8bec5a | 2017-12-11 17:44:33 -0800 | [diff] [blame] | 26 | #include <vector> |
Christopher Ferris | 5f11851 | 2017-09-01 11:17:16 -0700 | [diff] [blame] | 27 | |
Christopher Ferris | c8bec5a | 2017-12-11 17:44:33 -0800 | [diff] [blame] | 28 | #include <backtrace/Backtrace.h> |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 29 | #include <backtrace/BacktraceMap.h> |
David Srbecky | b9cc4fb | 2019-04-05 18:23:32 +0000 | [diff] [blame^] | 30 | #if !defined(NO_LIBDEXFILE_SUPPORT) |
| 31 | #include <unwindstack/DexFiles.h> |
| 32 | #endif |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 33 | #include <unwindstack/Elf.h> |
Christopher Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 34 | #include <unwindstack/JitDebug.h> |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 35 | #include <unwindstack/Maps.h> |
| 36 | |
Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 37 | // Forward declarations. |
| 38 | class UnwindDexFile; |
| 39 | |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 40 | class UnwindStackMap : public BacktraceMap { |
| 41 | public: |
| 42 | explicit UnwindStackMap(pid_t pid); |
Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 43 | ~UnwindStackMap() = default; |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 44 | |
| 45 | bool Build() override; |
| 46 | |
Christopher Ferris | 7937a36 | 2018-01-18 11:15:49 -0800 | [diff] [blame] | 47 | void FillIn(uint64_t addr, backtrace_map_t* map) override; |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 48 | |
Christopher Ferris | 7937a36 | 2018-01-18 11:15:49 -0800 | [diff] [blame] | 49 | virtual std::string GetFunctionName(uint64_t pc, uint64_t* offset) override; |
Josh Gao | ebea0ef | 2017-09-06 15:39:14 -0700 | [diff] [blame] | 50 | virtual std::shared_ptr<unwindstack::Memory> GetProcessMemory() override final; |
Josh Gao | 358de18 | 2017-09-06 22:16:09 -0700 | [diff] [blame] | 51 | |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 52 | unwindstack::Maps* stack_maps() { return stack_maps_.get(); } |
| 53 | |
Christopher Ferris | 5f11851 | 2017-09-01 11:17:16 -0700 | [diff] [blame] | 54 | const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; } |
| 55 | |
David Srbecky | b9cc4fb | 2019-04-05 18:23:32 +0000 | [diff] [blame^] | 56 | unwindstack::JitDebug* GetJitDebug() { return jit_debug_.get(); } |
| 57 | |
| 58 | #if !defined(NO_LIBDEXFILE_SUPPORT) |
| 59 | unwindstack::DexFiles* GetDexFiles() { return dex_files_.get(); } |
| 60 | #endif |
| 61 | |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 62 | void SetArch(unwindstack::ArchEnum arch) { arch_ = arch; } |
| 63 | |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 64 | protected: |
Christopher Ferris | b7de5f5 | 2017-12-01 21:37:37 -0800 | [diff] [blame] | 65 | uint64_t GetLoadBias(size_t index) override; |
| 66 | |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 67 | std::unique_ptr<unwindstack::Maps> stack_maps_; |
Christopher Ferris | 5f11851 | 2017-09-01 11:17:16 -0700 | [diff] [blame] | 68 | std::shared_ptr<unwindstack::Memory> process_memory_; |
David Srbecky | b9cc4fb | 2019-04-05 18:23:32 +0000 | [diff] [blame^] | 69 | std::unique_ptr<unwindstack::JitDebug> jit_debug_; |
| 70 | #if !defined(NO_LIBDEXFILE_SUPPORT) |
| 71 | std::unique_ptr<unwindstack::DexFiles> dex_files_; |
| 72 | #endif |
| 73 | |
Christopher Ferris | 4568f4b | 2018-10-23 17:42:41 -0700 | [diff] [blame] | 74 | unwindstack::ArchEnum arch_ = unwindstack::ARCH_UNKNOWN; |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Christopher Ferris | c8bec5a | 2017-12-11 17:44:33 -0800 | [diff] [blame] | 77 | class UnwindStackOfflineMap : public UnwindStackMap { |
| 78 | public: |
| 79 | UnwindStackOfflineMap(pid_t pid); |
| 80 | ~UnwindStackOfflineMap() = default; |
| 81 | |
| 82 | bool Build() override; |
| 83 | |
Christopher Ferris | 432981b | 2018-02-22 19:42:53 -0800 | [diff] [blame] | 84 | bool Build(const std::vector<backtrace_map_t>& maps); |
| 85 | |
| 86 | bool CreateProcessMemory(const backtrace_stackinfo_t& stack); |
Christopher Ferris | 6633b0c | 2018-04-03 16:03:28 -0700 | [diff] [blame] | 87 | |
| 88 | private: |
| 89 | unwindstack::MemoryOfflineBuffer* memory_ = nullptr; |
Christopher Ferris | c8bec5a | 2017-12-11 17:44:33 -0800 | [diff] [blame] | 90 | }; |
| 91 | |
Christopher Ferris | 6f3981c | 2017-07-27 09:29:18 -0700 | [diff] [blame] | 92 | #endif // _LIBBACKTRACE_UNWINDSTACK_MAP_H |