tracing: protect reader of cmdline output
[linux-2.6] / kernel / trace / trace_output.c
1 /*
2  * trace_output.c
3  *
4  * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
5  *
6  */
7
8 #include <linux/module.h>
9 #include <linux/mutex.h>
10 #include <linux/ftrace.h>
11
12 #include "trace_output.h"
13
14 /* must be a power of 2 */
15 #define EVENT_HASHSIZE  128
16
17 static DEFINE_MUTEX(trace_event_mutex);
18 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
19
20 static int next_event_type = __TRACE_LAST_TYPE + 1;
21
22 /**
23  * trace_seq_printf - sequence printing of trace information
24  * @s: trace sequence descriptor
25  * @fmt: printf format string
26  *
27  * The tracer may use either sequence operations or its own
28  * copy to user routines. To simplify formating of a trace
29  * trace_seq_printf is used to store strings into a special
30  * buffer (@s). Then the output may be either used by
31  * the sequencer or pulled into another buffer.
32  */
33 int
34 trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
35 {
36         int len = (PAGE_SIZE - 1) - s->len;
37         va_list ap;
38         int ret;
39
40         if (!len)
41                 return 0;
42
43         va_start(ap, fmt);
44         ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
45         va_end(ap);
46
47         /* If we can't write it all, don't bother writing anything */
48         if (ret >= len)
49                 return 0;
50
51         s->len += ret;
52
53         return len;
54 }
55
56 int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
57 {
58         int len = (PAGE_SIZE - 1) - s->len;
59         int ret;
60
61         if (!len)
62                 return 0;
63
64         ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
65
66         /* If we can't write it all, don't bother writing anything */
67         if (ret >= len)
68                 return 0;
69
70         s->len += ret;
71
72         return len;
73 }
74
75 /**
76  * trace_seq_puts - trace sequence printing of simple string
77  * @s: trace sequence descriptor
78  * @str: simple string to record
79  *
80  * The tracer may use either the sequence operations or its own
81  * copy to user routines. This function records a simple string
82  * into a special buffer (@s) for later retrieval by a sequencer
83  * or other mechanism.
84  */
85 int trace_seq_puts(struct trace_seq *s, const char *str)
86 {
87         int len = strlen(str);
88
89         if (len > ((PAGE_SIZE - 1) - s->len))
90                 return 0;
91
92         memcpy(s->buffer + s->len, str, len);
93         s->len += len;
94
95         return len;
96 }
97
98 int trace_seq_putc(struct trace_seq *s, unsigned char c)
99 {
100         if (s->len >= (PAGE_SIZE - 1))
101                 return 0;
102
103         s->buffer[s->len++] = c;
104
105         return 1;
106 }
107
108 int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
109 {
110         if (len > ((PAGE_SIZE - 1) - s->len))
111                 return 0;
112
113         memcpy(s->buffer + s->len, mem, len);
114         s->len += len;
115
116         return len;
117 }
118
119 int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
120 {
121         unsigned char hex[HEX_CHARS];
122         unsigned char *data = mem;
123         int i, j;
124
125 #ifdef __BIG_ENDIAN
126         for (i = 0, j = 0; i < len; i++) {
127 #else
128         for (i = len-1, j = 0; i >= 0; i--) {
129 #endif
130                 hex[j++] = hex_asc_hi(data[i]);
131                 hex[j++] = hex_asc_lo(data[i]);
132         }
133         hex[j++] = ' ';
134
135         return trace_seq_putmem(s, hex, j);
136 }
137
138 int trace_seq_path(struct trace_seq *s, struct path *path)
139 {
140         unsigned char *p;
141
142         if (s->len >= (PAGE_SIZE - 1))
143                 return 0;
144         p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
145         if (!IS_ERR(p)) {
146                 p = mangle_path(s->buffer + s->len, p, "\n");
147                 if (p) {
148                         s->len = p - s->buffer;
149                         return 1;
150                 }
151         } else {
152                 s->buffer[s->len++] = '?';
153                 return 1;
154         }
155
156         return 0;
157 }
158
159 #ifdef CONFIG_KRETPROBES
160 static inline const char *kretprobed(const char *name)
161 {
162         static const char tramp_name[] = "kretprobe_trampoline";
163         int size = sizeof(tramp_name);
164
165         if (strncmp(tramp_name, name, size) == 0)
166                 return "[unknown/kretprobe'd]";
167         return name;
168 }
169 #else
170 static inline const char *kretprobed(const char *name)
171 {
172         return name;
173 }
174 #endif /* CONFIG_KRETPROBES */
175
176 static int
177 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
178 {
179 #ifdef CONFIG_KALLSYMS
180         char str[KSYM_SYMBOL_LEN];
181         const char *name;
182
183         kallsyms_lookup(address, NULL, NULL, NULL, str);
184
185         name = kretprobed(str);
186
187         return trace_seq_printf(s, fmt, name);
188 #endif
189         return 1;
190 }
191
192 static int
193 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
194                      unsigned long address)
195 {
196 #ifdef CONFIG_KALLSYMS
197         char str[KSYM_SYMBOL_LEN];
198         const char *name;
199
200         sprint_symbol(str, address);
201         name = kretprobed(str);
202
203         return trace_seq_printf(s, fmt, name);
204 #endif
205         return 1;
206 }
207
208 #ifndef CONFIG_64BIT
209 # define IP_FMT "%08lx"
210 #else
211 # define IP_FMT "%016lx"
212 #endif
213
214 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
215                       unsigned long ip, unsigned long sym_flags)
216 {
217         struct file *file = NULL;
218         unsigned long vmstart = 0;
219         int ret = 1;
220
221         if (mm) {
222                 const struct vm_area_struct *vma;
223
224                 down_read(&mm->mmap_sem);
225                 vma = find_vma(mm, ip);
226                 if (vma) {
227                         file = vma->vm_file;
228                         vmstart = vma->vm_start;
229                 }
230                 if (file) {
231                         ret = trace_seq_path(s, &file->f_path);
232                         if (ret)
233                                 ret = trace_seq_printf(s, "[+0x%lx]",
234                                                        ip - vmstart);
235                 }
236                 up_read(&mm->mmap_sem);
237         }
238         if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
239                 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
240         return ret;
241 }
242
243 int
244 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
245                       unsigned long sym_flags)
246 {
247         struct mm_struct *mm = NULL;
248         int ret = 1;
249         unsigned int i;
250
251         if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
252                 struct task_struct *task;
253                 /*
254                  * we do the lookup on the thread group leader,
255                  * since individual threads might have already quit!
256                  */
257                 rcu_read_lock();
258                 task = find_task_by_vpid(entry->ent.tgid);
259                 if (task)
260                         mm = get_task_mm(task);
261                 rcu_read_unlock();
262         }
263
264         for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
265                 unsigned long ip = entry->caller[i];
266
267                 if (ip == ULONG_MAX || !ret)
268                         break;
269                 if (i && ret)
270                         ret = trace_seq_puts(s, " <- ");
271                 if (!ip) {
272                         if (ret)
273                                 ret = trace_seq_puts(s, "??");
274                         continue;
275                 }
276                 if (!ret)
277                         break;
278                 if (ret)
279                         ret = seq_print_user_ip(s, mm, ip, sym_flags);
280         }
281
282         if (mm)
283                 mmput(mm);
284         return ret;
285 }
286
287 int
288 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
289 {
290         int ret;
291
292         if (!ip)
293                 return trace_seq_printf(s, "0");
294
295         if (sym_flags & TRACE_ITER_SYM_OFFSET)
296                 ret = seq_print_sym_offset(s, "%s", ip);
297         else
298                 ret = seq_print_sym_short(s, "%s", ip);
299
300         if (!ret)
301                 return 0;
302
303         if (sym_flags & TRACE_ITER_SYM_ADDR)
304                 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
305         return ret;
306 }
307
308 static int
309 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
310 {
311         int hardirq, softirq;
312         char comm[TASK_COMM_LEN];
313
314         trace_find_cmdline(entry->pid, comm);
315         hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
316         softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
317
318         if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
319                               comm, entry->pid, cpu,
320                               (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
321                                 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
322                                   'X' : '.',
323                               (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
324                                 'N' : '.',
325                               (hardirq && softirq) ? 'H' :
326                                 hardirq ? 'h' : softirq ? 's' : '.'))
327                 return 0;
328
329         if (entry->preempt_count)
330                 return trace_seq_printf(s, "%x", entry->preempt_count);
331         return trace_seq_puts(s, ".");
332 }
333
334 static unsigned long preempt_mark_thresh = 100;
335
336 static int
337 lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
338                     unsigned long rel_usecs)
339 {
340         return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
341                                 rel_usecs > preempt_mark_thresh ? '!' :
342                                   rel_usecs > 1 ? '+' : ' ');
343 }
344
345 int trace_print_context(struct trace_iterator *iter)
346 {
347         struct trace_seq *s = &iter->seq;
348         struct trace_entry *entry = iter->ent;
349         unsigned long long t = ns2usecs(iter->ts);
350         unsigned long usec_rem = do_div(t, USEC_PER_SEC);
351         unsigned long secs = (unsigned long)t;
352         char comm[TASK_COMM_LEN];
353
354         trace_find_cmdline(entry->pid, comm);
355
356         return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
357                                 comm, entry->pid, iter->cpu, secs, usec_rem);
358 }
359
360 int trace_print_lat_context(struct trace_iterator *iter)
361 {
362         u64 next_ts;
363         int ret;
364         struct trace_seq *s = &iter->seq;
365         struct trace_entry *entry = iter->ent,
366                            *next_entry = trace_find_next_entry(iter, NULL,
367                                                                &next_ts);
368         unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
369         unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
370         unsigned long rel_usecs;
371
372         if (!next_entry)
373                 next_ts = iter->ts;
374         rel_usecs = ns2usecs(next_ts - iter->ts);
375
376         if (verbose) {
377                 char comm[TASK_COMM_LEN];
378
379                 trace_find_cmdline(entry->pid, comm);
380
381                 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
382                                        " %ld.%03ldms (+%ld.%03ldms): ", comm,
383                                        entry->pid, iter->cpu, entry->flags,
384                                        entry->preempt_count, iter->idx,
385                                        ns2usecs(iter->ts),
386                                        abs_usecs / USEC_PER_MSEC,
387                                        abs_usecs % USEC_PER_MSEC,
388                                        rel_usecs / USEC_PER_MSEC,
389                                        rel_usecs % USEC_PER_MSEC);
390         } else {
391                 ret = lat_print_generic(s, entry, iter->cpu);
392                 if (ret)
393                         ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
394         }
395
396         return ret;
397 }
398
399 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
400
401 static int task_state_char(unsigned long state)
402 {
403         int bit = state ? __ffs(state) + 1 : 0;
404
405         return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
406 }
407
408 /**
409  * ftrace_find_event - find a registered event
410  * @type: the type of event to look for
411  *
412  * Returns an event of type @type otherwise NULL
413  */
414 struct trace_event *ftrace_find_event(int type)
415 {
416         struct trace_event *event;
417         struct hlist_node *n;
418         unsigned key;
419
420         key = type & (EVENT_HASHSIZE - 1);
421
422         hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
423                 if (event->type == type)
424                         return event;
425         }
426
427         return NULL;
428 }
429
430 /**
431  * register_ftrace_event - register output for an event type
432  * @event: the event type to register
433  *
434  * Event types are stored in a hash and this hash is used to
435  * find a way to print an event. If the @event->type is set
436  * then it will use that type, otherwise it will assign a
437  * type to use.
438  *
439  * If you assign your own type, please make sure it is added
440  * to the trace_type enum in trace.h, to avoid collisions
441  * with the dynamic types.
442  *
443  * Returns the event type number or zero on error.
444  */
445 int register_ftrace_event(struct trace_event *event)
446 {
447         unsigned key;
448         int ret = 0;
449
450         mutex_lock(&trace_event_mutex);
451
452         if (!event->type)
453                 event->type = next_event_type++;
454         else if (event->type > __TRACE_LAST_TYPE) {
455                 printk(KERN_WARNING "Need to add type to trace.h\n");
456                 WARN_ON(1);
457         }
458
459         if (ftrace_find_event(event->type))
460                 goto out;
461
462         if (event->trace == NULL)
463                 event->trace = trace_nop_print;
464         if (event->raw == NULL)
465                 event->raw = trace_nop_print;
466         if (event->hex == NULL)
467                 event->hex = trace_nop_print;
468         if (event->binary == NULL)
469                 event->binary = trace_nop_print;
470
471         key = event->type & (EVENT_HASHSIZE - 1);
472
473         hlist_add_head_rcu(&event->node, &event_hash[key]);
474
475         ret = event->type;
476  out:
477         mutex_unlock(&trace_event_mutex);
478
479         return ret;
480 }
481
482 /**
483  * unregister_ftrace_event - remove a no longer used event
484  * @event: the event to remove
485  */
486 int unregister_ftrace_event(struct trace_event *event)
487 {
488         mutex_lock(&trace_event_mutex);
489         hlist_del(&event->node);
490         mutex_unlock(&trace_event_mutex);
491
492         return 0;
493 }
494
495 /*
496  * Standard events
497  */
498
499 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
500 {
501         return TRACE_TYPE_HANDLED;
502 }
503
504 /* TRACE_FN */
505 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
506 {
507         struct ftrace_entry *field;
508         struct trace_seq *s = &iter->seq;
509
510         trace_assign_type(field, iter->ent);
511
512         if (!seq_print_ip_sym(s, field->ip, flags))
513                 goto partial;
514
515         if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
516                 if (!trace_seq_printf(s, " <-"))
517                         goto partial;
518                 if (!seq_print_ip_sym(s,
519                                       field->parent_ip,
520                                       flags))
521                         goto partial;
522         }
523         if (!trace_seq_printf(s, "\n"))
524                 goto partial;
525
526         return TRACE_TYPE_HANDLED;
527
528  partial:
529         return TRACE_TYPE_PARTIAL_LINE;
530 }
531
532 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
533 {
534         struct ftrace_entry *field;
535
536         trace_assign_type(field, iter->ent);
537
538         if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
539                               field->ip,
540                               field->parent_ip))
541                 return TRACE_TYPE_PARTIAL_LINE;
542
543         return TRACE_TYPE_HANDLED;
544 }
545
546 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
547 {
548         struct ftrace_entry *field;
549         struct trace_seq *s = &iter->seq;
550
551         trace_assign_type(field, iter->ent);
552
553         SEQ_PUT_HEX_FIELD_RET(s, field->ip);
554         SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
555
556         return TRACE_TYPE_HANDLED;
557 }
558
559 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
560 {
561         struct ftrace_entry *field;
562         struct trace_seq *s = &iter->seq;
563
564         trace_assign_type(field, iter->ent);
565
566         SEQ_PUT_FIELD_RET(s, field->ip);
567         SEQ_PUT_FIELD_RET(s, field->parent_ip);
568
569         return TRACE_TYPE_HANDLED;
570 }
571
572 static struct trace_event trace_fn_event = {
573         .type           = TRACE_FN,
574         .trace          = trace_fn_trace,
575         .raw            = trace_fn_raw,
576         .hex            = trace_fn_hex,
577         .binary         = trace_fn_bin,
578 };
579
580 /* TRACE_CTX an TRACE_WAKE */
581 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
582                                              char *delim)
583 {
584         struct ctx_switch_entry *field;
585         char comm[TASK_COMM_LEN];
586         int S, T;
587
588
589         trace_assign_type(field, iter->ent);
590
591         T = task_state_char(field->next_state);
592         S = task_state_char(field->prev_state);
593         trace_find_cmdline(field->next_pid, comm);
594         if (!trace_seq_printf(&iter->seq,
595                               " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
596                               field->prev_pid,
597                               field->prev_prio,
598                               S, delim,
599                               field->next_cpu,
600                               field->next_pid,
601                               field->next_prio,
602                               T, comm))
603                 return TRACE_TYPE_PARTIAL_LINE;
604
605         return TRACE_TYPE_HANDLED;
606 }
607
608 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
609 {
610         return trace_ctxwake_print(iter, "==>");
611 }
612
613 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
614                                           int flags)
615 {
616         return trace_ctxwake_print(iter, "  +");
617 }
618
619 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
620 {
621         struct ctx_switch_entry *field;
622         int T;
623
624         trace_assign_type(field, iter->ent);
625
626         if (!S)
627                 task_state_char(field->prev_state);
628         T = task_state_char(field->next_state);
629         if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
630                               field->prev_pid,
631                               field->prev_prio,
632                               S,
633                               field->next_cpu,
634                               field->next_pid,
635                               field->next_prio,
636                               T))
637                 return TRACE_TYPE_PARTIAL_LINE;
638
639         return TRACE_TYPE_HANDLED;
640 }
641
642 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
643 {
644         return trace_ctxwake_raw(iter, 0);
645 }
646
647 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
648 {
649         return trace_ctxwake_raw(iter, '+');
650 }
651
652
653 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
654 {
655         struct ctx_switch_entry *field;
656         struct trace_seq *s = &iter->seq;
657         int T;
658
659         trace_assign_type(field, iter->ent);
660
661         if (!S)
662                 task_state_char(field->prev_state);
663         T = task_state_char(field->next_state);
664
665         SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
666         SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
667         SEQ_PUT_HEX_FIELD_RET(s, S);
668         SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
669         SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
670         SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
671         SEQ_PUT_HEX_FIELD_RET(s, T);
672
673         return TRACE_TYPE_HANDLED;
674 }
675
676 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
677 {
678         return trace_ctxwake_hex(iter, 0);
679 }
680
681 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
682 {
683         return trace_ctxwake_hex(iter, '+');
684 }
685
686 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
687                                            int flags)
688 {
689         struct ctx_switch_entry *field;
690         struct trace_seq *s = &iter->seq;
691
692         trace_assign_type(field, iter->ent);
693
694         SEQ_PUT_FIELD_RET(s, field->prev_pid);
695         SEQ_PUT_FIELD_RET(s, field->prev_prio);
696         SEQ_PUT_FIELD_RET(s, field->prev_state);
697         SEQ_PUT_FIELD_RET(s, field->next_pid);
698         SEQ_PUT_FIELD_RET(s, field->next_prio);
699         SEQ_PUT_FIELD_RET(s, field->next_state);
700
701         return TRACE_TYPE_HANDLED;
702 }
703
704 static struct trace_event trace_ctx_event = {
705         .type           = TRACE_CTX,
706         .trace          = trace_ctx_print,
707         .raw            = trace_ctx_raw,
708         .hex            = trace_ctx_hex,
709         .binary         = trace_ctxwake_bin,
710 };
711
712 static struct trace_event trace_wake_event = {
713         .type           = TRACE_WAKE,
714         .trace          = trace_wake_print,
715         .raw            = trace_wake_raw,
716         .hex            = trace_wake_hex,
717         .binary         = trace_ctxwake_bin,
718 };
719
720 /* TRACE_SPECIAL */
721 static enum print_line_t trace_special_print(struct trace_iterator *iter,
722                                              int flags)
723 {
724         struct special_entry *field;
725
726         trace_assign_type(field, iter->ent);
727
728         if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
729                               field->arg1,
730                               field->arg2,
731                               field->arg3))
732                 return TRACE_TYPE_PARTIAL_LINE;
733
734         return TRACE_TYPE_HANDLED;
735 }
736
737 static enum print_line_t trace_special_hex(struct trace_iterator *iter,
738                                            int flags)
739 {
740         struct special_entry *field;
741         struct trace_seq *s = &iter->seq;
742
743         trace_assign_type(field, iter->ent);
744
745         SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
746         SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
747         SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
748
749         return TRACE_TYPE_HANDLED;
750 }
751
752 static enum print_line_t trace_special_bin(struct trace_iterator *iter,
753                                            int flags)
754 {
755         struct special_entry *field;
756         struct trace_seq *s = &iter->seq;
757
758         trace_assign_type(field, iter->ent);
759
760         SEQ_PUT_FIELD_RET(s, field->arg1);
761         SEQ_PUT_FIELD_RET(s, field->arg2);
762         SEQ_PUT_FIELD_RET(s, field->arg3);
763
764         return TRACE_TYPE_HANDLED;
765 }
766
767 static struct trace_event trace_special_event = {
768         .type           = TRACE_SPECIAL,
769         .trace          = trace_special_print,
770         .raw            = trace_special_print,
771         .hex            = trace_special_hex,
772         .binary         = trace_special_bin,
773 };
774
775 /* TRACE_STACK */
776
777 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
778                                            int flags)
779 {
780         struct stack_entry *field;
781         struct trace_seq *s = &iter->seq;
782         int i;
783
784         trace_assign_type(field, iter->ent);
785
786         for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
787                 if (i) {
788                         if (!trace_seq_puts(s, " <= "))
789                                 goto partial;
790
791                         if (!seq_print_ip_sym(s, field->caller[i], flags))
792                                 goto partial;
793                 }
794                 if (!trace_seq_puts(s, "\n"))
795                         goto partial;
796         }
797
798         return TRACE_TYPE_HANDLED;
799
800  partial:
801         return TRACE_TYPE_PARTIAL_LINE;
802 }
803
804 static struct trace_event trace_stack_event = {
805         .type           = TRACE_STACK,
806         .trace          = trace_stack_print,
807         .raw            = trace_special_print,
808         .hex            = trace_special_hex,
809         .binary         = trace_special_bin,
810 };
811
812 /* TRACE_USER_STACK */
813 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
814                                                 int flags)
815 {
816         struct userstack_entry *field;
817         struct trace_seq *s = &iter->seq;
818
819         trace_assign_type(field, iter->ent);
820
821         if (!seq_print_userip_objs(field, s, flags))
822                 goto partial;
823
824         if (!trace_seq_putc(s, '\n'))
825                 goto partial;
826
827         return TRACE_TYPE_HANDLED;
828
829  partial:
830         return TRACE_TYPE_PARTIAL_LINE;
831 }
832
833 static struct trace_event trace_user_stack_event = {
834         .type           = TRACE_USER_STACK,
835         .trace          = trace_user_stack_print,
836         .raw            = trace_special_print,
837         .hex            = trace_special_hex,
838         .binary         = trace_special_bin,
839 };
840
841 /* TRACE_BPRINT */
842 static enum print_line_t
843 trace_bprint_print(struct trace_iterator *iter, int flags)
844 {
845         struct trace_entry *entry = iter->ent;
846         struct trace_seq *s = &iter->seq;
847         struct bprint_entry *field;
848
849         trace_assign_type(field, entry);
850
851         if (!seq_print_ip_sym(s, field->ip, flags))
852                 goto partial;
853
854         if (!trace_seq_puts(s, ": "))
855                 goto partial;
856
857         if (!trace_seq_bprintf(s, field->fmt, field->buf))
858                 goto partial;
859
860         return TRACE_TYPE_HANDLED;
861
862  partial:
863         return TRACE_TYPE_PARTIAL_LINE;
864 }
865
866
867 static enum print_line_t
868 trace_bprint_raw(struct trace_iterator *iter, int flags)
869 {
870         struct bprint_entry *field;
871         struct trace_seq *s = &iter->seq;
872
873         trace_assign_type(field, iter->ent);
874
875         if (!trace_seq_printf(s, ": %lx : ", field->ip))
876                 goto partial;
877
878         if (!trace_seq_bprintf(s, field->fmt, field->buf))
879                 goto partial;
880
881         return TRACE_TYPE_HANDLED;
882
883  partial:
884         return TRACE_TYPE_PARTIAL_LINE;
885 }
886
887
888 static struct trace_event trace_bprint_event = {
889         .type           = TRACE_BPRINT,
890         .trace          = trace_bprint_print,
891         .raw            = trace_bprint_raw,
892 };
893
894 /* TRACE_PRINT */
895 static enum print_line_t trace_print_print(struct trace_iterator *iter,
896                                            int flags)
897 {
898         struct print_entry *field;
899         struct trace_seq *s = &iter->seq;
900
901         trace_assign_type(field, iter->ent);
902
903         if (!seq_print_ip_sym(s, field->ip, flags))
904                 goto partial;
905
906         if (!trace_seq_printf(s, ": %s", field->buf))
907                 goto partial;
908
909         return TRACE_TYPE_HANDLED;
910
911  partial:
912         return TRACE_TYPE_PARTIAL_LINE;
913 }
914
915 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
916 {
917         struct print_entry *field;
918
919         trace_assign_type(field, iter->ent);
920
921         if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
922                 goto partial;
923
924         return TRACE_TYPE_HANDLED;
925
926  partial:
927         return TRACE_TYPE_PARTIAL_LINE;
928 }
929
930 static struct trace_event trace_print_event = {
931         .type           = TRACE_PRINT,
932         .trace          = trace_print_print,
933         .raw            = trace_print_raw,
934 };
935
936
937 static struct trace_event *events[] __initdata = {
938         &trace_fn_event,
939         &trace_ctx_event,
940         &trace_wake_event,
941         &trace_special_event,
942         &trace_stack_event,
943         &trace_user_stack_event,
944         &trace_bprint_event,
945         &trace_print_event,
946         NULL
947 };
948
949 __init static int init_events(void)
950 {
951         struct trace_event *event;
952         int i, ret;
953
954         for (i = 0; events[i]; i++) {
955                 event = events[i];
956
957                 ret = register_ftrace_event(event);
958                 if (!ret) {
959                         printk(KERN_WARNING "event %d failed to register\n",
960                                event->type);
961                         WARN_ON_ONCE(1);
962                 }
963         }
964
965         return 0;
966 }
967 device_initcall(init_events);