Commit 7e5e1b1404c30db5f6bc3f5203b6c21c1d244f99

Authored by Arnaldo Carvalho de Melo
1 parent c6e718ff8c

perf symbols: map_groups__find_symbol must return the map too

Tools need to know from which map in the map_group a symbol was resolved
to, so that, for isntance, we can annotate kernel modules symbols by
getting its precise name, etc.

Also add the _by_name variants for completeness.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Showing 3 changed files with 48 additions and 6 deletions Side-by-side Diff

tools/perf/builtin-kmem.c
... ... @@ -369,7 +369,8 @@
369 369 if (is_caller) {
370 370 addr = data->call_site;
371 371 if (!raw_ip)
372   - sym = map_groups__find_function(&session->kmaps, addr, NULL);
  372 + sym = map_groups__find_function(&session->kmaps,
  373 + addr, NULL, NULL);
373 374 } else
374 375 addr = data->ptr;
375 376  
tools/perf/util/map.c
... ... @@ -268,12 +268,38 @@
268 268  
269 269 struct symbol *map_groups__find_symbol(struct map_groups *self,
270 270 enum map_type type, u64 addr,
  271 + struct map **mapp,
271 272 symbol_filter_t filter)
272 273 {
273 274 struct map *map = map_groups__find(self, type, addr);
274 275  
275   - if (map != NULL)
  276 + if (map != NULL) {
  277 + if (mapp != NULL)
  278 + *mapp = map;
276 279 return map__find_symbol(map, map->map_ip(map, addr), filter);
  280 + }
  281 +
  282 + return NULL;
  283 +}
  284 +
  285 +struct symbol *map_groups__find_symbol_by_name(struct map_groups *self,
  286 + enum map_type type,
  287 + const char *name,
  288 + struct map **mapp,
  289 + symbol_filter_t filter)
  290 +{
  291 + struct rb_node *nd;
  292 +
  293 + for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
  294 + struct map *pos = rb_entry(nd, struct map, rb_node);
  295 + struct symbol *sym = map__find_symbol_by_name(pos, name, filter);
  296 +
  297 + if (sym == NULL)
  298 + continue;
  299 + if (mapp != NULL)
  300 + *mapp = pos;
  301 + return sym;
  302 + }
277 303  
278 304 return NULL;
279 305 }
tools/perf/util/map.h
... ... @@ -119,13 +119,28 @@
119 119  
120 120 struct symbol *map_groups__find_symbol(struct map_groups *self,
121 121 enum map_type type, u64 addr,
  122 + struct map **mapp,
122 123 symbol_filter_t filter);
123 124  
124   -static inline struct symbol *map_groups__find_function(struct map_groups *self,
125   - u64 addr,
126   - symbol_filter_t filter)
  125 +struct symbol *map_groups__find_symbol_by_name(struct map_groups *self,
  126 + enum map_type type,
  127 + const char *name,
  128 + struct map **mapp,
  129 + symbol_filter_t filter);
  130 +
  131 +static inline
  132 +struct symbol *map_groups__find_function(struct map_groups *self, u64 addr,
  133 + struct map **mapp, symbol_filter_t filter)
127 134 {
128   - return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter);
  135 + return map_groups__find_symbol(self, MAP__FUNCTION, addr, mapp, filter);
  136 +}
  137 +
  138 +static inline
  139 +struct symbol *map_groups__find_function_by_name(struct map_groups *self,
  140 + const char *name, struct map **mapp,
  141 + symbol_filter_t filter)
  142 +{
  143 + return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter);
129 144 }
130 145  
131 146 int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,