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
47namespace google_breakpad {
48
49class CodeModules;
50
51class 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.
66  void SetContextFrameValidity(uint64_t valid) {
67    context_frame_validity_ = valid;
68  }
69
70 private:
71  // Implementation of Stackwalker, using arm64 context and stack conventions.
72  virtual StackFrame* GetContextFrame();
73  virtual StackFrame* GetCallerFrame(const CallStack* stack,
74                                     bool stack_scan_allowed);
75
76  // Use cfi_frame_info (derived from STACK CFI records) to construct
77  // the frame that called frames.back(). The caller takes ownership
78  // of the returned frame. Return NULL on failure.
79  StackFrameARM64* GetCallerByCFIFrameInfo(const vector<StackFrame*> &frames,
80                                           CFIFrameInfo* cfi_frame_info);
81
82  // Use the frame pointer. The caller takes ownership of the returned frame.
83  // Return NULL on failure.
84  StackFrameARM64* GetCallerByFramePointer(const vector<StackFrame*> &frames);
85
86  // Scan the stack for plausible return addresses. The caller takes ownership
87  // of the returned frame. Return NULL on failure.
88  StackFrameARM64* GetCallerByStackScan(const vector<StackFrame*> &frames);
89
90  // Stores the CPU context corresponding to the youngest stack frame, to
91  // be returned by GetContextFrame.
92  const MDRawContextARM64* context_;
93
94  // Validity mask for youngest stack frame. This is always
95  // CONTEXT_VALID_ALL in real use; it is only changeable for the sake of
96  // unit tests.
97  uint64_t context_frame_validity_;
98};
99
100
101}  // namespace google_breakpad
102
103
104#endif  // PROCESSOR_STACKWALKER_ARM64_H__
105