blob: ae343ac35bfa7e6c1df4c129639b1b47b8a0a5c1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sasha Levin5634bd72013-06-13 18:41:17 -04002#ifndef _LIBLOCKDEP_LINUX_STACKTRACE_H_
3#define _LIBLOCKDEP_LINUX_STACKTRACE_H_
4
5#include <execinfo.h>
6
7struct stack_trace {
8 unsigned int nr_entries, max_entries;
9 unsigned long *entries;
10 int skip;
11};
12
13static inline void print_stack_trace(struct stack_trace *trace, int spaces)
14{
15 backtrace_symbols_fd((void **)trace->entries, trace->nr_entries, 1);
16}
17
18#define save_stack_trace(trace) \
19 ((trace)->nr_entries = \
20 backtrace((void **)(trace)->entries, (trace)->max_entries))
21
22static inline int dump_stack(void)
23{
24 void *array[64];
25 size_t size;
26
27 size = backtrace(array, 64);
28 backtrace_symbols_fd(array, size, 1);
29
30 return 0;
31}
32
33#endif