• 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   virtual std::string GetFunctionName(uint64_t pc, uint64_t* offset) override;
51   virtual std::shared_ptr<unwindstack::Memory> GetProcessMemory() override final;
52 
stack_maps()53   unwindstack::Maps* stack_maps() { return stack_maps_.get(); }
54 
process_memory()55   const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
56 
GetJitDebug()57   unwindstack::JitDebug* GetJitDebug() { return jit_debug_.get(); }
58 
59 #if !defined(NO_LIBDEXFILE_SUPPORT)
GetDexFiles()60   unwindstack::DexFiles* GetDexFiles() { return dex_files_.get(); }
61 #endif
62 
SetArch(unwindstack::ArchEnum arch)63   void SetArch(unwindstack::ArchEnum arch) { arch_ = arch; }
64 
65  protected:
66   uint64_t GetLoadBias(size_t index) override;
67 
68   std::unique_ptr<unwindstack::Maps> stack_maps_;
69   std::shared_ptr<unwindstack::Memory> process_memory_;
70   std::unique_ptr<unwindstack::JitDebug> jit_debug_;
71 #if !defined(NO_LIBDEXFILE_SUPPORT)
72   std::unique_ptr<unwindstack::DexFiles> dex_files_;
73 #endif
74 
75   unwindstack::ArchEnum arch_ = unwindstack::ARCH_UNKNOWN;
76 };
77 
78 #endif  // _LIBBACKTRACE_UNWINDSTACK_MAP_H
79