From 29a2cff09e52ea9a7ecc4bef3e52012d1dd3d525 Mon Sep 17 00:00:00 2001 From: Vegard Nossum Date: Fri, 16 May 2008 16:33:29 +0200 Subject: [PATCH] proc: add "stacktrace" file This patch adds a /proc//stacktrace file which will show the current kernel stack trace of the specified pid. Signed-off-by: Vegard Nossum --- fs/proc/base.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 808cbdc..9e2e29e 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -318,6 +319,48 @@ static int proc_pid_wchan(struct task_struct *task, char *buffer) } #endif /* CONFIG_KALLSYMS */ +#ifdef CONFIG_STACKTRACE +static int proc_stack_trace(struct task_struct *task, char *buffer) +{ + char *cur; + unsigned int len; + + struct stack_trace trace; + unsigned long entries[32]; + int i; + + cur = buffer; + + trace.nr_entries = 0; + trace.entries = entries; + trace.max_entries = ARRAY_SIZE(entries); + trace.skip = 0; + + save_stack_trace_tsk(task, &trace); + + for(i = 0; i < trace.nr_entries; ++i) { + unsigned long ip = trace.entries[i]; + + len = sprintf(cur, "[<%p>] ", (void *) ip); + if (len < 0) + return len; + cur += len; + + len = sprint_symbol(cur, ip); + if (len < 0) + return len; + cur += len; + + len = sprintf(cur, "\n"); + if (len < 0) + return len; + cur += len; + } + + return cur - buffer; +} +#endif + #ifdef CONFIG_SCHEDSTATS /* * Provides /proc/PID/schedstat @@ -2425,6 +2468,9 @@ static const struct pid_entry tgid_base_stuff[] = { #ifdef CONFIG_KALLSYMS INF("wchan", S_IRUGO, pid_wchan), #endif +#ifdef CONFIG_STACKTRACE + INF("stacktrace", S_IRUSR, stack_trace), +#endif #ifdef CONFIG_SCHEDSTATS INF("schedstat", S_IRUGO, pid_schedstat), #endif @@ -2757,6 +2803,9 @@ static const struct pid_entry tid_base_stuff[] = { #ifdef CONFIG_KALLSYMS INF("wchan", S_IRUGO, pid_wchan), #endif +#ifdef CONFIG_STACKTRACE + INF("stacktrace", S_IRUSR, stack_trace), +#endif #ifdef CONFIG_SCHEDSTATS INF("schedstat", S_IRUGO, pid_schedstat), #endif -- 1.5.4.1