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