stacktrace.h 639 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef _LIBLOCKDEP_LINUX_STACKTRACE_H_
  2. #define _LIBLOCKDEP_LINUX_STACKTRACE_H_
  3. #include <execinfo.h>
  4. struct stack_trace {
  5. unsigned int nr_entries, max_entries;
  6. unsigned long *entries;
  7. int skip;
  8. };
  9. static inline void print_stack_trace(struct stack_trace *trace, int spaces)
  10. {
  11. backtrace_symbols_fd((void **)trace->entries, trace->nr_entries, 1);
  12. }
  13. #define save_stack_trace(trace) \
  14. ((trace)->nr_entries = \
  15. backtrace((void **)(trace)->entries, (trace)->max_entries))
  16. static inline int dump_stack(void)
  17. {
  18. void *array[64];
  19. size_t size;
  20. size = backtrace(array, 64);
  21. backtrace_symbols_fd(array, size, 1);
  22. return 0;
  23. }
  24. #endif