stacktrace.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Stack trace management functions
  3. *
  4. * Copyright (C) 2007 Atmel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/sched.h>
  11. #include <linux/stacktrace.h>
  12. #include <linux/thread_info.h>
  13. #include <linux/module.h>
  14. register unsigned long current_frame_pointer asm("r7");
  15. struct stackframe {
  16. unsigned long lr;
  17. unsigned long fp;
  18. };
  19. /*
  20. * Save stack-backtrace addresses into a stack_trace buffer.
  21. */
  22. void save_stack_trace(struct stack_trace *trace)
  23. {
  24. unsigned long low, high;
  25. unsigned long fp;
  26. struct stackframe *frame;
  27. int skip = trace->skip;
  28. low = (unsigned long)task_stack_page(current);
  29. high = low + THREAD_SIZE;
  30. fp = current_frame_pointer;
  31. while (fp >= low && fp <= (high - 8)) {
  32. frame = (struct stackframe *)fp;
  33. if (skip) {
  34. skip--;
  35. } else {
  36. trace->entries[trace->nr_entries++] = frame->lr;
  37. if (trace->nr_entries >= trace->max_entries)
  38. break;
  39. }
  40. /*
  41. * The next frame must be at a higher address than the
  42. * current frame.
  43. */
  44. low = fp + 8;
  45. fp = frame->fp;
  46. }
  47. }
  48. EXPORT_SYMBOL_GPL(save_stack_trace);