native_unwinder_mac.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_PROFILER_NATIVE_UNWINDER_MAC_H_
  5. #define BASE_PROFILER_NATIVE_UNWINDER_MAC_H_
  6. #include <libunwind.h>
  7. #include "base/macros.h"
  8. #include "base/optional.h"
  9. #include "base/profiler/unwinder.h"
  10. namespace base {
  11. // Native unwinder implementation for Mac, using libunwind.
  12. class NativeUnwinderMac : public Unwinder {
  13. public:
  14. NativeUnwinderMac(ModuleCache* module_cache);
  15. NativeUnwinderMac(const NativeUnwinderMac&) = delete;
  16. NativeUnwinderMac& operator=(const NativeUnwinderMac&) = delete;
  17. // Unwinder:
  18. bool CanUnwindFrom(const Frame& current_frame) const override;
  19. UnwindResult TryUnwind(RegisterContext* thread_context,
  20. uintptr_t stack_top,
  21. ModuleCache* module_cache,
  22. std::vector<Frame>* stack) const override;
  23. private:
  24. Optional<UnwindResult> CheckPreconditions(const Frame* current_frame,
  25. unw_cursor_t* unwind_cursor,
  26. uintptr_t stack_top) const;
  27. // Returns the result from unw_step.
  28. int UnwindStep(unw_context_t* unwind_context,
  29. unw_cursor_t* cursor,
  30. bool at_first_frame,
  31. ModuleCache* module_cache) const;
  32. Optional<UnwindResult> CheckPostconditions(int step_result,
  33. unw_word_t prev_rsp,
  34. unw_word_t rsp,
  35. uintptr_t stack_top,
  36. bool* should_record_frame) const;
  37. // Cached pointer to the libsystem_kernel module.
  38. const ModuleCache::Module* const libsystem_kernel_module_;
  39. // The address range of |_sigtramp|, the signal trampoline function.
  40. uintptr_t sigtramp_start_;
  41. uintptr_t sigtramp_end_;
  42. };
  43. } // namespace base
  44. #endif // BASE_PROFILER_NATIVE_UNWINDER_MAC_H_