diff options
Diffstat (limited to 'kernel/trace/trace_kdb.c')
-rw-r--r-- | kernel/trace/trace_kdb.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c new file mode 100644 index 000000000000..44cbda25b0a5 --- /dev/null +++ b/kernel/trace/trace_kdb.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /* | ||
2 | * kdb helper for dumping the ftrace buffer | ||
3 | * | ||
4 | * Copyright (C) 2010 Jason Wessel <jason.wessel@windriver.com> | ||
5 | * | ||
6 | * ftrace_dump_buf based on ftrace_dump: | ||
7 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> | ||
8 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> | ||
9 | * | ||
10 | */ | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/kgdb.h> | ||
13 | #include <linux/kdb.h> | ||
14 | #include <linux/ftrace.h> | ||
15 | |||
16 | #include "../debug/kdb/kdb_private.h" | ||
17 | #include "trace.h" | ||
18 | #include "trace_output.h" | ||
19 | |||
20 | static void ftrace_dump_buf(int skip_lines) | ||
21 | { | ||
22 | /* use static because iter can be a bit big for the stack */ | ||
23 | static struct trace_iterator iter; | ||
24 | unsigned int old_userobj; | ||
25 | int cnt = 0, cpu; | ||
26 | |||
27 | trace_init_global_iter(&iter); | ||
28 | |||
29 | for_each_tracing_cpu(cpu) { | ||
30 | atomic_inc(&iter.tr->data[cpu]->disabled); | ||
31 | } | ||
32 | |||
33 | old_userobj = trace_flags; | ||
34 | |||
35 | /* don't look at user memory in panic mode */ | ||
36 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; | ||
37 | |||
38 | kdb_printf("Dumping ftrace buffer:\n"); | ||
39 | |||
40 | /* reset all but tr, trace, and overruns */ | ||
41 | memset(&iter.seq, 0, | ||
42 | sizeof(struct trace_iterator) - | ||
43 | offsetof(struct trace_iterator, seq)); | ||
44 | iter.iter_flags |= TRACE_FILE_LAT_FMT; | ||
45 | iter.pos = -1; | ||
46 | |||
47 | for_each_tracing_cpu(cpu) { | ||
48 | iter.buffer_iter[cpu] = | ||
49 | ring_buffer_read_prepare(iter.tr->buffer, cpu); | ||
50 | ring_buffer_read_start(iter.buffer_iter[cpu]); | ||
51 | tracing_iter_reset(&iter, cpu); | ||
52 | } | ||
53 | |||
54 | if (!trace_empty(&iter)) | ||
55 | trace_find_next_entry_inc(&iter); | ||
56 | while (!trace_empty(&iter)) { | ||
57 | if (!cnt) | ||
58 | kdb_printf("---------------------------------\n"); | ||
59 | cnt++; | ||
60 | |||
61 | if (trace_find_next_entry_inc(&iter) != NULL && !skip_lines) | ||
62 | print_trace_line(&iter); | ||
63 | if (!skip_lines) | ||
64 | trace_printk_seq(&iter.seq); | ||
65 | else | ||
66 | skip_lines--; | ||
67 | if (KDB_FLAG(CMD_INTERRUPT)) | ||
68 | goto out; | ||
69 | } | ||
70 | |||
71 | if (!cnt) | ||
72 | kdb_printf(" (ftrace buffer empty)\n"); | ||
73 | else | ||
74 | kdb_printf("---------------------------------\n"); | ||
75 | |||
76 | out: | ||
77 | trace_flags = old_userobj; | ||
78 | |||
79 | for_each_tracing_cpu(cpu) { | ||
80 | atomic_dec(&iter.tr->data[cpu]->disabled); | ||
81 | } | ||
82 | |||
83 | for_each_tracing_cpu(cpu) | ||
84 | if (iter.buffer_iter[cpu]) | ||
85 | ring_buffer_read_finish(iter.buffer_iter[cpu]); | ||
86 | } | ||
87 | |||
88 | /* | ||
89 | * kdb_ftdump - Dump the ftrace log buffer | ||
90 | */ | ||
91 | static int kdb_ftdump(int argc, const char **argv) | ||
92 | { | ||
93 | int skip_lines = 0; | ||
94 | char *cp; | ||
95 | |||
96 | if (argc > 1) | ||
97 | return KDB_ARGCOUNT; | ||
98 | |||
99 | if (argc) { | ||
100 | skip_lines = simple_strtol(argv[1], &cp, 0); | ||
101 | if (*cp) | ||
102 | skip_lines = 0; | ||
103 | } | ||
104 | |||
105 | kdb_trap_printk++; | ||
106 | ftrace_dump_buf(skip_lines); | ||
107 | kdb_trap_printk--; | ||
108 | |||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static __init int kdb_ftrace_register(void) | ||
113 | { | ||
114 | kdb_register_repeat("ftdump", kdb_ftdump, "", "Dump ftrace log", | ||
115 | 0, KDB_REPEAT_NONE); | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | late_initcall(kdb_ftrace_register); | ||