]> Pileus Git - ~andy/linux/commitdiff
xtensa: add stacktrace support
authorMax Filippov <jcmvbkbc@gmail.com>
Mon, 15 Apr 2013 05:20:48 +0000 (09:20 +0400)
committerChris Zankel <chris@zankel.net>
Thu, 9 May 2013 08:07:10 +0000 (01:07 -0700)
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Chris Zankel <chris@zankel.net>
arch/xtensa/Kconfig
arch/xtensa/include/asm/stacktrace.h [new file with mode: 0644]
arch/xtensa/kernel/Makefile
arch/xtensa/kernel/stacktrace.c [new file with mode: 0644]
arch/xtensa/kernel/traps.c

index a9bdb1c5f13d975494c2099a6ece07eb4f43cad2..13280f2780c859a330aca32ec3562bef394939cd 100644 (file)
@@ -52,6 +52,9 @@ config HZ
 source "init/Kconfig"
 source "kernel/Kconfig.freezer"
 
+config STACKTRACE_SUPPORT
+       def_bool y
+
 config MMU
        def_bool n
 
diff --git a/arch/xtensa/include/asm/stacktrace.h b/arch/xtensa/include/asm/stacktrace.h
new file mode 100644 (file)
index 0000000..6a05fcb
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * arch/xtensa/include/asm/stacktrace.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2001 - 2013 Tensilica Inc.
+ */
+#ifndef _XTENSA_STACKTRACE_H
+#define _XTENSA_STACKTRACE_H
+
+#include <linux/sched.h>
+
+struct stackframe {
+       unsigned long pc;
+       unsigned long sp;
+};
+
+static __always_inline unsigned long *stack_pointer(struct task_struct *task)
+{
+       unsigned long *sp;
+
+       if (!task || task == current)
+               __asm__ __volatile__ ("mov %0, a1\n" : "=a"(sp));
+       else
+               sp = (unsigned long *)task->thread.sp;
+
+       return sp;
+}
+
+void walk_stackframe(unsigned long *sp,
+               int (*fn)(struct stackframe *frame, void *data),
+               void *data);
+
+#endif /* _XTENSA_STACKTRACE_H */
index c433a56fbff955bd7b013fce13617b804fb7e8d5..1e7fc87a94bb80b5894f8ce0cc471090ab883241 100644 (file)
@@ -4,9 +4,9 @@
 
 extra-y := head.o vmlinux.lds
 
-obj-y := align.o entry.o irq.o coprocessor.o process.o ptrace.o \
-        setup.o signal.o syscall.o time.o traps.o vectors.o platform.o  \
-        pci-dma.o
+obj-y := align.o coprocessor.o entry.o irq.o pci-dma.o platform.o process.o \
+        ptrace.o setup.o signal.o stacktrace.o syscall.o time.o traps.o \
+        vectors.o
 
 obj-$(CONFIG_KGDB) += xtensa-stub.o
 obj-$(CONFIG_PCI) += pci.o
