]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - tools/perf/util/map.c
perf symbols: Unify symbol maps
[mirror_ubuntu-jammy-kernel.git] / tools / perf / util / map.c
index a164e1ed54620f9a1e4a82a43161e8183efd1d3f..c8fe836e4c3c6704f4e990fd683ad96fc364aaff 100644 (file)
 
 static void __maps__insert(struct maps *maps, struct map *map);
 
-const char *map_type__name[MAP__NR_TYPES] = {
-       [MAP__FUNCTION] = "Functions",
-       [MAP__VARIABLE] = "Variables",
-};
-
 static inline int is_anon_memory(const char *filename, u32 flags)
 {
        return flags & MAP_HUGETLB ||
@@ -129,10 +124,8 @@ static inline bool replace_android_lib(const char *filename, char *newfilename)
        return false;
 }
 
-void map__init(struct map *map, enum map_type type,
-              u64 start, u64 end, u64 pgoff, struct dso *dso)
+void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
 {
-       map->type     = type;
        map->start    = start;
        map->end      = end;
        map->pgoff    = pgoff;
@@ -149,7 +142,7 @@ void map__init(struct map *map, enum map_type type,
 struct map *map__new(struct machine *machine, u64 start, u64 len,
                     u64 pgoff, u32 d_maj, u32 d_min, u64 ino,
                     u64 ino_gen, u32 prot, u32 flags, char *filename,
-                    enum map_type type, struct thread *thread)
+                    struct thread *thread)
 {
        struct map *map = malloc(sizeof(*map));
        struct nsinfo *nsi = NULL;
@@ -203,7 +196,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
                if (dso == NULL)
                        goto out_delete;
 
-               map__init(map, type, start, start + len, pgoff, dso);
+               map__init(map, start, start + len, pgoff, dso);
 
                if (anon || no_dso) {
                        map->map_ip = map->unmap_ip = identity__map_ip;
@@ -214,7 +207,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
                         * unnecessary map__load warning.
                         */
                        if (!(prot & PROT_EXEC))
-                               dso__set_loaded(dso, map->type);
+                               dso__set_loaded(dso);
                }
                dso->nsinfo = nsi;
                dso__put(dso);
@@ -231,7 +224,7 @@ out_delete:
  * they are loaded) and for vmlinux, where only after we load all the
  * symbols we'll know where it starts and ends.
  */
-struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
+struct map *map__new2(u64 start, struct dso *dso)
 {
        struct map *map = calloc(1, (sizeof(*map) +
                                     (dso->kernel ? sizeof(struct kmap) : 0)));
@@ -239,7 +232,7 @@ struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
                /*
                 * ->end will be filled after we load all the symbols
                 */
-               map__init(map, type, start, 0, 0, dso);
+               map__init(map, start, 0, 0, dso);
        }
 
        return map;
@@ -256,12 +249,12 @@ struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
  */
 bool __map__is_kernel(const struct map *map)
 {
-       return __machine__kernel_map(map->groups->machine, map->type) == map;
+       return machine__kernel_map(map->groups->machine) == map;
 }
 
 bool map__has_symbols(const struct map *map)
 {
-       return dso__has_symbols(map->dso, map->type);
+       return dso__has_symbols(map->dso);
 }
 
 static void map__exit(struct map *map)
@@ -284,7 +277,7 @@ void map__put(struct map *map)
 
 void map__fixup_start(struct map *map)
 {
-       struct rb_root *symbols = &map->dso->symbols[map->type];
+       struct rb_root *symbols = &map->dso->symbols;
        struct rb_node *nd = rb_first(symbols);
        if (nd != NULL) {
                struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -294,7 +287,7 @@ void map__fixup_start(struct map *map)
 
 void map__fixup_end(struct map *map)
 {
-       struct rb_root *symbols = &map->dso->symbols[map->type];
+       struct rb_root *symbols = &map->dso->symbols;
        struct rb_node *nd = rb_last(symbols);
        if (nd != NULL) {
                struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -309,7 +302,7 @@ int map__load(struct map *map)
        const char *name = map->dso->long_name;
        int nr;
 
-       if (dso__loaded(map->dso, map->type))
+       if (dso__loaded(map->dso))
                return 0;
 
        nr = dso__load(map->dso, map);
@@ -353,7 +346,7 @@ struct symbol *map__find_symbol(struct map *map, u64 addr)
        if (map__load(map) < 0)
                return NULL;
 
-       return __dso__find_symbol(map->dso, map->type, addr);
+       return dso__find_symbol(map->dso, addr);
 }
 
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
@@ -361,10 +354,10 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
        if (map__load(map) < 0)
                return NULL;
 
-       if (!dso__sorted_by_name(map->dso, map->type))
-               dso__sort_by_name(map->dso, map->type);
+       if (!dso__sorted_by_name(map->dso))
+               dso__sort_by_name(map->dso);
 
-       return __dso__find_symbol_by_name(map->dso, map->type, name);
+       return dso__find_symbol_by_name(map->dso, name);
 }
 
 struct map *map__clone(struct map *from)
@@ -499,10 +492,7 @@ static void maps__init(struct maps *maps)
 
 void map_groups__init(struct map_groups *mg, struct machine *machine)
 {
-       int i;
-       for (i = 0; i < MAP__NR_TYPES; ++i) {
-               maps__init(&mg->maps[i]);
-       }
+       maps__init(&mg->maps);
        mg->machine = machine;
        refcount_set(&mg->refcnt, 1);
 }
@@ -530,22 +520,12 @@ static void maps__exit(struct maps *maps)
 
 void map_groups__exit(struct map_groups *mg)
 {
-       int i;
-
-       for (i = 0; i < MAP__NR_TYPES; ++i)
-               maps__exit(&mg->maps[i]);
+       maps__exit(&mg->maps);
 }
 
 bool map_groups__empty(struct map_groups *mg)
 {
-       int i;
-
-       for (i = 0; i < MAP__NR_TYPES; ++i) {
-               if (maps__first(&mg->maps[i]))
-                       return false;
-       }
-
-       return true;
+       return !maps__first(&mg->maps);
 }
 
 struct map_groups *map_groups__new(struct machine *machine)
@@ -571,10 +551,9 @@ void map_groups__put(struct map_groups *mg)
 }
 
 struct symbol *map_groups__find_symbol(struct map_groups *mg,
-                                      enum map_type type, u64 addr,
-                                      struct map **mapp)
+                                      u64 addr, struct map **mapp)
 {
-       struct map *map = __map_groups__find(mg, type, addr);
+       struct map *map = map_groups__find(mg, addr);
 
        /* Ensure map is loaded before using map->map_ip */
        if (map != NULL && map__load(map) >= 0) {
@@ -613,13 +592,10 @@ out:
 }
 
 struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
-                                              enum map_type type,
                                               const char *name,
                                               struct map **mapp)
 {
-       struct symbol *sym = maps__find_symbol_by_name(&mg->maps[type], name, mapp);
-
-       return sym;
+       return maps__find_symbol_by_name(&mg->maps, name, mapp);
 }
 
 int map_groups__find_ams(struct addr_map_symbol *ams)
@@ -627,7 +603,7 @@ int map_groups__find_ams(struct addr_map_symbol *ams)
        if (ams->addr < ams->map->start || ams->addr >= ams->map->end) {
                if (ams->map->groups == NULL)
                        return -1;
-               ams->map = __map_groups__find(ams->map->groups, ams->map->type, ams->addr);
+               ams->map = map_groups__find(ams->map->groups, ams->addr);
                if (ams->map == NULL)
                        return -1;
        }
@@ -650,7 +626,7 @@ static size_t maps__fprintf(struct maps *maps, FILE *fp)
                printed += fprintf(fp, "Map:");
                printed += map__fprintf(pos, fp);
                if (verbose > 2) {
-                       printed += dso__fprintf(pos->dso, pos->type, fp);
+                       printed += dso__fprintf(pos->dso, fp);
                        printed += fprintf(fp, "--\n");
                }
        }
