stacktrace.c 977 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * arch/sh/kernel/stacktrace.c
  3. *
  4. * Stack trace management functions
  5. *
  6. * Copyright (C) 2006 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/stacktrace.h>
  14. #include <linux/thread_info.h>
  15. #include <asm/ptrace.h>
  16. /*
  17. * Save stack-backtrace addresses into a stack_trace buffer.
  18. */
  19. void save_stack_trace(struct stack_trace *trace, struct task_struct *task)
  20. {
  21. unsigned long *sp;
  22. if (!task)
  23. task = current;
  24. if (task == current)
  25. sp = (unsigned long *)current_stack_pointer;
  26. else
  27. sp = (unsigned long *)task->thread.sp;
  28. while (!kstack_end(sp)) {
  29. unsigned long addr = *sp++;
  30. if (__kernel_text_address(addr)) {
  31. if (trace->skip > 0)
  32. trace->skip--;
  33. else
  34. trace->entries[trace->nr_entries++] = addr;
  35. if (trace->nr_entries >= trace->max_entries)
  36. break;
  37. }
  38. }
  39. }