diff --git a/arch/xtensa/kernel/stacktrace.c b/arch/xtensa/kernel/stacktrace.c
new file mode 100644 (file)
index 0000000..e3aff95
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * arch/xtensa/kernel/stacktrace.c
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2001 - 2013 Tensilica Inc.
+ */
+#include <linux/export.h>
+#include <linux/sched.h>
+#include <linux/stacktrace.h>
+
+#include <asm/stacktrace.h>
+#include <asm/traps.h>
+
+void walk_stackframe(unsigned long *sp,
+               int (*fn)(struct stackframe *frame, void *data),
+               void *data)
+{
+       unsigned long a0, a1;
+       unsigned long sp_end;
+
+       a1 = (unsigned long)sp;
+       sp_end = ALIGN(a1, THREAD_SIZE);
+
+       spill_registers();
+
+       while (a1 < sp_end) {
+               struct stackframe frame;
+
+               sp = (unsigned long *)a1;
+
+               a0 = *(sp - 4);
+               a1 = *(sp - 3);
+
+               if (a1 <= (unsigned long)sp)
+                       break;
+
+               frame.pc = MAKE_PC_FROM_RA(a0, a1);
+               frame.sp = a1;
+
+               if (fn(&frame, data))
+                       return;
+       }
+}
+
+#ifdef CONFIG_STACKTRACE
+
+struct stack_trace_data {
+       struct stack_trace *trace;
+       unsigned skip;
+};
+
+static int stack_trace_cb(struct stackframe *frame, void *data)
+{
+       struct stack_trace_data *trace_data = data;
+       struct stack_trace *trace = trace_data->trace;
+
+       if (trace_data->skip) {
+               --trace_data->skip;
+               return 0;
+       }
+       if (!kernel_text_address(frame->pc))
+               return 0;
+
+       trace->entries[trace->nr_entries++] = frame->pc;
+       return trace->nr_entries >= trace->max_entries;
+}
+
+void save_stack_trace_tsk(struct task_struct *task, struct stack_trace *trace)
+{
+       struct stack_trace_data trace_data = {
+               .trace = trace,
+               .skip = trace->skip,
+       };
+       walk_stackframe(stack_pointer(task), stack_trace_cb, &trace_data);
+}
+EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
+
+void save_stack_trace(struct stack_trace *trace)
+{
+       save_stack_trace_tsk(current, trace);
+}
+EXPORT_SYMBOL_GPL(save_stack_trace);
+
+#endif
index 923db5c15278fc530bc593fa321781a01ecd1c37..cf065e165cebc50714c70c618471dbf30bedd589 100644 (file)
@@ -11,7 +11,7 @@
  *
  * Essentially rewritten for the Xtensa architecture port.
  *
- * Copyright (C) 2001 - 2005 Tensilica Inc.
+ * Copyright (C) 2001 - 2013 Tensilica Inc.
  *
  * Joe Taylor  <joe@tensilica.com, joetylr@yahoo.com>
  * Chris Zankel        <chris@zankel.net>
@@ -32,6 +32,7 @@
 #include <linux/delay.h>
 #include <linux/hardirq.h>
 
+#include <asm/stacktrace.h>
 #include <asm/ptrace.h>
 #include <asm/timex.h>
 #include <asm/uaccess.h>
@@ -402,53 +403,25 @@ void show_regs(struct pt_regs * regs)
                       regs->syscall);
 }
 
-static __always_inline unsigned long *stack_pointer(struct task_struct *task)
+static int show_trace_cb(struct stackframe *frame, void *data)
 {
-       unsigned long *sp;
-
-       if (!task || task == current)
-               __asm__ __volatile__ ("mov %0, a1\n" : "=a"(sp));
-       else
-               sp = (unsigned long *)task->thread.sp;
-
-       return sp;
+       if (kernel_text_address(frame->pc)) {
+               printk(" [<%08lx>] ", frame->pc);
+               print_symbol("%s\n", frame->pc);
+       }
+       return 0;
 }
 
 void show_trace(struct task_struct *task, unsigned long *sp)
 {
-       unsigned long a0, a1, pc;
-       unsigned long sp_start, sp_end;
-
-       if (sp)
-               a1 = (unsigned long)sp;
-       else
-               a1 = (unsigned long)stack_pointer(task);
-
-       sp_start = a1 & ~(THREAD_SIZE-1);
-       sp_end = sp_start + THREAD_SIZE;
+       if (!sp)
+               sp = stack_pointer(task);
 
        printk("Call Trace:");
 #ifdef CONFIG_KALLSYMS
        printk("\n");
 #endif
-       spill_registers();
-
-       while (a1 > sp_start && a1 < sp_end) {
-               sp = (unsigned long*)a1;
-
-               a0 = *(sp - 4);
-               a1 = *(sp - 3);
-
-               if (a1 <= (unsigned long) sp)
-                       break;
-
-               pc = MAKE_PC_FROM_RA(a0, a1);
-
-               if (kernel_text_address(pc)) {
-                       printk(" [<%08lx>] ", pc);
-                       print_symbol("%s\n", pc);
-               }
-       }
+       walk_stackframe(sp, show_trace_cb, NULL);
        printk("\n");
 }