2 * Copyright 2012 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.
18 #ifndef FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_STACKTRACE_H_
19 #define FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_STACKTRACE_H_
28 typedef struct StackTrace {
29 uintptr_t* frameIPs; /* allocated with malloc() */
34 * Get the current stack trace, allocating trace->frameIPs using malloc().
35 * Skip the topmost "skip" frames.
36 * Return 0 on success, a negative value on error.
37 * On error, trace->frameIPs is NULL.
39 int getCurrentStackTrace(size_t skip, StackTrace* trace);
42 * Free data allocated in a StackTrace object.
44 void destroyStackTrace(StackTrace* trace);
47 * A stack of stack traces.
49 typedef struct StackTraceStack {
51 struct StackTraceStack* next;
55 * Push the current stack trace onto the stack.
56 * Return 0 on success, a negative value on error.
57 * On error, the stack is unchanged.
59 int pushCurrentStackTrace(size_t skip, StackTraceStack** head);
62 * Pop (and destroy) the top stack trace from the stack.
64 void popStackTrace(StackTraceStack** head);
67 * Completely empty the stack, destroying everything.
69 void clearStack(StackTraceStack** head);
72 * Move the top stack trace from one stack to another.
73 * Return 0 on success, a negative value on error (if the source stack is
76 int moveTop(StackTraceStack** from, StackTraceStack** to);
82 #endif /* FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_STACKTRACE_H_ */