2006-07-03 15:24:38 +08:00
|
|
|
/*
|
|
|
|
* kernel/stacktrace.c
|
|
|
|
*
|
|
|
|
* Stack trace management functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
|
|
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
2008-12-25 18:21:20 +08:00
|
|
|
#include <linux/kernel.h>
|
2011-05-24 02:51:41 +08:00
|
|
|
#include <linux/export.h>
|
2006-07-03 15:24:38 +08:00
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/stacktrace.h>
|
|
|
|
|
|
|
|
void print_stack_trace(struct stack_trace *trace, int spaces)
|
|
|
|
{
|
2008-06-13 17:00:14 +08:00
|
|
|
int i;
|
2006-07-03 15:24:38 +08:00
|
|
|
|
2008-05-13 03:21:14 +08:00
|
|
|
if (WARN_ON(!trace->entries))
|
|
|
|
return;
|
|
|
|
|
2017-02-08 07:33:20 +08:00
|
|
|
for (i = 0; i < trace->nr_entries; i++)
|
|
|
|
printk("%*c%pS\n", 1 + spaces, ' ', (void *)trace->entries[i]);
|
2006-07-03 15:24:38 +08:00
|
|
|
}
|
2008-06-28 03:20:17 +08:00
|
|
|
EXPORT_SYMBOL_GPL(print_stack_trace);
|
2006-07-03 15:24:38 +08:00
|
|
|
|
2014-12-13 08:55:58 +08:00
|
|
|
int snprint_stack_trace(char *buf, size_t size,
|
|
|
|
struct stack_trace *trace, int spaces)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int generated;
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
if (WARN_ON(!trace->entries))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < trace->nr_entries; i++) {
|
2017-02-08 07:33:20 +08:00
|
|
|
generated = snprintf(buf, size, "%*c%pS\n", 1 + spaces, ' ',
|
|
|
|
(void *)trace->entries[i]);
|
2014-12-13 08:55:58 +08:00
|
|
|
|
|
|
|
total += generated;
|
|
|
|
|
|
|
|
/* Assume that generated isn't a negative number */
|
|
|
|
if (generated >= size) {
|
|
|
|
buf += size;
|
|
|
|
size = 0;
|
|
|
|
} else {
|
|
|
|
buf += generated;
|
|
|
|
size -= generated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snprint_stack_trace);
|
|
|
|
|
2008-12-25 18:21:20 +08:00
|
|
|
/*
|
2017-02-14 09:42:28 +08:00
|
|
|
* Architectures that do not implement save_stack_trace_*()
|
|
|
|
* get these weak aliases and once-per-bootup warnings
|
2011-06-08 15:09:27 +08:00
|
|
|
* (whenever this facility is utilized - for example by procfs):
|
2008-12-25 18:21:20 +08:00
|
|
|
*/
|
|
|
|
__weak void
|
|
|
|
save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
WARN_ONCE(1, KERN_INFO "save_stack_trace_tsk() not implemented yet.\n");
|
|
|
|
}
|
2011-06-08 15:09:27 +08:00
|
|
|
|
|
|
|
__weak void
|
|
|
|
save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
WARN_ONCE(1, KERN_INFO "save_stack_trace_regs() not implemented yet.\n");
|
|
|
|
}
|
2017-02-14 09:42:28 +08:00
|
|
|
|
|
|
|
__weak int
|
|
|
|
save_stack_trace_tsk_reliable(struct task_struct *tsk,
|
|
|
|
struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
WARN_ONCE(1, KERN_INFO "save_stack_tsk_reliable() not implemented yet.\n");
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|