/* Find lines which match lazy pattern */ static int find_lazy_match_lines(struct list_head *head, const char *fname, const char *pat) { char *fbuf, *p1, *p2; int fd, line, nlines = -1; struct stat st; fd = open(fname, O_RDONLY); if (fd < 0) { pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); return -errno; } if (fstat(fd, &st) < 0) { pr_warning("Failed to get the size of %s: %s\n", fname, strerror(errno)); nlines = -errno; goto out_close; } nlines = -ENOMEM; fbuf = malloc(st.st_size + 2); if (fbuf == NULL) goto out_close; if (read(fd, fbuf, st.st_size) < 0) { pr_warning("Failed to read %s: %s\n", fname, strerror(errno)); nlines = -errno; goto out_free_fbuf; } fbuf[st.st_size] = '\n'; /* Dummy line */ fbuf[st.st_size + 1] = '\0'; p1 = fbuf; line = 1; nlines = 0; while ((p2 = strchr(p1, '\n')) != NULL) { *p2 = '\0'; if (strlazymatch(p1, pat)) { line_list__add_line(head, line); nlines++; } line++; p1 = p2 + 1; } out_free_fbuf: free(fbuf); out_close: close(fd); return nlines; }
/* Find lines which match lazy pattern */ static int find_lazy_match_lines(struct list_head *head, const char *fname, const char *pat) { FILE *fp; char *line = NULL; size_t line_len; ssize_t len; int count = 0, linenum = 1; fp = fopen(fname, "r"); if (!fp) { pr_warning("Failed to open %s: %s\n", fname, strerror(errno)); return -errno; } while ((len = getline(&line, &line_len, fp)) > 0) { if (line[len - 1] == '\n') line[len - 1] = '\0'; if (strlazymatch(line, pat)) { line_list__add_line(head, linenum); count++; } linenum++; } if (ferror(fp)) count = -errno; free(line); fclose(fp); if (count == 0) pr_debug("No matched lines found in %s.\n", fname); return count; }
static Dwarf_Die *find_best_scope(struct probe_finder *pf, Dwarf_Die *die_mem) { struct find_scope_param fsp = { .function = pf->pev->point.function, .file = pf->fname, .line = pf->lno, .diff = INT_MAX, .die_mem = die_mem, .found = false, }; cu_walk_functions_at(&pf->cu_die, pf->addr, find_best_scope_cb, &fsp); return fsp.found ? die_mem : NULL; } static int probe_point_line_walker(const char *fname, int lineno, Dwarf_Addr addr, void *data) { struct probe_finder *pf = data; Dwarf_Die *sc_die, die_mem; int ret; if (lineno != pf->lno || strtailcmp(fname, pf->fname) != 0) return 0; pf->addr = addr; sc_die = find_best_scope(pf, &die_mem); if (!sc_die) { pr_warning("Failed to find scope of probe point.\n"); return -ENOENT; } ret = call_probe_finder(sc_die, pf); return ret < 0 ? ret : 0; } static int find_probe_point_by_line(struct probe_finder *pf) { return die_walk_lines(&pf->cu_die, probe_point_line_walker, pf); } static int find_lazy_match_lines(struct list_head *head, const char *fname, const char *pat) { FILE *fp; char *line = NULL; size_t line_len; ssize_t len; int count = 0, linenum = 1; fp = fopen(fname, "r"); if (!fp) { pr_warning("Failed to open %s: %s\n", fname, strerror(errno)); return -errno; } while ((len = getline(&line, &line_len, fp)) > 0) { if (line[len - 1] == '\n') line[len - 1] = '\0'; if (strlazymatch(line, pat)) { line_list__add_line(head, linenum); count++; } linenum++; } if (ferror(fp)) count = -errno; free(line); fclose(fp); if (count == 0) pr_debug("No matched lines found in %s.\n", fname); return count; }