Linux 5.1.15
[linux/fpc-iii.git] / tools / perf / util / symbol_fprintf.c
blob02e89b02c2cefc9e0cab6c0d0059603e898685a8
1 // SPDX-License-Identifier: GPL-2.0
2 #include <elf.h>
3 #include <inttypes.h>
4 #include <stdio.h>
6 #include "map.h"
7 #include "symbol.h"
9 size_t symbol__fprintf(struct symbol *sym, FILE *fp)
11 return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n",
12 sym->start, sym->end,
13 sym->binding == STB_GLOBAL ? 'g' :
14 sym->binding == STB_LOCAL ? 'l' : 'w',
15 sym->name);
18 size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
19 const struct addr_location *al,
20 bool unknown_as_addr,
21 bool print_offsets, FILE *fp)
23 unsigned long offset;
24 size_t length;
26 if (sym) {
27 length = fprintf(fp, "%s", sym->name);
28 if (al && print_offsets) {
29 if (al->addr < sym->end)
30 offset = al->addr - sym->start;
31 else
32 offset = al->addr - al->map->start - sym->start;
33 length += fprintf(fp, "+0x%lx", offset);
35 return length;
36 } else if (al && unknown_as_addr)
37 return fprintf(fp, "[%#" PRIx64 "]", al->addr);
38 else
39 return fprintf(fp, "[unknown]");
42 size_t symbol__fprintf_symname_offs(const struct symbol *sym,
43 const struct addr_location *al,
44 FILE *fp)
46 return __symbol__fprintf_symname_offs(sym, al, false, true, fp);
49 size_t __symbol__fprintf_symname(const struct symbol *sym,
50 const struct addr_location *al,
51 bool unknown_as_addr, FILE *fp)
53 return __symbol__fprintf_symname_offs(sym, al, unknown_as_addr, false, fp);
56 size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
58 return __symbol__fprintf_symname_offs(sym, NULL, false, false, fp);
61 size_t dso__fprintf_symbols_by_name(struct dso *dso,
62 FILE *fp)
64 size_t ret = 0;
65 struct rb_node *nd;
66 struct symbol_name_rb_node *pos;
68 for (nd = rb_first_cached(&dso->symbol_names); nd; nd = rb_next(nd)) {
69 pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
70 fprintf(fp, "%s\n", pos->sym.name);
73 return ret;