aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/symbol.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r--tools/perf/util/symbol.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 48c38791d61b..5fd95135e838 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -500,6 +500,64 @@ out_failure:
500 return -1; 500 return -1;
501} 501}
502 502
503int modules__parse(const char *filename, void *arg,
504 int (*process_module)(void *arg, const char *name,
505 u64 start))
506{
507 char *line = NULL;
508 size_t n;
509 FILE *file;
510 int err = 0;
511
512 file = fopen(filename, "r");
513 if (file == NULL)
514 return -1;
515
516 while (1) {
517 char name[PATH_MAX];
518 u64 start;
519 char *sep;
520 ssize_t line_len;
521
522 line_len = getline(&line, &n, file);
523 if (line_len < 0) {
524 if (feof(file))
525 break;
526 err = -1;
527 goto out;
528 }
529
530 if (!line) {
531 err = -1;
532 goto out;
533 }
534
535 line[--line_len] = '\0'; /* \n */
536
537 sep = strrchr(line, 'x');
538 if (sep == NULL)
539 continue;
540
541 hex2u64(sep + 1, &start);
542
543 sep = strchr(line, ' ');
544 if (sep == NULL)
545 continue;
546
547 *sep = '\0';
548
549 scnprintf(name, sizeof(name), "[%s]", line);
550
551 err = process_module(arg, name, start);
552 if (err)
553 break;
554 }
555out:
556 free(line);
557 fclose(file);
558 return err;
559}
560
503struct process_kallsyms_args { 561struct process_kallsyms_args {
504 struct map *map; 562 struct map *map;
505 struct dso *dso; 563 struct dso *dso;