• 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 #include <unwindstack/Memory.h>
37 
38 // Forward declarations.
39 class UnwindDexFile;
40 
41 class UnwindStackMap : public BacktraceMap {
42  public:
43   explicit UnwindStackMap(pid_t pid);
44   ~UnwindStackMap() = default;
45 
46   bool Build() override;
47 
48   void FillIn(uint64_t addr, backtrace_map_t* map) override;
49 
50   std::string GetBuildId(uint64_t addr) override;
51 
52   virtual std::string GetFunctionName(uint64_t pc, uint64_t* offset) override;
53   virtual std::shared_ptr<unwindstack::Memory> GetProcessMemory() override final;
54 
stack_maps()55   unwindstack::Maps* stack_maps() { return stack_maps_.get(); }
56 
process_memory()57   const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
58 
GetJitDebug()59   unwindstack::JitDebug* GetJitDebug() { return jit_debug_.get(); }
60 
61 #if !defined(NO_LIBDEXFILE_SUPPORT)
GetDexFiles()62   unwindstack::DexFiles* GetDexFiles() { return dex_files_.get(); }
63 #endif
64 
SetArch(unwindstack::ArchEnum arch)65   void SetArch(unwindstack::ArchEnum arch) { arch_ = arch; }
66 
67  protected:
68   uint64_t GetLoadBias(size_t index) override;
69 
70   std::unique_ptr<unwindstack::Maps> stack_maps_;
71   std::shared_ptr<unwindstack::Memory> process_memory_;
72   std::unique_ptr<unwindstack::JitDebug> jit_debug_;
73 #if !defined(NO_LIBDEXFILE_SUPPORT)
74   std::unique_ptr<unwindstack::DexFiles> dex_files_;
75 #endif
76 
77   unwindstack::ArchEnum arch_ = unwindstack::ARCH_UNKNOWN;
78 };
79 
80 #endif  // _LIBBACKTRACE_UNWINDSTACK_MAP_H
81