blob: 8c4e4f5bf0403fa0ffaa42e89f9261e2f4fa4fe1 [file] [log] [blame]
Ingo Molnar21b32bb2006-07-03 00:24:40 -07001/*
Ingo Molnar21b32bb2006-07-03 00:24:40 -07002 * 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 Kleenc0b766f2006-09-26 10:52:34 +02008#include <linux/module.h>
9#include <asm/stacktrace.h>
Ingo Molnar21b32bb2006-07-03 00:24:40 -070010
Andi Kleenc0b766f2006-09-26 10:52:34 +020011static void save_stack_warning(void *data, char *msg)
Ingo Molnar21b32bb2006-07-03 00:24:40 -070012{
Ingo Molnar21b32bb2006-07-03 00:24:40 -070013}
14
Andi Kleenc0b766f2006-09-26 10:52:34 +020015static void
16save_stack_warning_symbol(void *data, char *msg, unsigned long symbol)
Ingo Molnar21b32bb2006-07-03 00:24:40 -070017{
Ingo Molnar21b32bb2006-07-03 00:24:40 -070018}
19
Andi Kleenc0b766f2006-09-26 10:52:34 +020020static int save_stack_stack(void *data, char *name)
Ingo Molnar21b32bb2006-07-03 00:24:40 -070021{
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070022 return -1;
Ingo Molnar21b32bb2006-07-03 00:24:40 -070023}
24
Arjan van de Venbc850d62008-01-30 13:33:07 +010025static void save_stack_address(void *data, unsigned long addr, int reliable)
Andi Kleenc0b766f2006-09-26 10:52:34 +020026{
27 struct stack_trace *trace = (struct stack_trace *)data;
28 if (trace->skip > 0) {
29 trace->skip--;
30 return;
31 }
Catalin Marinas006e84ee2007-02-13 13:26:21 +010032 if (trace->nr_entries < trace->max_entries)
Andi Kleenc0b766f2006-09-26 10:52:34 +020033 trace->entries[trace->nr_entries++] = addr;
34}
35
Arjan van de Ven97455122008-01-25 21:08:34 +010036static 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 Beulich9689ba82007-10-17 18:04:37 +020049static const struct stacktrace_ops save_stack_ops = {
Andi Kleenc0b766f2006-09-26 10:52:34 +020050 .warning = save_stack_warning,
51 .warning_symbol = save_stack_warning_symbol,
52 .stack = save_stack_stack,
53 .address = save_stack_address,
54};
Ingo Molnar21b32bb2006-07-03 00:24:40 -070055
Arjan van de Ven97455122008-01-25 21:08:34 +010056static 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 Molnar21b32bb2006-07-03 00:24:40 -070063/*
64 * Save stack-backtrace addresses into a stack_trace buffer.
Ingo Molnar21b32bb2006-07-03 00:24:40 -070065 */
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070066void save_stack_trace(struct stack_trace *trace)
Ingo Molnar21b32bb2006-07-03 00:24:40 -070067{
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070068 dump_trace(current, NULL, NULL, &save_stack_ops, trace);
Catalin Marinas006e84ee2007-02-13 13:26:21 +010069 if (trace->nr_entries < trace->max_entries)
70 trace->entries[trace->nr_entries++] = ULONG_MAX;
Ingo Molnar21b32bb2006-07-03 00:24:40 -070071}
Arjan van de Ven97455122008-01-25 21:08:34 +010072
73void 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}