stacktrace.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <linux/module.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)
  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. }
  39. EXPORT_SYMBOL_GPL(save_stack_trace);