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