stacktrace.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * arch/sh/kernel/stacktrace.c
  3. *
  4. * Stack trace management functions
  5. *
  6. * Copyright (C) 2006 - 2008 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 <linux/module.h>
  16. #include <asm/unwinder.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/stacktrace.h>
  19. static int save_stack_stack(void *data, char *name)
  20. {
  21. return 0;
  22. }
  23. /*
  24. * Save stack-backtrace addresses into a stack_trace buffer.
  25. */
  26. static void save_stack_address(void *data, unsigned long addr, int reliable)
  27. {
  28. struct stack_trace *trace = data;
  29. if (!reliable)
  30. return;
  31. if (trace->skip > 0) {
  32. trace->skip--;
  33. return;
  34. }
  35. if (trace->nr_entries < trace->max_entries)
  36. trace->entries[trace->nr_entries++] = addr;
  37. }
  38. static const struct stacktrace_ops save_stack_ops = {
  39. .stack = save_stack_stack,
  40. .address = save_stack_address,
  41. };
  42. void save_stack_trace(struct stack_trace *trace)
  43. {
  44. unsigned long *sp = (unsigned long *)current_stack_pointer;
  45. unwind_stack(current, NULL, sp, &save_stack_ops, trace);
  46. if (trace->nr_entries < trace->max_entries)
  47. trace->entries[trace->nr_entries++] = ULONG_MAX;
  48. }
  49. EXPORT_SYMBOL_GPL(save_stack_trace);
  50. static void
  51. save_stack_address_nosched(void *data, unsigned long addr, int reliable)
  52. {
  53. struct stack_trace *trace = (struct stack_trace *)data;
  54. if (!reliable)
  55. return;
  56. if (in_sched_functions(addr))
  57. return;
  58. if (trace->skip > 0) {
  59. trace->skip--;
  60. return;
  61. }
  62. if (trace->nr_entries < trace->max_entries)
  63. trace->entries[trace->nr_entries++] = addr;
  64. }
  65. static const struct stacktrace_ops save_stack_ops_nosched = {
  66. .stack = save_stack_stack,
  67. .address = save_stack_address_nosched,
  68. };
  69. void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
  70. {
  71. unsigned long *sp = (unsigned long *)tsk->thread.sp;
  72. unwind_stack(current, NULL, sp, &save_stack_ops_nosched, trace);
  73. if (trace->nr_entries < trace->max_entries)
  74. trace->entries[trace->nr_entries++] = ULONG_MAX;
  75. }
  76. EXPORT_SYMBOL_GPL(save_stack_trace_tsk);