@@ -660,24 +636,14 @@ static size_t maps__fprintf(struct maps *maps, FILE *fp)
        return printed;
 }
 
-size_t __map_groups__fprintf_maps(struct map_groups *mg, enum map_type type,
-                                 FILE *fp)
-{
-       size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
-       return printed += maps__fprintf(&mg->maps[type], fp);
-}
-
 size_t map_groups__fprintf(struct map_groups *mg, FILE *fp)
 {
-       size_t printed = 0, i;
-       for (i = 0; i < MAP__NR_TYPES; ++i)
-               printed += __map_groups__fprintf_maps(mg, i, fp);
-       return printed;
+       return maps__fprintf(&mg->maps, fp);
 }
 
 static void __map_groups__insert(struct map_groups *mg, struct map *map)
 {
-       __maps__insert(&mg->maps[map->type], map);
+       __maps__insert(&mg->maps, map);
        map->groups = mg;
 }
 
@@ -762,19 +728,18 @@ out:
 int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
                                   FILE *fp)
 {
-       return maps__fixup_overlappings(&mg->maps[map->type], map, fp);
+       return maps__fixup_overlappings(&mg->maps, map, fp);
 }
 
 /*
  * XXX This should not really _copy_ te maps, but refcount them.
  */
-int map_groups__clone(struct thread *thread,
-                     struct map_groups *parent, enum map_type type)
+int map_groups__clone(struct thread *thread, struct map_groups *parent)
 {
        struct map_groups *mg = thread->mg;
        int err = -ENOMEM;
        struct map *map;
-       struct maps *maps = &parent->maps[type];
+       struct maps *maps = &parent->maps;
 
        down_read(&maps->lock);