stacktrace.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Blackfin stacktrace code (mostly copied from avr32)
  3. *
  4. * Copyright 2009 Analog Devices Inc.
  5. * Licensed under the GPL-2 or later.
  6. */
  7. #include <linux/sched.h>
  8. #include <linux/stacktrace.h>
  9. #include <linux/thread_info.h>
  10. #include <linux/module.h>
  11. register unsigned long current_frame_pointer asm("FP");
  12. struct stackframe {
  13. unsigned long fp;
  14. unsigned long rets;
  15. };
  16. /*
  17. * Save stack-backtrace addresses into a stack_trace buffer.
  18. */
  19. void save_stack_trace(struct stack_trace *trace)
  20. {
  21. unsigned long low, high;
  22. unsigned long fp;
  23. struct stackframe *frame;
  24. int skip = trace->skip;
  25. low = (unsigned long)task_stack_page(current);
  26. high = low + THREAD_SIZE;
  27. fp = current_frame_pointer;
  28. while (fp >= low && fp <= (high - sizeof(*frame))) {
  29. frame = (struct stackframe *)fp;
  30. if (skip) {
  31. skip--;
  32. } else {
  33. trace->entries[trace->nr_entries++] = frame->rets;
  34. if (trace->nr_entries >= trace->max_entries)
  35. break;
  36. }
  37. /*
  38. * The next frame must be at a higher address than the
  39. * current frame.
  40. */
  41. low = fp + sizeof(*frame);
  42. fp = frame->fp;
  43. }
  44. }
  45. EXPORT_SYMBOL_GPL(save_stack_trace);