diff --git a/kitty/backtrace.h b/kitty/backtrace.h new file mode 100644 index 000000000..e3497bba5 --- /dev/null +++ b/kitty/backtrace.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 Kovid Goyal + * + * Distributed under terms of the GPL3 license. + */ + +#pragma once + +#include +#include +#include +#include + +#if __has_include() +#include + +static inline void +print_stack_trace(void) { + void *array[256]; + size_t size; + + // get void*'s for all entries on the stack + size = backtrace(array, 256); + + // print out all the frames to stderr + backtrace_symbols_fd(array, size, STDERR_FILENO); +} +#else +static inline void +print_stack_trace(void) { + fprintf(stderr, "stack trace functionality not available"); +} +#endif