stacktrace.h 678 B

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