summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/arch/powerpc/util/sym-handling.c12
-rw-r--r--tools/perf/util/map.c5
-rw-r--r--tools/perf/util/map.h5
-rw-r--r--tools/perf/util/symbol.c61
-rw-r--r--tools/perf/util/symbol.h11
5 files changed, 74 insertions, 20 deletions
diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index 39dbe512b9fc..bf9a2594572c 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -52,6 +52,18 @@ int arch__compare_symbol_names(const char *namea, const char *nameb)
52 52
53 return strcmp(namea, nameb); 53 return strcmp(namea, nameb);
54} 54}
55
56int arch__compare_symbol_names_n(const char *namea, const char *nameb,
57 unsigned int n)
58{
59 /* Skip over initial dot */
60 if (*namea == '.')
61 namea++;
62 if (*nameb == '.')
63 nameb++;
64
65 return strncmp(namea, nameb, n);
66}
55#endif 67#endif
56 68
57#if defined(_CALL_ELF) && _CALL_ELF == 2 69#if defined(_CALL_ELF) && _CALL_ELF == 2
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index ebfa5d92358a..2179b2deb730 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -325,11 +325,6 @@ int map__load(struct map *map)
325 return 0; 325 return 0;
326} 326}
327 327
328int __weak arch__compare_symbol_names(const char *namea, const char *nameb)
329{
330 return strcmp(namea, nameb);
331}
332
333struct symbol *map__find_symbol(struct map *map, u64 addr) 328struct symbol *map__find_symbol(struct map *map, u64 addr)
334{ 329{
335 if (map__load(map) < 0) 330 if (map__load(map) < 0)
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index c8a5a644c0a9..f9e8ac8a52cd 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -130,13 +130,14 @@ struct thread;
130 */ 130 */
131#define __map__for_each_symbol_by_name(map, sym_name, pos) \ 131#define __map__for_each_symbol_by_name(map, sym_name, pos) \
132 for (pos = map__find_symbol_by_name(map, sym_name); \ 132 for (pos = map__find_symbol_by_name(map, sym_name); \
133 pos && arch__compare_symbol_names(pos->name, sym_name) == 0; \ 133 pos && \
134 !symbol__match_symbol_name(pos->name, sym_name, \
135 SYMBOL_TAG_INCLUDE__DEFAULT_ONLY); \
134 pos = symbol__next_by_name(pos)) 136 pos = symbol__next_by_name(pos))
135 137
136#define map__for_each_symbol_by_name(map, sym_name, pos) \ 138#define map__for_each_symbol_by_name(map, sym_name, pos) \
137 __map__for_each_symbol_by_name(map, sym_name, (pos)) 139 __map__for_each_symbol_by_name(map, sym_name, (pos))
138 140
139int arch__compare_symbol_names(const char *namea, const char *nameb);
140void map__init(struct map *map, enum map_type type, 141void map__init(struct map *map, enum map_type type,
141 u64 start, u64 end, u64 pgoff, struct dso *dso); 142 u64 start, u64 end, u64 pgoff, struct dso *dso);
142struct map *map__new(struct machine *machine, u64 start, u64 len, 143struct map *map__new(struct machine *machine, u64 start, u64 len,
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b349e8eda0e2..8f2b068ff756 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -90,6 +90,17 @@ static int prefix_underscores_count(const char *str)
90 return tail - str; 90 return tail - str;
91} 91}
92 92
93int __weak arch__compare_symbol_names(const char *namea, const char *nameb)
94{
95 return strcmp(namea, nameb);
96}
97
98int __weak arch__compare_symbol_names_n(const char *namea, const char *nameb,
99 unsigned int n)
100{
101 return strncmp(namea, nameb, n);
102}
103
93int __weak arch__choose_best_symbol(struct symbol *syma, 104int __weak arch__choose_best_symbol(struct symbol *syma,
94 struct symbol *symb __maybe_unused) 105 struct symbol *symb __maybe_unused)
95{ 106{
@@ -399,8 +410,26 @@ static void symbols__sort_by_name(struct rb_root *symbols,
399 } 410 }
400} 411}
401 412
413int symbol__match_symbol_name(const char *name, const char *str,
414 enum symbol_tag_include includes)
415{
416 const char *versioning;
417
418 if (includes == SYMBOL_TAG_INCLUDE__DEFAULT_ONLY &&
419 (versioning = strstr(name, "@@"))) {
420 int len = strlen(str);
421
422 if (len < versioning - name)
423 len = versioning - name;
424
425 return arch__compare_symbol_names_n(name, str, len);
426 } else
427 return arch__compare_symbol_names(name, str);
428}
429
402static struct symbol *symbols__find_by_name(struct rb_root *symbols, 430static struct symbol *symbols__find_by_name(struct rb_root *symbols,
403 const char *name) 431 const char *name,
432 enum symbol_tag_include includes)
404{ 433{
405 struct rb_node *n; 434 struct rb_node *n;
406 struct symbol_name_rb_node *s = NULL; 435 struct symbol_name_rb_node *s = NULL;
@@ -414,11 +443,11 @@ static struct symbol *symbols__find_by_name(struct rb_root *symbols,
414 int cmp; 443 int cmp;
415 444
416 s = rb_entry(n, struct symbol_name_rb_node, rb_node); 445 s = rb_entry(n, struct symbol_name_rb_node, rb_node);
417 cmp = arch__compare_symbol_names(name, s->sym.name); 446 cmp = symbol__match_symbol_name(s->sym.name, name, includes);
418 447
419 if (cmp < 0) 448 if (cmp > 0)
420 n = n->rb_left; 449 n = n->rb_left;
421 else if (cmp > 0) 450 else if (cmp < 0)
422 n = n->rb_right; 451 n = n->rb_right;
423 else 452 else
424 break; 453 break;
@@ -427,16 +456,17 @@ static struct symbol *symbols__find_by_name(struct rb_root *symbols,
427 if (n == NULL) 456 if (n == NULL)
428 return NULL; 457 return NULL;
429 458
430 /* return first symbol that has same name (if any) */ 459 if (includes != SYMBOL_TAG_INCLUDE__DEFAULT_ONLY)
431 for (n = rb_prev(n); n; n = rb_prev(n)) { 460 /* return first symbol that has same name (if any) */
432 struct symbol_name_rb_node *tmp; 461 for (n = rb_prev(n); n; n = rb_prev(n)) {
462 struct symbol_name_rb_node *tmp;
433 463
434 tmp = rb_entry(n, struct symbol_name_rb_node, rb_node); 464 tmp = rb_entry(n, struct symbol_name_rb_node, rb_node);
435 if (arch__compare_symbol_names(tmp->sym.name, s->sym.name)) 465 if (arch__compare_symbol_names(tmp->sym.name, s->sym.name))
436 break; 466 break;
437 467
438 s = tmp; 468 s = tmp;
439 } 469 }
440 470
441 return &s->sym; 471 return &s->sym;
442} 472}
@@ -503,7 +533,12 @@ struct symbol *symbol__next_by_name(struct symbol *sym)
503struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, 533struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
504 const char *name) 534 const char *name)
505{ 535{
506 return symbols__find_by_name(&dso->symbol_names[type], name); 536 struct symbol *s = symbols__find_by_name(&dso->symbol_names[type], name,
537 SYMBOL_TAG_INCLUDE__NONE);
538 if (!s)
539 s = symbols__find_by_name(&dso->symbol_names[type], name,
540 SYMBOL_TAG_INCLUDE__DEFAULT_ONLY);
541 return s;
507} 542}
508 543
509void dso__sort_by_name(struct dso *dso, enum map_type type) 544void dso__sort_by_name(struct dso *dso, enum map_type type)
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 7acd70fce68e..41ebba9a2eb2 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -348,8 +348,19 @@ void arch__sym_update(struct symbol *s, GElf_Sym *sym);
348#define SYMBOL_A 0 348#define SYMBOL_A 0
349#define SYMBOL_B 1 349#define SYMBOL_B 1
350 350
351int arch__compare_symbol_names(const char *namea, const char *nameb);
352int arch__compare_symbol_names_n(const char *namea, const char *nameb,
353 unsigned int n);
351int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb); 354int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb);
352 355
356enum symbol_tag_include {
357 SYMBOL_TAG_INCLUDE__NONE = 0,
358 SYMBOL_TAG_INCLUDE__DEFAULT_ONLY
359};
360
361int symbol__match_symbol_name(const char *namea, const char *nameb,
362 enum symbol_tag_include includes);
363
353/* structure containing an SDT note's info */ 364/* structure containing an SDT note's info */
354struct sdt_note { 365struct sdt_note {
355 char *name; /* name of the note*/ 366 char *name; /* name of the note*/