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.
17 #include <folly/experimental/exception_tracer/StackTrace.h>
23 #include <folly/experimental/symbolizer/StackTrace.h>
26 namespace exception_tracer {
28 class StackTraceStack::Node : public StackTrace {
30 static Node* allocate();
36 Node() : next(nullptr) {}
40 auto StackTraceStack::Node::allocate() -> Node* {
41 // Null pointer on error, please.
42 return new (std::nothrow) Node();
45 void StackTraceStack::Node::deallocate() {
49 bool StackTraceStack::pushCurrent() {
51 auto node = Node::allocate();
53 // cannot allocate memory
57 ssize_t n = folly::symbolizer::getStackTrace(node->addresses, kMaxFrames);
69 bool StackTraceStack::pop() {
81 bool StackTraceStack::moveTopFrom(StackTraceStack& other) {
87 auto node = other.top_;
88 other.top_ = node->next;
94 void StackTraceStack::clear() {
101 StackTrace* StackTraceStack::top() {
106 StackTrace* StackTraceStack::next(StackTrace* p) {
109 return static_cast<Node*>(p)->next;
111 } // namespace exception_tracer