perf tools: Use __maybe_used for unused variables
[deliverable/linux.git] / tools / perf / util / symbol.h
CommitLineData
8b40f521
JK
1#ifndef __PERF_SYMBOL
2#define __PERF_SYMBOL 1
a2928c42
ACM
3
4#include <linux/types.h>
e4204992 5#include <stdbool.h>
5aab621b
ACM
6#include <stdint.h>
7#include "map.h"
b5387528 8#include "../perf.h"
5da50258 9#include <linux/list.h>
43cbcd8a 10#include <linux/rbtree.h>
5aab621b 11#include <stdio.h>
8db4841f 12#include <byteswap.h>
b771a830 13#include <libgen.h>
a2928c42 14
b68e2f91
CS
15#ifndef NO_LIBELF_SUPPORT
16#include <libelf.h>
17#include <gelf.h>
18#include <elf.h>
19#endif
20
247648e3
ACM
21#ifdef HAVE_CPLUS_DEMANGLE
22extern char *cplus_demangle(const char *, int);
23
1d037ca1 24static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i)
247648e3
ACM
25{
26 return cplus_demangle(c, i);
27}
28#else
29#ifdef NO_DEMANGLE
1d037ca1
IT
30static inline char *bfd_demangle(void __maybe_unused *v,
31 const char __maybe_unused *c,
32 int __maybe_unused i)
247648e3
ACM
33{
34 return NULL;
35}
36#else
37#include <bfd.h>
38#endif
39#endif
40
5aab621b
ACM
41int hex2u64(const char *ptr, u64 *val);
42char *strxfrchar(char *s, char from, char to);
43
84087126
MR
44/*
45 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
46 * for newer versions we can use mmap to reduce memory usage:
47 */
48#ifdef LIBELF_NO_MMAP
49# define PERF_ELF_C_READ_MMAP ELF_C_READ
50#else
51# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
52#endif
53
247648e3
ACM
54#ifndef DMGL_PARAMS
55#define DMGL_PARAMS (1 << 0) /* Include function args */
56#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
57#endif
58
5aab621b
ACM
59#define BUILD_ID_SIZE 20
60
171b3be9
ACM
61/** struct symbol - symtab entry
62 *
63 * @ignore - resolvable but tools ignore it (e.g. idle routines)
64 */
a2928c42
ACM
65struct symbol {
66 struct rb_node rb_node;
9cffa8d5
PM
67 u64 start;
68 u64 end;
fefb0b94 69 u16 namelen;
c408fedf 70 u8 binding;
171b3be9 71 bool ignore;
a2928c42
ACM
72 char name[0];
73};
74
aeafcbaf 75void symbol__delete(struct symbol *sym);
628ada0c 76
1b2e2df4
ACM
77static inline size_t symbol__size(const struct symbol *sym)
78{
79 return sym->end - sym->start + 1;
80}
81
655000e7
ACM
82struct strlist;
83
b32d133a
ACM
84struct symbol_conf {
85 unsigned short priv_size;
d04b35f8 86 unsigned short nr_events;
b32d133a 87 bool try_vmlinux_path,
0bc8d205 88 show_kernel_path,
79406cd7 89 use_modules,
d599db3f
ACM
90 sort_by_name,
91 show_nr_samples,
3f2728bd 92 show_total_period,
d599db3f 93 use_callchain,
f7d87444 94 exclude_other,
85e00b55 95 show_cpu_utilization,
ec80fde7 96 initialized,
3e6a2a7f
SE
97 kptr_restrict,
98 annotate_asm_raw,
99 annotate_src;
c410a338 100 const char *vmlinux_name,
b226a5a7 101 *kallsyms_name,
9ed7e1b8 102 *source_prefix,
c410a338 103 *field_sep;
a1645ce1
ZY
104 const char *default_guest_vmlinux_name,
105 *default_guest_kallsyms,
106 *default_guest_modules;
107 const char *guestmount;
edb7c60e 108 const char *dso_list_str,
655000e7
ACM
109 *comm_list_str,
110 *sym_list_str,
111 *col_width_list_str;
112 struct strlist *dso_list,
113 *comm_list,
a68c2c58
SE
114 *sym_list,
115 *dso_from_list,
116 *dso_to_list,
117 *sym_from_list,
118 *sym_to_list;
ec5761ea 119 const char *symfs;
b32d133a
ACM
120};
121
75be6cf4 122extern struct symbol_conf symbol_conf;
00a192b3 123
aeafcbaf 124static inline void *symbol__priv(struct symbol *sym)
00a192b3 125{
aeafcbaf 126 return ((void *)sym) - symbol_conf.priv_size;
00a192b3
ACM
127}
128
9de89fe7
ACM
129struct ref_reloc_sym {
130 const char *name;
131 u64 addr;
132 u64 unrelocated_addr;
133};
134
59fd5306
ACM
135struct map_symbol {
136 struct map *map;
137 struct symbol *sym;
0f0cbf7a
ACM
138 bool unfolded;
139 bool has_children;
59fd5306
ACM
140};
141
b5387528
RAV
142struct addr_map_symbol {
143 struct map *map;
144 struct symbol *sym;
145 u64 addr;
a68c2c58 146 u64 al_addr;
b5387528
RAV
147};
148
149struct branch_info {
150 struct addr_map_symbol from;
151 struct addr_map_symbol to;
152 struct branch_flags flags;
153};
154
1ed091c4
ACM
155struct addr_location {
156 struct thread *thread;
157 struct map *map;
158 struct symbol *sym;
159 u64 addr;
160 char level;
c410a338 161 bool filtered;
f60f3593
AS
162 u8 cpumode;
163 s32 cpu;
a1645ce1
ZY
164};
165
44f24cb3
JO
166enum dso_binary_type {
167 DSO_BINARY_TYPE__KALLSYMS = 0,
168 DSO_BINARY_TYPE__GUEST_KALLSYMS,
21ea4539
CS
169 DSO_BINARY_TYPE__VMLINUX,
170 DSO_BINARY_TYPE__GUEST_VMLINUX,
44f24cb3
JO
171 DSO_BINARY_TYPE__JAVA_JIT,
172 DSO_BINARY_TYPE__DEBUGLINK,
173 DSO_BINARY_TYPE__BUILD_ID_CACHE,
174 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
175 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
176 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
177 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
178 DSO_BINARY_TYPE__GUEST_KMODULE,
179 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
180 DSO_BINARY_TYPE__NOT_FOUND,
181};
182
a1645ce1
ZY
183enum dso_kernel_type {
184 DSO_TYPE_USER = 0,
185 DSO_TYPE_KERNEL,
186 DSO_TYPE_GUEST_KERNEL
1ed091c4
ACM
187};
188
8db4841f
JO
189enum dso_swap_type {
190 DSO_SWAP__UNSET,
191 DSO_SWAP__NO,
192 DSO_SWAP__YES,
193};
194
4dff624a
JO
195#define DSO__DATA_CACHE_SIZE 4096
196#define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
197
198struct dso_cache {
199 struct rb_node rb_node;
200 u64 offset;
201 u64 size;
202 char data[0];
203};
204
a2928c42
ACM
205struct dso {
206 struct list_head node;
6a4694a4 207 struct rb_root symbols[MAP__NR_TYPES];
79406cd7 208 struct rb_root symbol_names[MAP__NR_TYPES];
4dff624a 209 struct rb_root cache;
6e406257 210 enum dso_kernel_type kernel;
8db4841f 211 enum dso_swap_type needs_swap;
44f24cb3 212 enum dso_binary_type symtab_type;
949d160b 213 enum dso_binary_type data_type;
8d06367f 214 u8 adjust_symbols:1;
8d06367f 215 u8 has_build_id:1;
88d3d9b7 216 u8 hit:1;
d06d92b7 217 u8 annotate_warned:1;
6e406257
ACM
218 u8 sname_alloc:1;
219 u8 lname_alloc:1;
79406cd7 220 u8 sorted_by_name;
3610583c 221 u8 loaded;
8d06367f 222 u8 build_id[BUILD_ID_SIZE];
439d473b
ACM
223 const char *short_name;
224 char *long_name;
b63be8d7
ACM
225 u16 long_name_len;
226 u16 short_name_len;
a2928c42
ACM
227 char name[0];
228};
229
b68e2f91
CS
230struct symsrc {
231 char *name;
232 int fd;
233 enum dso_binary_type type;
234
235#ifndef NO_LIBELF_SUPPORT
236 Elf *elf;
237 GElf_Ehdr ehdr;
238
239 Elf_Scn *opdsec;
240 size_t opdidx;
241 GElf_Shdr opdshdr;
242
243 Elf_Scn *symtab;
244 GElf_Shdr symshdr;
245
246 Elf_Scn *dynsym;
247 size_t dynsym_idx;
248 GElf_Shdr dynshdr;
249
250 bool adjust_symbols;
251#endif
252};
253
254void symsrc__destroy(struct symsrc *ss);
255int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
256 enum dso_binary_type type);
d26cd12b 257bool symsrc__has_symtab(struct symsrc *ss);
3aafe5ae 258bool symsrc__possibly_runtime(struct symsrc *ss);
b68e2f91 259
8db4841f
JO
260#define DSO__SWAP(dso, type, val) \
261({ \
262 type ____r = val; \
263 BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \
264 if (dso->needs_swap == DSO_SWAP__YES) { \
265 switch (sizeof(____r)) { \
266 case 2: \
267 ____r = bswap_16(val); \
268 break; \
269 case 4: \
270 ____r = bswap_32(val); \
271 break; \
272 case 8: \
273 ____r = bswap_64(val); \
274 break; \
275 default: \
276 BUG_ON(1); \
277 } \
278 } \
279 ____r; \
280})
281
00a192b3 282struct dso *dso__new(const char *name);
aeafcbaf 283void dso__delete(struct dso *dso);
a2928c42 284
aeafcbaf 285int dso__name_len(const struct dso *dso);
8a6c5b26 286
aeafcbaf
ACM
287bool dso__loaded(const struct dso *dso, enum map_type type);
288bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
79406cd7 289
aeafcbaf 290static inline void dso__set_loaded(struct dso *dso, enum map_type type)
8d92c02a 291{
aeafcbaf 292 dso->loaded |= (1 << type);
8d92c02a
ACM
293}
294
aeafcbaf 295void dso__sort_by_name(struct dso *dso, enum map_type type);
3610583c 296
e5a1845f 297void dsos__add(struct list_head *head, struct dso *dso);
1c4be9ff 298struct dso *dsos__find(struct list_head *head, const char *name);
a89e5abe
ACM
299struct dso *__dsos__findnew(struct list_head *head, const char *name);
300
aeafcbaf
ACM
301int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
302int dso__load_vmlinux(struct dso *dso, struct map *map,
fd930ff9 303 const char *vmlinux, symbol_filter_t filter);
aeafcbaf 304int dso__load_vmlinux_path(struct dso *dso, struct map *map,
9de89fe7 305 symbol_filter_t filter);
aeafcbaf 306int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
9de89fe7 307 symbol_filter_t filter);
aeafcbaf 308int machine__load_kallsyms(struct machine *machine, const char *filename,
5c0541d5 309 enum map_type type, symbol_filter_t filter);
aeafcbaf 310int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
5c0541d5
ACM
311 symbol_filter_t filter);
312
1f626bc3
ACM
313size_t __dsos__fprintf(struct list_head *head, FILE *fp);
314
aeafcbaf
ACM
315size_t machine__fprintf_dsos_buildid(struct machine *machine,
316 FILE *fp, bool with_hits);
317size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
318size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
319 FILE *fp, bool with_hits);
320size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
321size_t dso__fprintf_symbols_by_name(struct dso *dso,
322 enum map_type type, FILE *fp);
323size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
b0a9ab62 324
aeafcbaf
ACM
325char dso__symtab_origin(const struct dso *dso);
326void dso__set_long_name(struct dso *dso, char *name);
327void dso__set_build_id(struct dso *dso, void *build_id);
e5a1845f 328bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
aeafcbaf
ACM
329void dso__read_running_kernel_build_id(struct dso *dso,
330 struct machine *machine);
225466f1 331struct map *dso__new_map(const char *name);
aeafcbaf
ACM
332struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
333 u64 addr);
334struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
79406cd7 335 const char *name);
a2928c42 336
2643ce11 337int filename__read_build_id(const char *filename, void *bf, size_t size);
f1617b40 338int sysfs__read_build_id(const char *filename, void *bf, size_t size);
a1645ce1 339bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
aeafcbaf 340int build_id__sprintf(const u8 *build_id, int len, char *bf);
9e201442
ACM
341int kallsyms__parse(const char *filename, void *arg,
342 int (*process_symbol)(void *arg, const char *name,
82151520 343 char type, u64 start));
e5a1845f
NK
344int filename__read_debuglink(const char *filename, char *debuglink,
345 size_t size);
2643ce11 346
aeafcbaf
ACM
347void machine__destroy_kernel_maps(struct machine *machine);
348int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
349int machine__create_kernel_maps(struct machine *machine);
5c0541d5 350
aeafcbaf
ACM
351int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
352int machines__create_guest_kernel_maps(struct rb_root *machines);
353void machines__destroy_guest_kernel_maps(struct rb_root *machines);
a1645ce1 354
75be6cf4 355int symbol__init(void);
d65a458b 356void symbol__exit(void);
166ccc9c 357void symbol__elf_init(void);
e5a1845f 358struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
a978f2ab
AN
359size_t symbol__fprintf_symname_offs(const struct symbol *sym,
360 const struct addr_location *al, FILE *fp);
547a92e0 361size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
36a3e646
ACM
362bool symbol_type__is_a(char symbol_type, enum map_type map_type);
363
aeafcbaf 364size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
b0a9ab62 365
44f24cb3
JO
366int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
367 char *root_dir, char *file, size_t size);
949d160b
JO
368
369int dso__data_fd(struct dso *dso, struct machine *machine);
370ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
371 u64 offset, u8 *data, ssize_t size);
372ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
373 struct machine *machine, u64 addr,
374 u8 *data, ssize_t size);
f7add556 375int dso__test_data(void);
261360b6
CS
376int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
377 struct symsrc *runtime_ss, symbol_filter_t filter,
378 int kmodule);
a44f605b
CS
379int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
380 struct map *map, symbol_filter_t filter);
e5a1845f
NK
381
382void symbols__insert(struct rb_root *symbols, struct symbol *sym);
383void symbols__fixup_duplicate(struct rb_root *symbols);
384void symbols__fixup_end(struct rb_root *symbols);
385void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
386
8b40f521 387#endif /* __PERF_SYMBOL */
This page took 0.136273 seconds and 5 git commands to generate.