• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #include <memory>
24 #include <mutex>
25 #include <unordered_map>
26 #include <vector>
27 
28 #include <backtrace/Backtrace.h>
29 #include <backtrace/BacktraceMap.h>
30 #if !defined(NO_LIBDEXFILE_SUPPORT)
31 #include <unwindstack/DexFiles.h>
32 #endif
33 #include <unwindstack/Elf.h>
34 #include <unwindstack/JitDebug.h>
35 #include <unwindstack/Maps.h>
36 
37 // Forward declarations.
38 class UnwindDexFile;
39 
40 class UnwindStackMap : public BacktraceMap {
41  public:
42   explicit UnwindStackMap(pid_t pid);
43   ~UnwindStackMap() = default;
44 
45   bool Build() override;
46 
47   void FillIn(uint64_t addr, backtrace_map_t* map) override;
48 
49   virtual std::string GetFunctionName(uint64_t pc, uint64_t* offset) override;
50   virtual std::shared_ptr<unwindstack::Memory> GetProcessMemory() override final;
51 
stack_maps()52   unwindstack::Maps* stack_maps() { return stack_maps_.get(); }
53 
process_memory()54   const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
55 
GetJitDebug()56   unwindstack::JitDebug* GetJitDebug() { return jit_debug_.get(); }
57 
58 #if !defined(NO_LIBDEXFILE_SUPPORT)
GetDexFiles()59   unwindstack::DexFiles* GetDexFiles() { return dex_files_.get(); }
60 #endif
61 
SetArch(unwindstack::ArchEnum arch)62   void SetArch(unwindstack::ArchEnum arch) { arch_ = arch; }
63 
64  protected:
65   uint64_t GetLoadBias(size_t index) override;
66 
67   std::unique_ptr<unwindstack::Maps> stack_maps_;
68   std::shared_ptr<unwindstack::Memory> process_memory_;
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 
74   unwindstack::ArchEnum arch_ = unwindstack::ARCH_UNKNOWN;
75 };
76 
77 class UnwindStackOfflineMap : public UnwindStackMap {
78  public:
79   UnwindStackOfflineMap(pid_t pid);
80   ~UnwindStackOfflineMap() = default;
81 
82   bool Build() override;
83 
84   bool Build(const std::vector<backtrace_map_t>& maps);
85 
86   bool CreateProcessMemory(const backtrace_stackinfo_t& stack);
87 
88  private:
89   unwindstack::MemoryOfflineBuffer* memory_ = nullptr;
90 };
91 
92 #endif  // _LIBBACKTRACE_UNWINDSTACK_MAP_H
93