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 
5 #ifndef BASE_PROFILER_CHROME_UNWINDER_ANDROID_H_
6 #define BASE_PROFILER_CHROME_UNWINDER_ANDROID_H_
7 
8 #include "base/profiler/unwinder.h"
9 
10 #include "base/base_export.h"
11 #include "base/optional.h"
12 #include "base/profiler/arm_cfi_table.h"
13 #include "base/profiler/module_cache.h"
14 #include "base/profiler/register_context.h"
15 
16 namespace base {
17 
18 // Chrome unwinder implementation for Android, using ArmCfiTable.
19 class BASE_EXPORT ChromeUnwinderAndroid : public Unwinder {
20  public:
21   ChromeUnwinderAndroid(const ArmCFITable* cfi_table,
22                         uintptr_t chrome_module_base_address);
23   ~ChromeUnwinderAndroid() override;
24   ChromeUnwinderAndroid(const ChromeUnwinderAndroid&) = delete;
25   ChromeUnwinderAndroid& operator=(const ChromeUnwinderAndroid&) = delete;
26 
27   // Unwinder:
28   bool CanUnwindFrom(const Frame& current_frame) const override;
29   UnwindResult TryUnwind(RegisterContext* thread_context,
30                          uintptr_t stack_top,
31                          ModuleCache* module_cache,
32                          std::vector<Frame>* stack) const override;
33 
StepForTesting(RegisterContext * thread_context,uintptr_t stack_top,const ArmCFITable::FrameEntry & entry)34   static bool StepForTesting(RegisterContext* thread_context,
35                              uintptr_t stack_top,
36                              const ArmCFITable::FrameEntry& entry) {
37     return Step(thread_context, stack_top, entry);
38   }
39 
40  private:
41   static bool Step(RegisterContext* thread_context,
42                    uintptr_t stack_top,
43                    const ArmCFITable::FrameEntry& entry);
44   // Fallback setp that attempts to use lr as return address.
45   static bool StepUsingLrRegister(RegisterContext* thread_context,
46                                   uintptr_t stack_top);
47 
48   const ArmCFITable* cfi_table_;
49   const uintptr_t chrome_module_base_address_;
50 };
51 
52 }  // namespace base
53 
54 #endif  // BASE_PROFILER_CHROME_UNWINDER_ANDROID_H_
55