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(int valid)66   void SetContextFrameValidity(int valid) { context_frame_validity_ = valid; }
67 
68  private:
69   // Implementation of Stackwalker, using arm64 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   StackFrameARM64* 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   StackFrameARM64* 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   StackFrameARM64* 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 MDRawContextARM64* context_;
91 
92   // Validity mask for youngest stack frame. This is always
93   // CONTEXT_VALID_ALL in real use; it is only changeable for the sake of
94   // unit tests.
95   uint64_t context_frame_validity_;
96 };
97 
98 
99 }  // namespace google_breakpad
100 
101 
102 #endif  // PROCESSOR_STACKWALKER_ARM64_H__
103