Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 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 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 16 | #include "trace.h" |
| 17 | #include "trace_output.h" |
| 18 | |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 19 | static void ftrace_dump_buf(int skip_lines, long cpu_file) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 20 | { |
| 21 | /* use static because iter can be a bit big for the stack */ |
| 22 | static struct trace_iterator iter; |
Daniel Thompson | c270cc7 | 2014-11-06 12:41:55 +0000 | [diff] [blame] | 23 | static struct ring_buffer_iter *buffer_iter[CONFIG_NR_CPUS]; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame^] | 24 | struct trace_array *tr; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 25 | unsigned int old_userobj; |
| 26 | int cnt = 0, cpu; |
| 27 | |
| 28 | trace_init_global_iter(&iter); |
Daniel Thompson | c270cc7 | 2014-11-06 12:41:55 +0000 | [diff] [blame] | 29 | iter.buffer_iter = buffer_iter; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame^] | 30 | tr = iter.tr; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 31 | |
| 32 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 33 | atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame^] | 36 | old_userobj = tr->trace_flags; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 37 | |
| 38 | /* don't look at user memory in panic mode */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame^] | 39 | tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 40 | |
| 41 | kdb_printf("Dumping ftrace buffer:\n"); |
| 42 | |
| 43 | /* reset all but tr, trace, and overruns */ |
| 44 | memset(&iter.seq, 0, |
| 45 | sizeof(struct trace_iterator) - |
| 46 | offsetof(struct trace_iterator, seq)); |
| 47 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 48 | iter.pos = -1; |
| 49 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 50 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 51 | for_each_tracing_cpu(cpu) { |
| 52 | iter.buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 53 | ring_buffer_read_prepare(iter.trace_buffer->buffer, cpu); |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 54 | ring_buffer_read_start(iter.buffer_iter[cpu]); |
| 55 | tracing_iter_reset(&iter, cpu); |
| 56 | } |
| 57 | } else { |
| 58 | iter.cpu_file = cpu_file; |
| 59 | iter.buffer_iter[cpu_file] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 60 | ring_buffer_read_prepare(iter.trace_buffer->buffer, cpu_file); |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 61 | ring_buffer_read_start(iter.buffer_iter[cpu_file]); |
| 62 | tracing_iter_reset(&iter, cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 63 | } |
Daniel Thompson | 8520ded | 2014-11-06 12:41:56 +0000 | [diff] [blame] | 64 | |
| 65 | while (trace_find_next_entry_inc(&iter)) { |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 66 | if (!cnt) |
| 67 | kdb_printf("---------------------------------\n"); |
| 68 | cnt++; |
| 69 | |
Daniel Thompson | 8520ded | 2014-11-06 12:41:56 +0000 | [diff] [blame] | 70 | if (!skip_lines) { |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 71 | print_trace_line(&iter); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 72 | trace_printk_seq(&iter.seq); |
Daniel Thompson | 8520ded | 2014-11-06 12:41:56 +0000 | [diff] [blame] | 73 | } else { |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 74 | skip_lines--; |
Daniel Thompson | 8520ded | 2014-11-06 12:41:56 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 77 | if (KDB_FLAG(CMD_INTERRUPT)) |
| 78 | goto out; |
| 79 | } |
| 80 | |
| 81 | if (!cnt) |
| 82 | kdb_printf(" (ftrace buffer empty)\n"); |
| 83 | else |
| 84 | kdb_printf("---------------------------------\n"); |
| 85 | |
| 86 | out: |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame^] | 87 | tr->trace_flags = old_userobj; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 88 | |
| 89 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 90 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Daniel Thompson | c270cc7 | 2014-11-06 12:41:55 +0000 | [diff] [blame] | 93 | for_each_tracing_cpu(cpu) { |
| 94 | if (iter.buffer_iter[cpu]) { |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 95 | ring_buffer_read_finish(iter.buffer_iter[cpu]); |
Daniel Thompson | c270cc7 | 2014-11-06 12:41:55 +0000 | [diff] [blame] | 96 | iter.buffer_iter[cpu] = NULL; |
| 97 | } |
| 98 | } |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
| 102 | * kdb_ftdump - Dump the ftrace log buffer |
| 103 | */ |
| 104 | static int kdb_ftdump(int argc, const char **argv) |
| 105 | { |
| 106 | int skip_lines = 0; |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 107 | long cpu_file; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 108 | char *cp; |
| 109 | |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 110 | if (argc > 2) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 111 | return KDB_ARGCOUNT; |
| 112 | |
| 113 | if (argc) { |
| 114 | skip_lines = simple_strtol(argv[1], &cp, 0); |
| 115 | if (*cp) |
| 116 | skip_lines = 0; |
| 117 | } |
| 118 | |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 119 | if (argc == 2) { |
| 120 | cpu_file = simple_strtol(argv[2], &cp, 0); |
| 121 | if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 || |
| 122 | !cpu_online(cpu_file)) |
| 123 | return KDB_BADINT; |
| 124 | } else { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 125 | cpu_file = RING_BUFFER_ALL_CPUS; |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 128 | kdb_trap_printk++; |
Jason Wessel | 19063c7 | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 129 | ftrace_dump_buf(skip_lines, cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 130 | kdb_trap_printk--; |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static __init int kdb_ftrace_register(void) |
| 136 | { |
Anton Vorontsov | 42c884c | 2014-11-06 14:36:42 +0000 | [diff] [blame] | 137 | kdb_register_flags("ftdump", kdb_ftdump, "[skip_#lines] [cpu]", |
Daniel Thompson | 9452e97 | 2014-11-06 14:36:45 +0000 | [diff] [blame] | 138 | "Dump ftrace log", 0, KDB_ENABLE_ALWAYS_SAFE); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | late_initcall(kdb_ftrace_register); |