2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 namespace exception_tracer {
26 constexpr size_t kMaxFrames = 500;
29 StackTrace() : frameCount(0) {}
32 uintptr_t addresses[kMaxFrames];
35 // note: no constructor so this can be __thread.
36 // A StackTraceStack MUST be placed in zero-initialized memory.
37 class StackTraceStack {
42 * Push the current stack trace onto the stack.
43 * Returns false on failure (not enough memory, getting stack trace failed),
49 * Pop the top stack trace from the stack.
50 * Returns true on success, false on failure (stack was empty).
55 * Move the top stack trace from other onto this.
56 * Returns true on success, false on failure (other was empty).
58 bool moveTopFrom(StackTraceStack& other);
74 * Return the top stack trace, or nullptr if the stack is empty.
79 * Return the stack trace following p, or nullptr if p is the bottom of
82 StackTrace* next(StackTrace* p);
85 // In debug mode, we assert that we're in zero-initialized memory by
86 // checking that the two guards around top_ are zero.
87 void checkGuard() const {
89 assert(guard1_ == 0 && guard2_ == 0);
101 } // namespace exception_tracer