stacktrace.c 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Stack trace utility
  3. *
  4. * Copyright 2008 Christoph Hellwig, IBM Corp.
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/stacktrace.h>
  14. #include <asm/ptrace.h>
  15. #include <asm/asm-offsets.h>
  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 sp;
  22. asm("mr %0,1" : "=r" (sp));
  23. for (;;) {
  24. unsigned long *stack = (unsigned long *) sp;
  25. unsigned long newsp, ip;
  26. if (!validate_sp(sp, current, STACK_FRAME_OVERHEAD))
  27. return;
  28. newsp = stack[0];
  29. ip = stack[STACK_FRAME_LR_SAVE];
  30. if (!trace->skip)
  31. trace->entries[trace->nr_entries++] = ip;
  32. else
  33. trace->skip--;
  34. if (trace->nr_entries >= trace->max_entries)
  35. return;
  36. sp = newsp;
  37. }
  38. }