| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_STACKTRACE_H |
| 4 | #define NETDATA_STACKTRACE_H 1 |
| 5 | |
| 6 | #include "libnetdata/libnetdata-base.h" |
| 7 | |
| 8 | #define STACK_TRACE_INFO_PREFIX "info: " |
| 9 | |
| 10 | // Opaque pointer to a stack trace |
| 11 | typedef struct stacktrace *STACKTRACE; |
| 12 | |
| 13 | // Set the signal handler function name to filter out in stack traces |
| 14 | void stacktrace_set_signal_handler_function(const char *function_name); |
| 15 | |
| 16 | // Returns the first netdata function found in the stack trace |
| 17 | const char *stacktrace_root_cause_function(void); |
| 18 | |
| 19 | // Initialize the stacktrace capture mechanism |
| 20 | void stacktrace_init(void); |
| 21 | |
| 22 | // Free any resources used by the stacktrace mechanism |
| 23 | void stacktrace_flush(void); |
| 24 | |
| 25 | // Return true if the stacktrace mechanism can be safely used in signal handlers |
| 26 | bool stacktrace_capture_is_async_signal_safe(void); |
| 27 | |
| 28 | // Return true if stacktrace capture is available on this platform |
| 29 | bool stacktrace_available(void); |
| 30 | |
| 31 | // Capture a stacktrace to a buffer |
| 32 | struct web_buffer; |
| 33 | typedef struct web_buffer BUFFER; |
| 34 | void stacktrace_capture(BUFFER *wb); |
| 35 | |
| 36 | // Return a string describing the backend used for capturing stacktraces |
| 37 | const char *stacktrace_backend(void); |
| 38 | |
| 39 | // Get the current stacktrace, hash it, and store it in a cache |
| 40 | STACKTRACE stacktrace_get(int skip_frames); |
| 41 | |
| 42 | // Convert a stacktrace to a buffer |
| 43 | void stacktrace_to_buffer(STACKTRACE trace, struct web_buffer *wb); |
| 44 | |
| 45 | void stacktrace_forked(void); |
| 46 | bool stack_trace_formatter(struct web_buffer *wb, void *data); |
| 47 | |
| 48 | // Unit testing |
| 49 | int stacktrace_unittest(void); |
| 50 | |
| 51 | #include "stacktrace-array.h" |
| 52 | |
| 53 | #endif /* NETDATA_STACKTRACE_H */ |