]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - tools/perf/util/symbol.h
perf symbols: Mark if a symbol is idle in the library
[mirror_ubuntu-artful-kernel.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>
4383db88 14#include "build-id.h"
0776eb59 15#include "event.h"
972f393b 16#include "util.h"
a2928c42 17
89fe808a 18#ifdef HAVE_LIBELF_SUPPORT
b68e2f91
CS
19#include <libelf.h>
20#include <gelf.h>
b68e2f91 21#endif
eec185ab 22#include <elf.h>
b68e2f91 23
cdd059d7
JO
24#include "dso.h"
25
84087126
MR
26/*
27 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
28 * for newer versions we can use mmap to reduce memory usage:
29 */
89fe808a 30#ifdef HAVE_LIBELF_MMAP_SUPPORT
84087126 31# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
29a0fc9b
NK
32#else
33# define PERF_ELF_C_READ_MMAP ELF_C_READ
84087126
MR
34#endif
35
99ca4233 36#ifdef HAVE_LIBELF_SUPPORT
3938bad4
ACM
37Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
38 GElf_Shdr *shp, const char *name, size_t *idx);
99ca4233
MH
39#endif
40
247648e3 41#ifndef DMGL_PARAMS
e71e7945 42#define DMGL_NO_OPTS 0 /* For readability... */
247648e3
ACM
43#define DMGL_PARAMS (1 << 0) /* Include function args */
44#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
45#endif
46
0a77582f
MH
47#define DSO__NAME_KALLSYMS "[kernel.kallsyms]"
48#define DSO__NAME_KCORE "[kernel.kcore]"
49
171b3be9
ACM
50/** struct symbol - symtab entry
51 *
52 * @ignore - resolvable but tools ignore it (e.g. idle routines)
53 */
a2928c42
ACM
54struct symbol {
55 struct rb_node rb_node;
9cffa8d5
PM
56 u64 start;
57 u64 end;
fefb0b94 58 u16 namelen;
c408fedf 59 u8 binding;
b55cc4ed 60 u8 idle:1;
0b3c2264 61 u8 arch_sym;
a2928c42
ACM
62 char name[0];
63};
64
aeafcbaf 65void symbol__delete(struct symbol *sym);
cdd059d7 66void symbols__delete(struct rb_root *symbols);
628ada0c 67
eb948e50
MH
68/* symbols__for_each_entry - iterate over symbols (rb_root)
69 *
70 * @symbols: the rb_root of symbols
71 * @pos: the 'struct symbol *' to use as a loop cursor
72 * @nd: the 'struct rb_node *' to use as a temporary storage
73 */
74#define symbols__for_each_entry(symbols, pos, nd) \
75 for (nd = rb_first(symbols); \
76 nd && (pos = rb_entry(nd, struct symbol, rb_node)); \
77 nd = rb_next(nd))
78
1b2e2df4
ACM
79static inline size_t symbol__size(const struct symbol *sym)
80{
2c241bd3 81 return sym->end - sym->start;
1b2e2df4
ACM
82}
83
655000e7 84struct strlist;
e03eaa40 85struct intlist;
655000e7 86
b32d133a
ACM
87struct symbol_conf {
88 unsigned short priv_size;
d04b35f8 89 unsigned short nr_events;
b32d133a 90 bool try_vmlinux_path,
b01141f4 91 init_annotation,
2059fc7a 92 force,
fc2be696 93 ignore_vmlinux,
00dc8657 94 ignore_vmlinux_buildid,
0bc8d205 95 show_kernel_path,
79406cd7 96 use_modules,
680d926a 97 allow_aliases,
d599db3f
ACM
98 sort_by_name,
99 show_nr_samples,
3f2728bd 100 show_total_period,
d599db3f 101 use_callchain,
f8be1c8c 102 cumulate_callchain,
f7d87444 103 exclude_other,
85e00b55 104 show_cpu_utilization,
ec80fde7 105 initialized,
3e6a2a7f
SE
106 kptr_restrict,
107 annotate_asm_raw,
6e1f601a 108 annotate_src,
328ccdac 109 event_group,
f2148330 110 demangle,
763122ad 111 demangle_kernel,
c8302367 112 filter_relative,
8b7bad58 113 show_hist_headers,
0bc2f2f7 114 branch_callstack,
9e207ddf 115 has_filter,
b49a8fe5 116 show_ref_callgraph,
053a3989 117 hide_unresolved,
aef810ec
NK
118 raw_trace,
119 report_hierarchy;
c410a338 120 const char *vmlinux_name,
b226a5a7 121 *kallsyms_name,
9ed7e1b8 122 *source_prefix,
c410a338 123 *field_sep;
a1645ce1
ZY
124 const char *default_guest_vmlinux_name,
125 *default_guest_kallsyms,
126 *default_guest_modules;
127 const char *guestmount;
edb7c60e 128 const char *dso_list_str,
655000e7 129 *comm_list_str,
e03eaa40
DA
130 *pid_list_str,
131 *tid_list_str,
655000e7
ACM
132 *sym_list_str,
133 *col_width_list_str;
134 struct strlist *dso_list,
135 *comm_list,
a68c2c58
SE
136 *sym_list,
137 *dso_from_list,
138 *dso_to_list,
139 *sym_from_list,
140 *sym_to_list;
e03eaa40
DA
141 struct intlist *pid_list,
142 *tid_list;
ec5761ea 143 const char *symfs;
b32d133a
ACM
144};
145
75be6cf4 146extern struct symbol_conf symbol_conf;
972f393b 147
bfbba189
ACM
148struct symbol_name_rb_node {
149 struct rb_node rb_node;
150 struct symbol sym;
151};
152
972f393b
ACM
153static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
154{
155 return path__join(bf, size, symbol_conf.symfs, path);
156}
157
158#define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
159
3f067dca
ACM
160extern int vmlinux_path__nr_entries;
161extern char **vmlinux_path;
00a192b3 162
aeafcbaf 163static inline void *symbol__priv(struct symbol *sym)
00a192b3 164{
aeafcbaf 165 return ((void *)sym) - symbol_conf.priv_size;
00a192b3
ACM
166}
167
9de89fe7
ACM
168struct ref_reloc_sym {
169 const char *name;
170 u64 addr;
171 u64 unrelocated_addr;
172};
173
59fd5306
ACM
174struct map_symbol {
175 struct map *map;
176 struct symbol *sym;
177};
178
b5387528
RAV
179struct addr_map_symbol {
180 struct map *map;
181 struct symbol *sym;
182 u64 addr;
a68c2c58 183 u64 al_addr;
b5387528
RAV
184};
185
186struct branch_info {
187 struct addr_map_symbol from;
188 struct addr_map_symbol to;
189 struct branch_flags flags;
508be0df
AK
190 char *srcline_from;
191 char *srcline_to;
b5387528
RAV
192};
193
98a3b32c
SE
194struct mem_info {
195 struct addr_map_symbol iaddr;
196 struct addr_map_symbol daddr;
197 union perf_mem_data_src data_src;
198};
199
1ed091c4 200struct addr_location {
cc22e575 201 struct machine *machine;
1ed091c4
ACM
202 struct thread *thread;
203 struct map *map;
204 struct symbol *sym;
205 u64 addr;
206 char level;
b3cef7f6 207 u8 filtered;
f60f3593
AS
208 u8 cpumode;
209 s32 cpu;
0c4c4deb 210 s32 socket;
a1645ce1
ZY
211};
212
b68e2f91
CS
213struct symsrc {
214 char *name;
215 int fd;
216 enum dso_binary_type type;
217
89fe808a 218#ifdef HAVE_LIBELF_SUPPORT
b68e2f91
CS
219 Elf *elf;
220 GElf_Ehdr ehdr;
221
222 Elf_Scn *opdsec;
223 size_t opdidx;
224 GElf_Shdr opdshdr;
225
226 Elf_Scn *symtab;
227 GElf_Shdr symshdr;
228
229 Elf_Scn *dynsym;
230 size_t dynsym_idx;
231 GElf_Shdr dynshdr;
232
233 bool adjust_symbols;
c6d8f2a4 234 bool is_64_bit;
b68e2f91
CS
235#endif
236};
237
238void symsrc__destroy(struct symsrc *ss);
239int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
240 enum dso_binary_type type);
d26cd12b 241bool symsrc__has_symtab(struct symsrc *ss);
3aafe5ae 242bool symsrc__possibly_runtime(struct symsrc *ss);
b68e2f91 243
aeafcbaf
ACM
244int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
245int dso__load_vmlinux(struct dso *dso, struct map *map,
5230fb7d
ACM
246 const char *vmlinux, bool vmlinux_allocated,
247 symbol_filter_t filter);
aeafcbaf 248int dso__load_vmlinux_path(struct dso *dso, struct map *map,
9de89fe7 249 symbol_filter_t filter);
e02092b9
ACM
250int __dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
251 bool no_kcore, symbol_filter_t filter);
aeafcbaf 252int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
9de89fe7 253 symbol_filter_t filter);
cdd059d7 254
ae93a6c7
CP
255void dso__insert_symbol(struct dso *dso, enum map_type type,
256 struct symbol *sym);
257
aeafcbaf
ACM
258struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
259 u64 addr);
260struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
79406cd7 261 const char *name);
18bd7264 262struct symbol *symbol__next_by_name(struct symbol *sym);
a2928c42 263
9c00a81b
AH
264struct symbol *dso__first_symbol(struct dso *dso, enum map_type type);
265struct symbol *dso__next_symbol(struct symbol *sym);
266
2b5b8bb2
AH
267enum dso_type dso__type_fd(int fd);
268
2643ce11 269int filename__read_build_id(const char *filename, void *bf, size_t size);
f1617b40 270int sysfs__read_build_id(const char *filename, void *bf, size_t size);
316d70d6
AH
271int modules__parse(const char *filename, void *arg,
272 int (*process_module)(void *arg, const char *name,
273 u64 start));
e5a1845f
NK
274int filename__read_debuglink(const char *filename, char *debuglink,
275 size_t size);
2643ce11 276
ce80d3be
KL
277struct perf_env;
278int symbol__init(struct perf_env *env);
d65a458b 279void symbol__exit(void);
166ccc9c 280void symbol__elf_init(void);
b01141f4
ACM
281int symbol__annotation_init(void);
282
e5a1845f 283struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
fd4be130
ACM
284size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
285 const struct addr_location *al,
286 bool unknown_as_addr, FILE *fp);
a978f2ab
AN
287size_t symbol__fprintf_symname_offs(const struct symbol *sym,
288 const struct addr_location *al, FILE *fp);
fd4be130
ACM
289size_t __symbol__fprintf_symname(const struct symbol *sym,
290 const struct addr_location *al,
291 bool unknown_as_addr, FILE *fp);
547a92e0 292size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
cdd059d7 293size_t symbol__fprintf(struct symbol *sym, FILE *fp);
36a3e646 294bool symbol_type__is_a(char symbol_type, enum map_type map_type);
3f067dca
ACM
295bool symbol__restricted_filename(const char *filename,
296 const char *restricted_filename);
a7066709
HK
297int symbol__config_symfs(const struct option *opt __maybe_unused,
298 const char *dir, int unset __maybe_unused);
36a3e646 299
261360b6
CS
300int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
301 struct symsrc *runtime_ss, symbol_filter_t filter,
302 int kmodule);
a44f605b
CS
303int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
304 struct map *map, symbol_filter_t filter);
e5a1845f 305
608c34de 306void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel);
e5a1845f
NK
307void symbols__insert(struct rb_root *symbols, struct symbol *sym);
308void symbols__fixup_duplicate(struct rb_root *symbols);
309void symbols__fixup_end(struct rb_root *symbols);
310void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
311
8e0cf965
AH
312typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
313int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
314 bool *is_64_bit);
315
afba19d9
AH
316#define PERF_KCORE_EXTRACT "/tmp/perf-kcore-XXXXXX"
317
318struct kcore_extract {
319 char *kcore_filename;
320 u64 addr;
321 u64 offs;
322 u64 len;
323 char extract_filename[sizeof(PERF_KCORE_EXTRACT)];
324 int fd;
325};
326
327int kcore_extract__create(struct kcore_extract *kce);
328void kcore_extract__delete(struct kcore_extract *kce);
329
fc1b691d
AH
330int kcore_copy(const char *from_dir, const char *to_dir);
331int compare_proc_modules(const char *from, const char *to);
332
3bfe5f81
DA
333int setup_list(struct strlist **list, const char *list_str,
334 const char *list_name);
e03eaa40
DA
335int setup_intlist(struct intlist **list, const char *list_str,
336 const char *list_name);
3bfe5f81 337
d2332098
NR
338#ifdef HAVE_LIBELF_SUPPORT
339bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
0b3c2264 340void arch__sym_update(struct symbol *s, GElf_Sym *sym);
d2332098
NR
341#endif
342
fb6d5942
NR
343#define SYMBOL_A 0
344#define SYMBOL_B 1
345
346int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb);
347
060fa0c7
HK
348/* structure containing an SDT note's info */
349struct sdt_note {
350 char *name; /* name of the note*/
351 char *provider; /* provider name */
352 bool bit32; /* whether the location is 32 bits? */
353 union { /* location, base and semaphore addrs */
354 Elf64_Addr a64[3];
355 Elf32_Addr a32[3];
356 } addr;
357 struct list_head note_list; /* SDT notes' list */
358};
359
360int get_sdt_note_list(struct list_head *head, const char *target);
361int cleanup_sdt_note_list(struct list_head *sdt_notes);
362int sdt_notes__get_count(struct list_head *start);
363
364#define SDT_BASE_SCN ".stapsdt.base"
365#define SDT_NOTE_SCN ".note.stapsdt"
366#define SDT_NOTE_TYPE 3
367#define SDT_NOTE_NAME "stapsdt"
368#define NR_ADDR 3
369
8b40f521 370#endif /* __PERF_SYMBOL */