• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // -*- mode: C++ -*-
2 
3 // Copyright (c) 2013 Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 //     * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 // stackwalker_arm64.h: arm64-specific stackwalker.
33 //
34 // Provides stack frames given arm64 register context and a memory region
35 // corresponding to an arm64 stack.
36 //
37 // Author: Mark Mentovai, Ted Mielczarek, Colin Blundell
38 
39 
40 #ifndef PROCESSOR_STACKWALKER_ARM64_H__
41 #define PROCESSOR_STACKWALKER_ARM64_H__
42 
43 #include "google_breakpad/common/breakpad_types.h"
44 #include "google_breakpad/common/minidump_format.h"
45 #include "google_breakpad/processor/stackwalker.h"
46 
47 namespace google_breakpad {
48 
49 class CodeModules;
50 
51 class StackwalkerARM64 : public Stackwalker {
52  public:
53   // context is an arm64 context object that gives access to arm64-specific
54   // register state corresponding to the innermost called frame to be
55   // included in the stack.  The other arguments are passed directly through
56   // to the base Stackwalker constructor.
57   StackwalkerARM64(const SystemInfo* system_info,
58                    const MDRawContextARM64* context,
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(uint64_t valid)66   void SetContextFrameValidity(uint64_t valid) {
67     context_frame_validity_ = valid;
68   }
69 
70  private:
71   // Strip pointer authentication codes from an address.
72   uint64_t PtrauthStrip(uint64_t ptr);
73 
74   // Implementation of Stackwalker, using arm64 context and stack conventions.
75   virtual StackFrame* GetContextFrame();
76   virtual StackFrame* GetCallerFrame(const CallStack* stack,
77                                      bool stack_scan_allowed);
78 
79   // Use cfi_frame_info (derived from STACK CFI records) to construct
80   // the frame that called frames.back(). The caller takes ownership
81   // of the returned frame. Return NULL on failure.
82   StackFrameARM64* GetCallerByCFIFrameInfo(const vector<StackFrame*> &frames,
83                                            CFIFrameInfo* cfi_frame_info);
84 
85   // Use the frame pointer. The caller takes ownership of the returned frame.
86   // Return NULL on failure.
87   StackFrameARM64* GetCallerByFramePointer(const vector<StackFrame*> &frames);
88 
89   // Scan the stack for plausible return addresses. The caller takes ownership
90   // of the returned frame. Return NULL on failure.
91   StackFrameARM64* GetCallerByStackScan(const vector<StackFrame*> &frames);
92 
93   // GetCallerByFramePointer() depends on the previous frame having recovered
94   // x30($LR) which may not have been done when using CFI.
95   // This function recovers $LR in the previous frame by using the frame-pointer
96   // two frames back to read it from the stack.
97   void CorrectRegLRByFramePointer(const vector<StackFrame*>& frames,
98                                   StackFrameARM64* last_frame);
99 
100   // Stores the CPU context corresponding to the youngest stack frame, to
101   // be returned by GetContextFrame.
102   const MDRawContextARM64* context_;
103 
104   // Validity mask for youngest stack frame. This is always
105   // CONTEXT_VALID_ALL in real use; it is only changeable for the sake of
106   // unit tests.
107   uint64_t context_frame_validity_;
108 
109   // A mask of the valid address bits, determined from the address range of
110   // modules_.
111   uint64_t address_range_mask_;
112 };
113 
114 
115 }  // namespace google_breakpad
116 
117 
118 #endif  // PROCESSOR_STACKWALKER_ARM64_H__
119