Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 1 | #ifndef _LIBLOCKDEP_LINUX_STACKTRACE_H_ |
| 2 | #define _LIBLOCKDEP_LINUX_STACKTRACE_H_ |
| 3 | |
| 4 | #include <execinfo.h> |
| 5 | |
| 6 | struct stack_trace { |
| 7 | unsigned int nr_entries, max_entries; |
| 8 | unsigned long *entries; |
| 9 | int skip; |
| 10 | }; |
| 11 | |
| 12 | static 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 | |
| 21 | static 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 |