• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_PROFILER_LIBUNWINDSTACK_UNWINDER_ANDROID_H_
6 #define BASE_PROFILER_LIBUNWINDSTACK_UNWINDER_ANDROID_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "base/profiler/native_unwinder_android_memory_regions_map_impl.h"
12 #include "base/profiler/unwinder.h"
13 #include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/DexFiles.h"
14 #include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/JitDebug.h"
15 #include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Memory.h"
16 
17 namespace base {
18 
19 // This unwinder uses the libunwindstack::Unwinder internally to provide the
20 // base::Unwinder implementation. This is in contrast to
21 // base::NativeUnwinderAndroid, which uses functions from libunwindstack
22 // selectively to provide a subset of libunwindstack::Unwinder features. This
23 // causes some divergences from other base::Unwinder (this unwinder either fully
24 // succeeds or fully fails). A good source for a compariative unwinder would be
25 // traced_perf or heapprofd on android which uses the same API.
26 class LibunwindstackUnwinderAndroid : public Unwinder {
27  public:
28   LibunwindstackUnwinderAndroid();
29   ~LibunwindstackUnwinderAndroid() override;
30 
31   LibunwindstackUnwinderAndroid(const LibunwindstackUnwinderAndroid&) = delete;
32   LibunwindstackUnwinderAndroid& operator=(
33       const LibunwindstackUnwinderAndroid&) = delete;
34 
35   // Unwinder
36   void InitializeModules() override;
37   bool CanUnwindFrom(const Frame& current_frame) const override;
38   UnwindResult TryUnwind(UnwinderStateCapture* capture_state,
39                          RegisterContext* thread_context,
40                          uintptr_t stack_top,
41                          std::vector<Frame>* stack) override;
42 
43  private:
44   unwindstack::JitDebug* GetOrCreateJitDebug(unwindstack::ArchEnum arch);
45   unwindstack::DexFiles* GetOrCreateDexFiles(unwindstack::ArchEnum arch);
46 
47   std::unique_ptr<NativeUnwinderAndroidMemoryRegionsMapImpl>
48       memory_regions_map_;
49 
50   std::unique_ptr<unwindstack::JitDebug> jit_debug_;
51   std::unique_ptr<unwindstack::DexFiles> dex_files_;
52   // Libraries where to search for dex and jit descriptors.
53   const std::vector<std::string> search_libs_ = {"libart.so", "libartd.so"};
54 };
55 }  // namespace base
56 
57 #endif  // BASE_PROFILER_LIBUNWINDSTACK_UNWINDER_ANDROID_H_
58