stacktrace.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <linux/sched.h>
  2. #include <linux/stacktrace.h>
  3. #include <linux/thread_info.h>
  4. #include <asm/ptrace.h>
  5. #include <asm/stacktrace.h>
  6. void save_stack_trace(struct stack_trace *trace)
  7. {
  8. unsigned long ksp, fp, thread_base;
  9. struct thread_info *tp = task_thread_info(current);
  10. stack_trace_flush();
  11. __asm__ __volatile__(
  12. "mov %%fp, %0"
  13. : "=r" (ksp)
  14. );
  15. fp = ksp + STACK_BIAS;
  16. thread_base = (unsigned long) tp;
  17. do {
  18. struct reg_window *rw;
  19. struct pt_regs *regs;
  20. unsigned long pc;
  21. /* Bogus frame pointer? */
  22. if (fp < (thread_base + sizeof(struct thread_info)) ||
  23. fp >= (thread_base + THREAD_SIZE))
  24. break;
  25. rw = (struct reg_window *) fp;
  26. regs = (struct pt_regs *) (rw + 1);
  27. if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
  28. pc = regs->tpc;
  29. fp = regs->u_regs[UREG_I6] + STACK_BIAS;
  30. } else {
  31. pc = rw->ins[7];
  32. fp = rw->ins[6] + STACK_BIAS;
  33. }
  34. if (trace->skip > 0)
  35. trace->skip--;
  36. else
  37. trace->entries[trace->nr_entries++] = pc;
  38. } while (trace->nr_entries < trace->max_entries);
  39. }