1 // Copyright 2021 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_FRAME_POINTER_UNWINDER_H_ 6 #define BASE_PROFILER_FRAME_POINTER_UNWINDER_H_ 7 8 #include <vector> 9 10 #include "base/base_export.h" 11 #include "base/functional/callback.h" 12 #include "base/profiler/unwinder.h" 13 #include "build/build_config.h" 14 15 #if BUILDFLAG(IS_APPLE) 16 #include <os/availability.h> 17 #endif 18 19 namespace base { 20 21 // Native unwinder implementation for platforms that have frame pointers: 22 // * iOS, ARM64 and X86_64, 23 // * macOS 24 // * ChromeOS X86_64 and ARM64 25 class BASE_EXPORT 26 #if BUILDFLAG(IS_APPLE) 27 API_AVAILABLE(ios(12)) 28 #endif 29 FramePointerUnwinder : public Unwinder { 30 public: 31 using CanUnwindFromDelegate = 32 RepeatingCallback<bool(const Frame& current_frame)>; 33 34 FramePointerUnwinder( 35 CanUnwindFromDelegate can_unwind_from_delegate = CanUnwindFromDelegate()); 36 ~FramePointerUnwinder() override; 37 38 FramePointerUnwinder(const FramePointerUnwinder&) = delete; 39 FramePointerUnwinder& operator=(const FramePointerUnwinder&) = delete; 40 41 // Unwinder: 42 bool CanUnwindFrom(const Frame& current_frame) const override; 43 UnwindResult TryUnwind(UnwinderStateCapture* capture_state, 44 RegisterContext* thread_context, 45 uintptr_t stack_top, 46 std::vector<Frame>* stack) override; 47 48 private: 49 CanUnwindFromDelegate can_unwind_from_delegate_; 50 }; 51 52 } // namespace base 53 54 #endif // BASE_PROFILER_FRAME_POINTER_UNWINDER_H_ 55