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(RegisterContext* thread_context, 39 uintptr_t stack_top, 40 std::vector<Frame>* stack) override; 41 42 private: 43 unwindstack::JitDebug* GetOrCreateJitDebug(unwindstack::ArchEnum arch); 44 unwindstack::DexFiles* GetOrCreateDexFiles(unwindstack::ArchEnum arch); 45 46 std::unique_ptr<NativeUnwinderAndroidMemoryRegionsMapImpl> 47 memory_regions_map_; 48 49 std::unique_ptr<unwindstack::JitDebug> jit_debug_; 50 std::unique_ptr<unwindstack::DexFiles> dex_files_; 51 // Libraries where to search for dex and jit descriptors. 52 const std::vector<std::string> search_libs_ = {"libart.so", "libartd.so"}; 53 }; 54 } // namespace base 55 56 #endif // BASE_PROFILER_LIBUNWINDSTACK_UNWINDER_ANDROID_H_ 57