xref: /aosp_15_r20/external/google-breakpad/src/processor/stackwalker_arm.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 // -*- mode: C++ -*-
2 
3 // Copyright 2010 Google LLC
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google LLC nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // stackwalker_arm.h: arm-specific stackwalker.
32 //
33 // Provides stack frames given arm register context and a memory region
34 // corresponding to an arm stack.
35 //
36 // Author: Mark Mentovai, Ted Mielczarek
37 
38 
39 #ifndef PROCESSOR_STACKWALKER_ARM_H__
40 #define PROCESSOR_STACKWALKER_ARM_H__
41 
42 #include "google_breakpad/common/breakpad_types.h"
43 #include "google_breakpad/common/minidump_format.h"
44 #include "google_breakpad/processor/stackwalker.h"
45 
46 namespace google_breakpad {
47 
48 class CodeModules;
49 
50 class StackwalkerARM : public Stackwalker {
51  public:
52   // context is an arm context object that gives access to arm-specific
53   // register state corresponding to the innermost called frame to be
54   // included in the stack.  The other arguments are passed directly through
55   // to the base Stackwalker constructor.
56   StackwalkerARM(const SystemInfo* system_info,
57                  const MDRawContextARM* context,
58                  int fp_register,
59                  MemoryRegion* memory,
60                  const CodeModules* modules,
61                  StackFrameSymbolizer* frame_symbolizer);
62 
63   // Change the context validity mask of the frame returned by
64   // GetContextFrame to VALID. This is only for use by unit tests; the
65   // default behavior is correct for all application code.
SetContextFrameValidity(int valid)66   void SetContextFrameValidity(int valid) { context_frame_validity_ = valid; }
67 
68  private:
69   // Implementation of Stackwalker, using arm context and stack conventions.
70   virtual StackFrame* GetContextFrame();
71   virtual StackFrame* GetCallerFrame(const CallStack* stack,
72                                      bool stack_scan_allowed);
73 
74   // Use cfi_frame_info (derived from STACK CFI records) to construct
75   // the frame that called frames.back(). The caller takes ownership
76   // of the returned frame. Return NULL on failure.
77   StackFrameARM* GetCallerByCFIFrameInfo(const vector<StackFrame*>& frames,
78                                          CFIFrameInfo* cfi_frame_info);
79 
80   // Use the frame pointer. The caller takes ownership of the returned frame.
81   // Return NULL on failure.
82   StackFrameARM* GetCallerByFramePointer(const vector<StackFrame*>& frames);
83 
84   // Scan the stack for plausible return addresses. The caller takes ownership
85   // of the returned frame. Return NULL on failure.
86   StackFrameARM* GetCallerByStackScan(const vector<StackFrame*>& frames);
87 
88   // Stores the CPU context corresponding to the youngest stack frame, to
89   // be returned by GetContextFrame.
90   const MDRawContextARM* context_;
91 
92   // The register to use a as frame pointer. The value is -1 if frame pointer
93   // cannot be used.
94   int fp_register_;
95 
96   // Validity mask for youngest stack frame. This is always
97   // CONTEXT_VALID_ALL in real use; it is only changeable for the sake of
98   // unit tests.
99   int context_frame_validity_;
100 };
101 
102 
103 }  // namespace google_breakpad
104 
105 
106 #endif  // PROCESSOR_STACKWALKER_ARM_H__
107