Back to home page

LXR

 
 

    


0001 /*
0002  * kernel/stacktrace.c
0003  *
0004  * Stack trace management functions
0005  *
0006  *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
0007  */
0008 #include <linux/sched.h>
0009 #include <linux/kernel.h>
0010 #include <linux/export.h>
0011 #include <linux/kallsyms.h>
0012 #include <linux/stacktrace.h>
0013 
0014 void print_stack_trace(struct stack_trace *trace, int spaces)
0015 {
0016     int i;
0017 
0018     if (WARN_ON(!trace->entries))
0019         return;
0020 
0021     for (i = 0; i < trace->nr_entries; i++)
0022         printk("%*c%pS\n", 1 + spaces, ' ', (void *)trace->entries[i]);
0023 }
0024 EXPORT_SYMBOL_GPL(print_stack_trace);
0025 
0026 int snprint_stack_trace(char *buf, size_t size,
0027             struct stack_trace *trace, int spaces)
0028 {
0029     int i;
0030     int generated;
0031     int total = 0;
0032 
0033     if (WARN_ON(!trace->entries))
0034         return 0;
0035 
0036     for (i = 0; i < trace->nr_entries; i++) {
0037         generated = snprintf(buf, size, "%*c%pS\n", 1 + spaces, ' ',
0038                      (void *)trace->entries[i]);
0039 
0040         total += generated;
0041 
0042         /* Assume that generated isn't a negative number */
0043         if (generated >= size) {
0044             buf += size;
0045             size = 0;
0046         } else {
0047             buf += generated;
0048             size -= generated;
0049         }
0050     }
0051 
0052     return total;
0053 }
0054 EXPORT_SYMBOL_GPL(snprint_stack_trace);
0055 
0056 /*
0057  * Architectures that do not implement save_stack_trace_tsk or
0058  * save_stack_trace_regs get this weak alias and a once-per-bootup warning
0059  * (whenever this facility is utilized - for example by procfs):
0060  */
0061 __weak void
0062 save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
0063 {
0064     WARN_ONCE(1, KERN_INFO "save_stack_trace_tsk() not implemented yet.\n");
0065 }
0066 
0067 __weak void
0068 save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
0069 {
0070     WARN_ONCE(1, KERN_INFO "save_stack_trace_regs() not implemented yet.\n");
0071 }