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 | { |
| 27 | struct stack_trace *trace = (struct stack_trace *)data; |
| 28 | if (trace->skip > 0) { |
| 29 | trace->skip--; |
| 30 | return; |
| 31 | } |
Catalin Marinas | 006e84ee | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 32 | if (trace->nr_entries < trace->max_entries) |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 33 | trace->entries[trace->nr_entries++] = addr; |
| 34 | } |
| 35 | |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 36 | static void save_stack_address_nosched(void *data, unsigned long addr) |
| 37 | { |
| 38 | struct stack_trace *trace = (struct stack_trace *)data; |
| 39 | if (in_sched_functions(addr)) |
| 40 | return; |
| 41 | if (trace->skip > 0) { |
| 42 | trace->skip--; |
| 43 | return; |
| 44 | } |
| 45 | if (trace->nr_entries < trace->max_entries) |
| 46 | trace->entries[trace->nr_entries++] = addr; |
| 47 | } |
| 48 | |
Jan Beulich | 9689ba8 | 2007-10-17 18:04:37 +0200 | [diff] [blame] | 49 | static const struct stacktrace_ops save_stack_ops = { |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 50 | .warning = save_stack_warning, |
| 51 | .warning_symbol = save_stack_warning_symbol, |
| 52 | .stack = save_stack_stack, |
| 53 | .address = save_stack_address, |
| 54 | }; |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 55 | |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 56 | static const struct stacktrace_ops save_stack_ops_nosched = { |
| 57 | .warning = save_stack_warning, |
| 58 | .warning_symbol = save_stack_warning_symbol, |
| 59 | .stack = save_stack_stack, |
| 60 | .address = save_stack_address_nosched, |
| 61 | }; |
| 62 | |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 63 | /* |
| 64 | * Save stack-backtrace addresses into a stack_trace buffer. |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 65 | */ |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 66 | void save_stack_trace(struct stack_trace *trace) |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 67 | { |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 68 | dump_trace(current, NULL, NULL, &save_stack_ops, trace); |
Catalin Marinas | 006e84ee | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 69 | if (trace->nr_entries < trace->max_entries) |
| 70 | trace->entries[trace->nr_entries++] = ULONG_MAX; |
Ingo Molnar | 21b32bb | 2006-07-03 00:24:40 -0700 | [diff] [blame] | 71 | } |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 72 | |
| 73 | void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) |
| 74 | { |
| 75 | dump_trace(tsk, NULL, NULL, &save_stack_ops_nosched, trace); |
| 76 | if (trace->nr_entries < trace->max_entries) |
| 77 | trace->entries[trace->nr_entries++] = ULONG_MAX; |
| 78 | } |