Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 1 | /* |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 2 | * Stack trace management functions |
| 3 | * |
| 4 | * Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> |
| 5 | */ |
| 6 | #include <linux/sched.h> |
| 7 | #include <linux/stacktrace.h> |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 8 | #include <linux/module.h> |
| 9 | #include <asm/stacktrace.h> |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 10 | |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 11 | static void save_stack_warning(void *data, char *msg) |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 12 | { |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 13 | } |
| 14 | |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 15 | static void |
| 16 | save_stack_warning_symbol(void *data, char *msg, unsigned long symbol) |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 17 | { |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 20 | static int save_stack_stack(void *data, char *name) |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 21 | { |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 22 | return -1; |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Arjan van de Ven | bc850d6 | 2008-01-30 13:33:07 +0100 | [diff] [blame] | 25 | static void save_stack_address(void *data, unsigned long addr, int reliable) |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 26 | { |
Jan Engelhardt | ade1af7 | 2008-01-30 13:33:23 +0100 | [diff] [blame] | 27 | struct stack_trace *trace = data; |
Vegard Nossum | 1650743 | 2008-02-22 19:23:58 +0100 | [diff] [blame] | 28 | if (!reliable) |
| 29 | return; |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 30 | if (trace->skip > 0) { |
| 31 | trace->skip--; |
| 32 | return; |
| 33 | } |
Catalin Marinas | 006e84ee | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 34 | if (trace->nr_entries < trace->max_entries) |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 35 | trace->entries[trace->nr_entries++] = addr; |
| 36 | } |
| 37 | |
Arjan van de Ven | 5bc27dc | 2008-01-30 13:33:07 +0100 | [diff] [blame] | 38 | static void |
| 39 | save_stack_address_nosched(void *data, unsigned long addr, int reliable) |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 40 | { |
| 41 | struct stack_trace *trace = (struct stack_trace *)data; |
Vegard Nossum | 1650743 | 2008-02-22 19:23:58 +0100 | [diff] [blame] | 42 | if (!reliable) |
| 43 | return; |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 44 | if (in_sched_functions(addr)) |
| 45 | return; |
| 46 | if (trace->skip > 0) { |
| 47 | trace->skip--; |
| 48 | return; |
| 49 | } |
| 50 | if (trace->nr_entries < trace->max_entries) |
| 51 | trace->entries[trace->nr_entries++] = addr; |
| 52 | } |
| 53 | |
Jan Beulich | 9689ba8 | 2007-10-17 18:04:37 +0200 | [diff] [blame] | 54 | static const struct stacktrace_ops save_stack_ops = { |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 55 | .warning = save_stack_warning, |
| 56 | .warning_symbol = save_stack_warning_symbol, |
| 57 | .stack = save_stack_stack, |
| 58 | .address = save_stack_address, |
| 59 | }; |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 60 | |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 61 | static const struct stacktrace_ops save_stack_ops_nosched = { |
| 62 | .warning = save_stack_warning, |
| 63 | .warning_symbol = save_stack_warning_symbol, |
| 64 | .stack = save_stack_stack, |
| 65 | .address = save_stack_address_nosched, |
| 66 | }; |
| 67 | |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 68 | /* |
| 69 | * Save stack-backtrace addresses into a stack_trace buffer. |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 70 | */ |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 71 | void save_stack_trace(struct stack_trace *trace) |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 72 | { |
Arjan van de Ven | 5bc27dc | 2008-01-30 13:33:07 +0100 | [diff] [blame] | 73 | dump_trace(current, NULL, NULL, 0, &save_stack_ops, trace); |
Catalin Marinas | 006e84ee | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 74 | if (trace->nr_entries < trace->max_entries) |
| 75 | trace->entries[trace->nr_entries++] = ULONG_MAX; |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 76 | } |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 77 | |
| 78 | void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) |
| 79 | { |
Arjan van de Ven | 5bc27dc | 2008-01-30 13:33:07 +0100 | [diff] [blame] | 80 | dump_trace(tsk, NULL, NULL, 0, &save_stack_ops_nosched, trace); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 81 | if (trace->nr_entries < trace->max_entries) |
| 82 | trace->entries[trace->nr_entries++] = ULONG_MAX; |
| 83 | } |