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.
5 #ifndef BASE_PROFILER_LIBUNWINDSTACK_UNWINDER_ANDROID_H_
6 #define BASE_PROFILER_LIBUNWINDSTACK_UNWINDER_ANDROID_H_
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"
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 {
28 LibunwindstackUnwinderAndroid();
29 ~LibunwindstackUnwinderAndroid() override;
31 LibunwindstackUnwinderAndroid(const LibunwindstackUnwinderAndroid&) = delete;
32 LibunwindstackUnwinderAndroid& operator=(
33 const LibunwindstackUnwinderAndroid&) = delete;
36 void InitializeModules() override;
37 bool CanUnwindFrom(const Frame& current_frame) const override;
38 UnwindResult TryUnwind(RegisterContext* thread_context,
40 std::vector<Frame>* stack) override;
43 unwindstack::JitDebug* GetOrCreateJitDebug(unwindstack::ArchEnum arch);
44 unwindstack::DexFiles* GetOrCreateDexFiles(unwindstack::ArchEnum arch);
46 std::unique_ptr<NativeUnwinderAndroidMemoryRegionsMapImpl>
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"};
56 #endif // BASE_PROFILER_LIBUNWINDSTACK_UNWINDER_ANDROID_H_