2 * probe-event.c : perf-probe definition to kprobe_events format converter
4 * Written by Masami Hiramatsu <mhiramat@redhat.com>
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
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <sys/utsname.h>
24 #include <sys/types.h>
45 #include "parse-events.h" /* For debugfs_path */
46 #include "probe-event.h"
47 #include "probe-finder.h"
49 #define MAX_CMDLEN 256
50 #define MAX_PROBE_ARGS 128
51 #define PERFPROBE_GROUP "probe"
53 bool probe_event_dry_run; /* Dry run flag */
55 #define semantic_error(msg ...) die("Semantic error :" msg)
57 /* If there is no space to write, returns -E2BIG. */
58 static int e_snprintf(char *str, size_t size, const char *format, ...)
59 __attribute__((format(printf, 3, 4)));
61 static int e_snprintf(char *str, size_t size, const char *format, ...)
66 ret = vsnprintf(str, size, format, ap);
74 static struct map_groups kmap_groups;
75 static struct map *kmaps[MAP__NR_TYPES];
77 /* Initialize symbol maps for vmlinux */
78 static void init_vmlinux(void)
80 symbol_conf.sort_by_name = true;
81 if (symbol_conf.vmlinux_name == NULL)
82 symbol_conf.try_vmlinux_path = true;
84 pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
85 if (symbol__init() < 0)
86 die("Failed to init symbol map.");
88 map_groups__init(&kmap_groups);
89 if (map_groups__create_kernel_maps(&kmap_groups, kmaps) < 0)
90 die("Failed to create kernel maps.");
93 #ifndef NO_DWARF_SUPPORT
94 static int open_vmlinux(void)
96 if (map__load(kmaps[MAP__FUNCTION], NULL) < 0) {
97 pr_debug("Failed to load kernel map.\n");
100 pr_debug("Try to open %s\n", kmaps[MAP__FUNCTION]->dso->long_name);
101 return open(kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY);
105 void parse_line_range_desc(const char *arg, struct line_range *lr)
112 * FUNC[:SLN[+NUM|-ELN]]
114 ptr = strchr(arg, ':');
116 lr->start = (unsigned int)strtoul(ptr + 1, &tmp, 0);
118 lr->end = lr->start + (unsigned int)strtoul(tmp + 1,
120 else if (*tmp == '-')
121 lr->end = (unsigned int)strtoul(tmp + 1, &tmp, 0);
124 pr_debug("Line range is %u to %u\n", lr->start, lr->end);
125 if (lr->end && lr->start > lr->end)
126 semantic_error("Start line must be smaller"
129 semantic_error("Tailing with invalid character '%d'.",
131 tmp = xstrndup(arg, (ptr - arg));
135 if (strchr(tmp, '.'))
141 /* Check the name is good for event/group */
142 static bool check_event_name(const char *name)
144 if (!isalpha(*name) && *name != '_')
146 while (*++name != '\0') {
147 if (!isalpha(*name) && !isdigit(*name) && *name != '_')
153 /* Parse probepoint definition. */
154 static void parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
156 struct perf_probe_point *pp = &pev->point;
161 * perf probe [EVENT=]SRC[:LN|;PTN]
162 * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
164 * TODO:Group name support
167 ptr = strpbrk(arg, ";=@+%");
168 if (ptr && *ptr == '=') { /* Event name */
171 ptr = strchr(arg, ':');
172 if (ptr) /* Group name is not supported yet. */
173 semantic_error("Group name is not supported yet.");
174 if (!check_event_name(arg))
175 semantic_error("%s is bad for event name -it must "
176 "follow C symbol-naming rule.", arg);
177 pev->event = xstrdup(arg);
182 ptr = strpbrk(arg, ";:+@%");
188 /* Check arg is function or file and copy it */
189 if (strchr(arg, '.')) /* File */
190 pp->file = xstrdup(arg);
192 pp->function = xstrdup(arg);
194 /* Parse other options */
198 if (c == ';') { /* Lazy pattern must be the last part */
199 pp->lazy_line = xstrdup(arg);
202 ptr = strpbrk(arg, ";:+@%");
208 case ':': /* Line number */
209 pp->line = strtoul(arg, &tmp, 0);
211 semantic_error("There is non-digit char"
214 case '+': /* Byte offset from a symbol */
215 pp->offset = strtoul(arg, &tmp, 0);
217 semantic_error("There is non-digit character"
220 case '@': /* File name */
222 semantic_error("SRC@SRC is not allowed.");
223 pp->file = xstrdup(arg);
225 case '%': /* Probe places */
226 if (strcmp(arg, "return") == 0) {
228 } else /* Others not supported yet */
229 semantic_error("%%%s is not supported.", arg);
232 DIE_IF("Program has a bug.");
237 /* Exclusion check */
238 if (pp->lazy_line && pp->line)
239 semantic_error("Lazy pattern can't be used with line number.");
241 if (pp->lazy_line && pp->offset)
242 semantic_error("Lazy pattern can't be used with offset.");
244 if (pp->line && pp->offset)
245 semantic_error("Offset can't be used with line number.");
247 if (!pp->line && !pp->lazy_line && pp->file && !pp->function)
248 semantic_error("File always requires line number or "
251 if (pp->offset && !pp->function)
252 semantic_error("Offset requires an entry function.");
254 if (pp->retprobe && !pp->function)
255 semantic_error("Return probe requires an entry function.");
257 if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe)
258 semantic_error("Offset/Line/Lazy pattern can't be used with "
261 pr_debug("symbol:%s file:%s line:%d offset:%lu return:%d lazy:%s\n",
262 pp->function, pp->file, pp->line, pp->offset, pp->retprobe,
266 /* Parse perf-probe event command */
267 void parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
272 argv = argv_split(cmd, &argc);
274 die("argv_split failed.");
275 if (argc > MAX_PROBE_ARGS + 1)
276 semantic_error("Too many arguments");
278 /* Parse probe point */
279 parse_perf_probe_point(argv[0], pev);
281 /* Copy arguments and ensure return probe has no C argument */
282 pev->nargs = argc - 1;
283 pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs);
284 for (i = 0; i < pev->nargs; i++) {
285 pev->args[i].name = xstrdup(argv[i + 1]);
286 if (is_c_varname(pev->args[i].name) && pev->point.retprobe)
287 semantic_error("You can't specify local variable for"
294 /* Return true if this perf_probe_event requires debuginfo */
295 bool perf_probe_event_need_dwarf(struct perf_probe_event *pev)
299 if (pev->point.file || pev->point.line || pev->point.lazy_line)
302 for (i = 0; i < pev->nargs; i++)
303 if (is_c_varname(pev->args[i].name))
309 /* Parse kprobe_events event into struct probe_point */
310 void parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev)
312 struct kprobe_trace_point *tp = &tev->point;
318 pr_debug("Parsing kprobe_events: %s\n", cmd);
319 argv = argv_split(cmd, &argc);
321 die("argv_split failed.");
323 semantic_error("Too less arguments.");
325 /* Scan event and group name. */
326 ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]",
327 &pr, (float *)(void *)&tev->group,
328 (float *)(void *)&tev->event);
330 semantic_error("Failed to parse event name: %s", argv[0]);
331 pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr);
333 tp->retprobe = (pr == 'r');
335 /* Scan function name and offset */
336 ret = sscanf(argv[1], "%a[^+]+%lu", (float *)(void *)&tp->symbol,
341 tev->nargs = argc - 2;
342 tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
343 for (i = 0; i < tev->nargs; i++) {
344 p = strchr(argv[i + 2], '=');
345 if (p) /* We don't need which register is assigned. */
349 tev->args[i].name = xstrdup(argv[i + 2]);
350 /* TODO: parse regs and offset */
351 tev->args[i].value = xstrdup(p);
357 /* Compose only probe point (not argument) */
358 static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
361 char offs[64] = "", line[64] = "";
364 buf = xzalloc(MAX_CMDLEN);
366 ret = e_snprintf(offs, 64, "+%lu", pp->offset);
371 ret = e_snprintf(line, 64, ":%d", pp->line);
377 ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s", pp->function,
378 offs, pp->retprobe ? "%return" : "", line);
380 ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", pp->file, line);
386 die("Failed to synthesize perf probe point: %s", strerror(-ret));
390 char *synthesize_perf_probe_command(struct perf_probe_event *pev)
395 buf = synthesize_perf_probe_point(&pev->point);
400 for (i = 0; i < pev->nargs; i++) {
401 ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
414 static int __synthesize_kprobe_trace_arg_ref(struct kprobe_trace_arg_ref *ref,
415 char **buf, size_t *buflen,
420 depth = __synthesize_kprobe_trace_arg_ref(ref->next, buf,
426 ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset);
438 static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg,
439 char *buf, size_t buflen)
444 /* Argument name or separator */
446 ret = e_snprintf(buf, buflen, " %s=", arg->name);
448 ret = e_snprintf(buf, buflen, " ");
454 /* Dereferencing arguments */
456 depth = __synthesize_kprobe_trace_arg_ref(arg->ref, &buf,
462 /* Print argument value */
463 ret = e_snprintf(buf, buflen, "%s", arg->value);
471 ret = e_snprintf(buf, buflen, ")");
481 char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev)
483 struct kprobe_trace_point *tp = &tev->point;
487 buf = xzalloc(MAX_CMDLEN);
488 len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu",
489 tp->retprobe ? 'r' : 'p',
490 tev->group, tev->event,
491 tp->symbol, tp->offset);
495 for (i = 0; i < tev->nargs; i++) {
496 ret = synthesize_kprobe_trace_arg(&tev->args[i], buf + len,
509 void convert_to_perf_probe_event(struct kprobe_trace_event *tev,
510 struct perf_probe_event *pev)
515 pev->event = xstrdup(tev->event);
516 pev->group = xstrdup(tev->group);
518 /* Convert trace_point to probe_point */
519 pev->point.function = xstrdup(tev->point.symbol);
520 pev->point.offset = tev->point.offset;
521 pev->point.retprobe = tev->point.retprobe;
523 /* Convert trace_arg to probe_arg */
524 pev->nargs = tev->nargs;
525 pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs);
526 for (i = 0; i < tev->nargs; i++)
527 if (tev->args[i].name)
528 pev->args[i].name = xstrdup(tev->args[i].name);
530 synthesize_kprobe_trace_arg(&tev->args[i], buf, 64);
531 pev->args[i].name = xstrdup(buf);
535 void clear_perf_probe_event(struct perf_probe_event *pev)
537 struct perf_probe_point *pp = &pev->point;
550 for (i = 0; i < pev->nargs; i++)
551 if (pev->args[i].name)
552 free(pev->args[i].name);
555 memset(pev, 0, sizeof(*pev));
558 void clear_kprobe_trace_event(struct kprobe_trace_event *tev)
560 struct kprobe_trace_arg_ref *ref, *next;
567 if (tev->point.symbol)
568 free(tev->point.symbol);
569 for (i = 0; i < tev->nargs; i++) {
570 if (tev->args[i].name)
571 free(tev->args[i].name);
572 if (tev->args[i].value)
573 free(tev->args[i].value);
574 ref = tev->args[i].ref;
583 memset(tev, 0, sizeof(*tev));
586 static int open_kprobe_events(bool readwrite)
591 ret = e_snprintf(buf, PATH_MAX, "%s/../kprobe_events", debugfs_path);
593 die("Failed to make kprobe_events path.");
595 if (readwrite && !probe_event_dry_run)
596 ret = open(buf, O_RDWR, O_APPEND);
598 ret = open(buf, O_RDONLY, 0);
602 die("kprobe_events file does not exist -"
603 " please rebuild with CONFIG_KPROBE_EVENT.");
605 die("Could not open kprobe_events file: %s",
611 /* Get raw string list of current kprobe_events */
612 static struct strlist *get_kprobe_trace_command_rawlist(int fd)
616 char buf[MAX_CMDLEN];
620 sl = strlist__new(true, NULL);
622 fp = fdopen(dup(fd), "r");
624 p = fgets(buf, MAX_CMDLEN, fp);
631 ret = strlist__add(sl, buf);
633 die("strlist__add failed: %s", strerror(-ret));
641 static void show_perf_probe_event(struct perf_probe_event *pev)
647 /* Synthesize only event probe point */
648 place = synthesize_perf_probe_point(&pev->point);
650 ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
652 die("Failed to copy event: %s", strerror(-ret));
653 printf(" %-40s (on %s", buf, place);
655 if (pev->nargs > 0) {
657 for (i = 0; i < pev->nargs; i++)
658 printf(" %s", pev->args[i].name);
664 /* List up current perf-probe events */
665 void show_perf_probe_events(void)
668 struct kprobe_trace_event tev;
669 struct perf_probe_event pev;
670 struct strlist *rawlist;
671 struct str_node *ent;
675 memset(&tev, 0, sizeof(tev));
676 memset(&pev, 0, sizeof(pev));
678 fd = open_kprobe_events(false);
679 rawlist = get_kprobe_trace_command_rawlist(fd);
682 strlist__for_each(ent, rawlist) {
683 parse_kprobe_trace_command(ent->s, &tev);
684 convert_to_perf_probe_event(&tev, &pev);
686 show_perf_probe_event(&pev);
687 clear_perf_probe_event(&pev);
688 clear_kprobe_trace_event(&tev);
691 strlist__delete(rawlist);
694 /* Get current perf-probe event names */
695 static struct strlist *get_kprobe_trace_event_names(int fd, bool include_group)
698 struct strlist *sl, *rawlist;
699 struct str_node *ent;
700 struct kprobe_trace_event tev;
702 memset(&tev, 0, sizeof(tev));
704 rawlist = get_kprobe_trace_command_rawlist(fd);
705 sl = strlist__new(true, NULL);
706 strlist__for_each(ent, rawlist) {
707 parse_kprobe_trace_command(ent->s, &tev);
709 if (e_snprintf(buf, 128, "%s:%s", tev.group,
711 die("Failed to copy group:event name.");
712 strlist__add(sl, buf);
714 strlist__add(sl, tev.event);
715 clear_kprobe_trace_event(&tev);
718 strlist__delete(rawlist);
723 static void write_kprobe_trace_event(int fd, struct kprobe_trace_event *tev)
726 char *buf = synthesize_kprobe_trace_command(tev);
728 pr_debug("Writing event: %s\n", buf);
729 if (!probe_event_dry_run) {
730 ret = write(fd, buf, strlen(buf));
732 die("Failed to write event: %s", strerror(errno));
737 static void get_new_event_name(char *buf, size_t len, const char *base,
738 struct strlist *namelist, bool allow_suffix)
743 ret = e_snprintf(buf, len, "%s", base);
745 die("snprintf() failed: %s", strerror(-ret));
746 if (!strlist__has_entry(namelist, buf))
750 pr_warning("Error: event \"%s\" already exists. "
751 "(Use -f to force duplicates.)\n", base);
752 die("Can't add new event.");
755 /* Try to add suffix */
756 for (i = 1; i < MAX_EVENT_INDEX; i++) {
757 ret = e_snprintf(buf, len, "%s_%d", base, i);
759 die("snprintf() failed: %s", strerror(-ret));
760 if (!strlist__has_entry(namelist, buf))
763 if (i == MAX_EVENT_INDEX)
764 die("Too many events are on the same function.");
767 static void __add_kprobe_trace_events(struct perf_probe_event *pev,
768 struct kprobe_trace_event *tevs,
769 int ntevs, bool allow_suffix)
772 struct kprobe_trace_event *tev;
774 const char *event, *group;
775 struct strlist *namelist;
777 fd = open_kprobe_events(true);
778 /* Get current event names */
779 namelist = get_kprobe_trace_event_names(fd, false);
781 printf("Add new event%s\n", (ntevs > 1) ? "s:" : ":");
782 for (i = 0; i < ntevs; i++) {
787 if (pev->point.function)
788 event = pev->point.function;
790 event = tev->point.symbol;
794 group = PERFPROBE_GROUP;
796 /* Get an unused new event name */
797 get_new_event_name(buf, 64, event, namelist, allow_suffix);
800 tev->event = xstrdup(event);
801 tev->group = xstrdup(group);
802 write_kprobe_trace_event(fd, tev);
803 /* Add added event name to namelist */
804 strlist__add(namelist, event);
806 /* Trick here - save current event/group */
809 pev->event = tev->event;
810 pev->group = tev->group;
811 show_perf_probe_event(pev);
812 /* Trick here - restore current event/group */
813 pev->event = (char *)event;
814 pev->group = (char *)group;
817 * Probes after the first probe which comes from same
818 * user input are always allowed to add suffix, because
819 * there might be several addresses corresponding to
824 /* Show how to use the event. */
825 printf("\nYou can now use it on all perf tools, such as:\n\n");
826 printf("\tperf record -e %s:%s -a sleep 1\n\n", tev->group, tev->event);
828 strlist__delete(namelist);
832 static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
833 struct kprobe_trace_event **tevs)
837 #ifndef NO_DWARF_SUPPORT
841 struct kprobe_trace_event *tev;
843 need_dwarf = perf_probe_event_need_dwarf(pev);
846 #ifdef NO_DWARF_SUPPORT
847 die("Debuginfo-analysis is not supported");
848 #else /* !NO_DWARF_SUPPORT */
849 pr_debug("Some probes require debuginfo.\n");
854 die("Could not open debuginfo file.");
856 pr_debug("Could not open vmlinux/module file."
857 " Try to use symbols.\n");
861 /* Searching probe points */
862 ntevs = find_kprobe_trace_events(fd, pev, tevs);
864 if (ntevs > 0) /* Found */
867 if (ntevs == 0) /* No error but failed to find probe point. */
868 die("Probe point '%s' not found. - probe not added.",
869 synthesize_perf_probe_point(&pev->point));
873 if (ntevs == -ENOENT)
874 pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n");
875 die("Could not analyze debuginfo.");
877 pr_debug("An error occurred in debuginfo analysis."
878 " Try to use symbols.\n");
881 #endif /* !NO_DWARF_SUPPORT */
883 /* Allocate trace event buffer */
885 tev = *tevs = xzalloc(sizeof(struct kprobe_trace_event));
887 /* Copy parameters */
888 tev->point.symbol = xstrdup(pev->point.function);
889 tev->point.offset = pev->point.offset;
890 tev->nargs = pev->nargs;
892 tev->args = xzalloc(sizeof(struct kprobe_trace_arg)
894 for (i = 0; i < tev->nargs; i++)
895 tev->args[i].value = xstrdup(pev->args[i].name);
898 /* Currently just checking function name from symbol map */
899 sym = map__find_symbol_by_name(kmaps[MAP__FUNCTION],
900 tev->point.symbol, NULL);
902 die("Kernel symbol \'%s\' not found - probe not added.",
909 struct __event_package {
910 struct perf_probe_event *pev;
911 struct kprobe_trace_event *tevs;
915 void add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
919 struct __event_package *pkgs;
921 pkgs = xzalloc(sizeof(struct __event_package) * npevs);
923 /* Init vmlinux path */
926 /* Loop 1: convert all events */
927 for (i = 0; i < npevs; i++) {
928 pkgs[i].pev = &pevs[i];
929 /* Convert with or without debuginfo */
930 pkgs[i].ntevs = convert_to_kprobe_trace_events(pkgs[i].pev,
934 /* Loop 2: add all events */
935 for (i = 0; i < npevs; i++)
936 __add_kprobe_trace_events(pkgs[i].pev, pkgs[i].tevs,
937 pkgs[i].ntevs, force_add);
938 /* TODO: cleanup all trace events? */
941 static void __del_trace_kprobe_event(int fd, struct str_node *ent)
947 /* Convert from perf-probe event to trace-kprobe event */
948 if (e_snprintf(buf, 128, "-:%s", ent->s) < 0)
949 die("Failed to copy event.");
950 p = strchr(buf + 2, ':');
952 die("Internal error: %s should have ':' but not.", ent->s);
955 pr_debug("Writing event: %s\n", buf);
956 ret = write(fd, buf, strlen(buf));
958 die("Failed to write event: %s", strerror(errno));
959 printf("Remove event: %s\n", ent->s);
962 static void del_trace_kprobe_event(int fd, const char *group,
963 const char *event, struct strlist *namelist)
966 struct str_node *ent, *n;
969 if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
970 die("Failed to copy event.");
972 if (strpbrk(buf, "*?")) { /* Glob-exp */
973 strlist__for_each_safe(ent, n, namelist)
974 if (strglobmatch(ent->s, buf)) {
976 __del_trace_kprobe_event(fd, ent);
977 strlist__remove(namelist, ent);
980 ent = strlist__find(namelist, buf);
983 __del_trace_kprobe_event(fd, ent);
984 strlist__remove(namelist, ent);
988 pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf);
991 void del_perf_probe_events(struct strlist *dellist)
994 const char *group, *event;
996 struct str_node *ent;
997 struct strlist *namelist;
999 fd = open_kprobe_events(true);
1000 /* Get current event names */
1001 namelist = get_kprobe_trace_event_names(fd, true);
1003 strlist__for_each(ent, dellist) {
1004 str = xstrdup(ent->s);
1005 pr_debug("Parsing: %s\n", str);
1006 p = strchr(str, ':');
1015 pr_debug("Group: %s, Event: %s\n", group, event);
1016 del_trace_kprobe_event(fd, group, event, namelist);
1019 strlist__delete(namelist);
1023 #define LINEBUF_SIZE 256
1024 #define NR_ADDITIONAL_LINES 2
1026 static void show_one_line(FILE *fp, unsigned int l, bool skip, bool show_num)
1028 char buf[LINEBUF_SIZE];
1029 const char *color = PERF_COLOR_BLUE;
1031 if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
1035 fprintf(stdout, "%7u %s", l, buf);
1037 color_fprintf(stdout, color, " %s", buf);
1040 while (strlen(buf) == LINEBUF_SIZE - 1 &&
1041 buf[LINEBUF_SIZE - 2] != '\n') {
1042 if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
1046 fprintf(stdout, "%s", buf);
1048 color_fprintf(stdout, color, "%s", buf);
1054 die("Source file is shorter than expected.");
1056 die("File read error: %s", strerror(errno));
1059 void show_line_range(struct line_range *lr)
1062 struct line_node *ln;
1066 /* Search a line range */
1068 fd = open_vmlinux();
1070 die("Could not open debuginfo file.");
1071 ret = find_line_range(fd, lr);
1073 die("Source line is not found.\n");
1079 fprintf(stdout, "<%s:%d>\n", lr->function,
1080 lr->start - lr->offset);
1082 fprintf(stdout, "<%s:%d>\n", lr->file, lr->start);
1084 fp = fopen(lr->path, "r");
1086 die("Failed to open %s: %s", lr->path, strerror(errno));
1087 /* Skip to starting line number */
1088 while (l < lr->start)
1089 show_one_line(fp, l++, true, false);
1091 list_for_each_entry(ln, &lr->line_list, list) {
1092 while (ln->line > l)
1093 show_one_line(fp, (l++) - lr->offset, false, false);
1094 show_one_line(fp, (l++) - lr->offset, false, true);
1097 if (lr->end == INT_MAX)
1098 lr->end = l + NR_ADDITIONAL_LINES;
1099 while (l < lr->end && !feof(fp))
1100 show_one_line(fp, (l++) - lr->offset, false, false);