probe-event.c (72041334b8c75ae7e1da2f17ba2b7afee8f2abd7) probe-event.c (631c9def804b2c92b5cca04fb9ff7b5df9e35094)
1/*
2 * probe-event.c : perf-probe definition to kprobe_events format converter
3 *
4 * Written by Masami Hiramatsu <mhiramat@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 24 unchanged lines hidden (view full) ---

33#include <limits.h>
34
35#undef _GNU_SOURCE
36#include "event.h"
37#include "string.h"
38#include "strlist.h"
39#include "debug.h"
40#include "cache.h"
1/*
2 * probe-event.c : perf-probe definition to kprobe_events format converter
3 *
4 * Written by Masami Hiramatsu <mhiramat@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 24 unchanged lines hidden (view full) ---

33#include <limits.h>
34
35#undef _GNU_SOURCE
36#include "event.h"
37#include "string.h"
38#include "strlist.h"
39#include "debug.h"
40#include "cache.h"
41#include "color.h"
41#include "parse-events.h" /* For debugfs_path */
42#include "probe-event.h"
43
44#define MAX_CMDLEN 256
45#define MAX_PROBE_ARGS 128
46#define PERFPROBE_GROUP "probe"
47
48#define semantic_error(msg ...) die("Semantic error :" msg)

--- 9 unchanged lines hidden (view full) ---

58 va_start(ap, format);
59 ret = vsnprintf(str, size, format, ap);
60 va_end(ap);
61 if (ret >= (int)size)
62 ret = -E2BIG;
63 return ret;
64}
65
42#include "parse-events.h" /* For debugfs_path */
43#include "probe-event.h"
44
45#define MAX_CMDLEN 256
46#define MAX_PROBE_ARGS 128
47#define PERFPROBE_GROUP "probe"
48
49#define semantic_error(msg ...) die("Semantic error :" msg)

--- 9 unchanged lines hidden (view full) ---

59 va_start(ap, format);
60 ret = vsnprintf(str, size, format, ap);
61 va_end(ap);
62 if (ret >= (int)size)
63 ret = -E2BIG;
64 return ret;
65}
66
67void parse_line_range_desc(const char *arg, struct line_range *lr)
68{
69 const char *ptr;
70 char *tmp;
71 /*
72 * <Syntax>
73 * SRC:SLN[+NUM|-ELN]
74 * FUNC[:SLN[+NUM|-ELN]]
75 */
76 ptr = strchr(arg, ':');
77 if (ptr) {
78 lr->start = (unsigned int)strtoul(ptr + 1, &tmp, 0);
79 if (*tmp == '+')
80 lr->end = lr->start + (unsigned int)strtoul(tmp + 1,
81 &tmp, 0);
82 else if (*tmp == '-')
83 lr->end = (unsigned int)strtoul(tmp + 1, &tmp, 0);
84 else
85 lr->end = 0;
86 pr_debug("Line range is %u to %u\n", lr->start, lr->end);
87 if (lr->end && lr->start > lr->end)
88 semantic_error("Start line must be smaller"
89 " than end line.");
90 if (*tmp != '\0')
91 semantic_error("Tailing with invalid character '%d'.",
92 *tmp);
93 tmp = strndup(arg, (ptr - arg));
94 } else
95 tmp = strdup(arg);
96
97 if (strchr(tmp, '.'))
98 lr->file = tmp;
99 else
100 lr->function = tmp;
101}
102
66/* Check the name is good for event/group */
67static bool check_event_name(const char *name)
68{
69 if (!isalpha(*name) && *name != '_')
70 return false;
71 while (*++name != '\0') {
72 if (!isalpha(*name) && !isdigit(*name) && *name != '_')
73 return false;

--- 599 unchanged lines hidden (view full) ---

673 pr_debug("Group: %s, Event: %s\n", group, event);
674 del_trace_kprobe_event(fd, group, event, namelist);
675 free(str);
676 }
677 strlist__delete(namelist);
678 close(fd);
679}
680
103/* Check the name is good for event/group */
104static bool check_event_name(const char *name)
105{
106 if (!isalpha(*name) && *name != '_')
107 return false;
108 while (*++name != '\0') {
109 if (!isalpha(*name) && !isdigit(*name) && *name != '_')
110 return false;

--- 599 unchanged lines hidden (view full) ---

710 pr_debug("Group: %s, Event: %s\n", group, event);
711 del_trace_kprobe_event(fd, group, event, namelist);
712 free(str);
713 }
714 strlist__delete(namelist);
715 close(fd);
716}
717
718#define LINEBUF_SIZE 256
719
720static void show_one_line(FILE *fp, unsigned int l, bool skip, bool show_num)
721{
722 char buf[LINEBUF_SIZE];
723 const char *color = PERF_COLOR_BLUE;
724
725 if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
726 goto error;
727 if (!skip) {
728 if (show_num)
729 fprintf(stdout, "%7u %s", l, buf);
730 else
731 color_fprintf(stdout, color, " %s", buf);
732 }
733
734 while (strlen(buf) == LINEBUF_SIZE - 1 &&
735 buf[LINEBUF_SIZE - 2] != '\n') {
736 if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
737 goto error;
738 if (!skip) {
739 if (show_num)
740 fprintf(stdout, "%s", buf);
741 else
742 color_fprintf(stdout, color, "%s", buf);
743 }
744 }
745 return;
746error:
747 if (feof(fp))
748 die("Source file is shorter than expected.");
749 else
750 die("File read error: %s", strerror(errno));
751}
752
753void show_line_range(struct line_range *lr)
754{
755 unsigned int l = 1;
756 struct line_node *ln;
757 FILE *fp;
758
759 setup_pager();
760
761 if (lr->function)
762 fprintf(stdout, "<%s:%d>\n", lr->function,
763 lr->start - lr->offset);
764 else
765 fprintf(stdout, "<%s:%d>\n", lr->file, lr->start);
766
767 fp = fopen(lr->path, "r");
768 if (fp == NULL)
769 die("Failed to open %s: %s", lr->path, strerror(errno));
770 /* Skip to starting line number */
771 while (l < lr->start)
772 show_one_line(fp, l++, true, false);
773
774 list_for_each_entry(ln, &lr->line_list, list) {
775 while (ln->line > l)
776 show_one_line(fp, (l++) - lr->offset, false, false);
777 show_one_line(fp, (l++) - lr->offset, false, true);
778 }
779 fclose(fp);
780}