blob: c28c342c162f0a90d3ad6e50ba0fb1d5ecd132a7 [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{
Jan Engelhardtade1af72008-01-30 13:33:23 +010027 struct stack_trace *trace = data;
Vegard Nossum16507432008-02-22 19:23:58 +010028 if (!reliable)
29 return;
Andi Kleenc0b766f2006-09-26 10:52:34 +020030 if (trace->skip > 0) {
31 trace->skip--;
32 return;
33 }
Catalin Marinas006e84ee2007-02-13 13:26:21 +010034 if (trace->nr_entries < trace->max_entries)
Andi Kleenc0b766f2006-09-26 10:52:34 +020035 trace->entries[trace->nr_entries++] = addr;
36}
37
Arjan van de Ven5bc27dc2008-01-30 13:33:07 +010038static void
39save_stack_address_nosched(void *data, unsigned long addr, int reliable)
Arjan van de Ven97455122008-01-25 21:08:34 +010040{
41 struct stack_trace *trace = (struct stack_trace *)data;
Vegard Nossum16507432008-02-22 19:23:58 +010042 if (!reliable)
43 return;
Arjan van de Ven97455122008-01-25 21:08:34 +010044 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 Beulich9689ba82007-10-17 18:04:37 +020054static const struct stacktrace_ops save_stack_ops = {
Andi Kleenc0b766f2006-09-26 10:52:34 +020055 .warning = save_stack_warning,
56 .warning_symbol = save_stack_warning_symbol,
57 .stack = save_stack_stack,
58 .address = save_stack_address,
59};
Ingo Molnar21b32bb2006-07-03 00:24:40 -070060
Arjan van de Ven97455122008-01-25 21:08:34 +010061static 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 Molnar21b32bb2006-07-03 00:24:40 -070068/*
69 * Save stack-backtrace addresses into a stack_trace buffer.
Ingo Molnar21b32bb2006-07-03 00:24:40 -070070 */
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070071void save_stack_trace(struct stack_trace *trace)
Ingo Molnar21b32bb2006-07-03 00:24:40 -070072{
Arjan van de Ven5bc27dc2008-01-30 13:33:07 +010073 dump_trace(current, NULL, NULL, 0, &save_stack_ops, trace);
Catalin Marinas006e84ee2007-02-13 13:26:21 +010074 if (trace->nr_entries < trace->max_entries)
75 trace->entries[trace->nr_entries++] = ULONG_MAX;
Ingo Molnar21b32bb2006-07-03 00:24:40 -070076}
Arjan van de Ven97455122008-01-25 21:08:34 +010077
78void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
79{
Arjan van de Ven5bc27dc2008-01-30 13:33:07 +010080 dump_trace(tsk, NULL, NULL, 0, &save_stack_ops_nosched, trace);
Arjan van de Ven97455122008-01-25 21:08:34 +010081 if (trace->nr_entries < trace->max_entries)
82 trace->entries[trace->nr_entries++] = ULONG_MAX;
83}