perf symbols: Return the first entry with a given name in find_by_name method
[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>
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
MH
36#ifdef HAVE_LIBELF_SUPPORT
37extern Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
38 GElf_Shdr *shp, const char *name, size_t *idx);
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
171b3be9
ACM
47/** struct symbol - symtab entry
48 *
49 * @ignore - resolvable but tools ignore it (e.g. idle routines)
50 */
a2928c42
ACM
51struct symbol {
52 struct rb_node rb_node;
9cffa8d5
PM
53 u64 start;
54 u64 end;
fefb0b94 55 u16 namelen;
c408fedf 56 u8 binding;
171b3be9 57 bool ignore;
a2928c42
ACM
58 char name[0];
59};
60
aeafcbaf 61void symbol__delete(struct symbol *sym);
cdd059d7 62void symbols__delete(struct rb_root *symbols);
628ada0c 63
eb948e50
MH
64/* symbols__for_each_entry - iterate over symbols (rb_root)
65 *
66 * @symbols: the rb_root of symbols
67 * @pos: the 'struct symbol *' to use as a loop cursor
68 * @nd: the 'struct rb_node *' to use as a temporary storage
69 */
70#define symbols__for_each_entry(symbols, pos, nd) \
71 for (nd = rb_first(symbols); \
72 nd && (pos = rb_entry(nd, struct symbol, rb_node)); \
73 nd = rb_next(nd))
74
1b2e2df4
ACM
75static inline size_t symbol__size(const struct symbol *sym)
76{
2c241bd3 77 return sym->end - sym->start;
1b2e2df4
ACM
78}
79
655000e7
ACM
80struct strlist;
81
b32d133a
ACM
82struct symbol_conf {
83 unsigned short priv_size;
d04b35f8 84 unsigned short nr_events;
b32d133a 85 bool try_vmlinux_path,
fc2be696 86 ignore_vmlinux,
00dc8657 87 ignore_vmlinux_buildid,
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,
f8be1c8c 94 cumulate_callchain,
f7d87444 95 exclude_other,
85e00b55 96 show_cpu_utilization,
ec80fde7 97 initialized,
3e6a2a7f
SE
98 kptr_restrict,
99 annotate_asm_raw,
6e1f601a 100 annotate_src,
328ccdac 101 event_group,
f2148330 102 demangle,
763122ad 103 demangle_kernel,
c8302367 104 filter_relative,
8b7bad58
AK
105 show_hist_headers,
106 branch_callstack;
c410a338 107 const char *vmlinux_name,
b226a5a7 108 *kallsyms_name,
9ed7e1b8 109 *source_prefix,
c410a338 110 *field_sep;
a1645ce1
ZY
111 const char *default_guest_vmlinux_name,
112 *default_guest_kallsyms,
113 *default_guest_modules;
114 const char *guestmount;
edb7c60e 115 const char *dso_list_str,
655000e7
ACM
116 *comm_list_str,
117 *sym_list_str,
118 *col_width_list_str;
119 struct strlist *dso_list,
120 *comm_list,
a68c2c58
SE
121 *sym_list,
122 *dso_from_list,
123 *dso_to_list,
124 *sym_from_list,
125 *sym_to_list;
ec5761ea 126 const char *symfs;
b32d133a
ACM
127};
128
75be6cf4 129extern struct symbol_conf symbol_conf;
972f393b
ACM
130
131static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
132{
133 return path__join(bf, size, symbol_conf.symfs, path);
134}
135
136#define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
137
3f067dca
ACM
138extern int vmlinux_path__nr_entries;
139extern char **vmlinux_path;
00a192b3 140
aeafcbaf 141static inline void *symbol__priv(struct symbol *sym)
00a192b3 142{
aeafcbaf 143 return ((void *)sym) - symbol_conf.priv_size;
00a192b3
ACM
144}
145
9de89fe7
ACM
146struct ref_reloc_sym {
147 const char *name;
148 u64 addr;
149 u64 unrelocated_addr;
150};
151
59fd5306
ACM
152struct map_symbol {
153 struct map *map;
154 struct symbol *sym;
0f0cbf7a
ACM
155 bool unfolded;
156 bool has_children;
59fd5306
ACM
157};
158
b5387528
RAV
159struct addr_map_symbol {
160 struct map *map;
161 struct symbol *sym;
162 u64 addr;
a68c2c58 163 u64 al_addr;
b5387528
RAV
164};
165
166struct branch_info {
167 struct addr_map_symbol from;
168 struct addr_map_symbol to;
169 struct branch_flags flags;
170};
171
98a3b32c
SE
172struct mem_info {
173 struct addr_map_symbol iaddr;
174 struct addr_map_symbol daddr;
175 union perf_mem_data_src data_src;
176};
177
1ed091c4 178struct addr_location {
cc22e575 179 struct machine *machine;
1ed091c4
ACM
180 struct thread *thread;
181 struct map *map;
182 struct symbol *sym;
183 u64 addr;
184 char level;
b3cef7f6 185 u8 filtered;
f60f3593
AS
186 u8 cpumode;
187 s32 cpu;
a1645ce1
ZY
188};
189
b68e2f91
CS
190struct symsrc {
191 char *name;
192 int fd;
193 enum dso_binary_type type;
194
89fe808a 195#ifdef HAVE_LIBELF_SUPPORT
b68e2f91
CS
196 Elf *elf;
197 GElf_Ehdr ehdr;
198
199 Elf_Scn *opdsec;
200 size_t opdidx;
201 GElf_Shdr opdshdr;
202
203 Elf_Scn *symtab;
204 GElf_Shdr symshdr;
205
206 Elf_Scn *dynsym;
207 size_t dynsym_idx;
208 GElf_Shdr dynshdr;
209
210 bool adjust_symbols;
c6d8f2a4 211 bool is_64_bit;
b68e2f91
CS
212#endif
213};
214
215void symsrc__destroy(struct symsrc *ss);
216int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
217 enum dso_binary_type type);
d26cd12b 218bool symsrc__has_symtab(struct symsrc *ss);
3aafe5ae 219bool symsrc__possibly_runtime(struct symsrc *ss);
b68e2f91 220
aeafcbaf
ACM
221int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
222int dso__load_vmlinux(struct dso *dso, struct map *map,
5230fb7d
ACM
223 const char *vmlinux, bool vmlinux_allocated,
224 symbol_filter_t filter);
aeafcbaf 225int dso__load_vmlinux_path(struct dso *dso, struct map *map,
9de89fe7 226 symbol_filter_t filter);
aeafcbaf 227int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
9de89fe7 228 symbol_filter_t filter);
cdd059d7 229
aeafcbaf
ACM
230struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
231 u64 addr);
232struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
79406cd7 233 const char *name);
a2928c42 234
9c00a81b
AH
235struct symbol *dso__first_symbol(struct dso *dso, enum map_type type);
236struct symbol *dso__next_symbol(struct symbol *sym);
237
2b5b8bb2
AH
238enum dso_type dso__type_fd(int fd);
239
2643ce11 240int filename__read_build_id(const char *filename, void *bf, size_t size);
f1617b40 241int sysfs__read_build_id(const char *filename, void *bf, size_t size);
316d70d6
AH
242int modules__parse(const char *filename, void *arg,
243 int (*process_module)(void *arg, const char *name,
244 u64 start));
e5a1845f
NK
245int filename__read_debuglink(const char *filename, char *debuglink,
246 size_t size);
2643ce11 247
0a7e6d1b
NK
248struct perf_session_env;
249int symbol__init(struct perf_session_env *env);
d65a458b 250void symbol__exit(void);
166ccc9c 251void symbol__elf_init(void);
e5a1845f 252struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
a978f2ab
AN
253size_t symbol__fprintf_symname_offs(const struct symbol *sym,
254 const struct addr_location *al, FILE *fp);
547a92e0 255size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
cdd059d7 256size_t symbol__fprintf(struct symbol *sym, FILE *fp);
36a3e646 257bool symbol_type__is_a(char symbol_type, enum map_type map_type);
3f067dca
ACM
258bool symbol__restricted_filename(const char *filename,
259 const char *restricted_filename);
82d1deb0 260bool symbol__is_idle(struct symbol *sym);
36a3e646 261
261360b6
CS
262int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
263 struct symsrc *runtime_ss, symbol_filter_t filter,
264 int kmodule);
a44f605b
CS
265int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
266 struct map *map, symbol_filter_t filter);
e5a1845f
NK
267
268void symbols__insert(struct rb_root *symbols, struct symbol *sym);
269void symbols__fixup_duplicate(struct rb_root *symbols);
270void symbols__fixup_end(struct rb_root *symbols);
271void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
272
8e0cf965
AH
273typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
274int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
275 bool *is_64_bit);
276
afba19d9
AH
277#define PERF_KCORE_EXTRACT "/tmp/perf-kcore-XXXXXX"
278
279struct kcore_extract {
280 char *kcore_filename;
281 u64 addr;
282 u64 offs;
283 u64 len;
284 char extract_filename[sizeof(PERF_KCORE_EXTRACT)];
285 int fd;
286};
287
288int kcore_extract__create(struct kcore_extract *kce);
289void kcore_extract__delete(struct kcore_extract *kce);
290
fc1b691d
AH
291int kcore_copy(const char *from_dir, const char *to_dir);
292int compare_proc_modules(const char *from, const char *to);
293
3bfe5f81
DA
294int setup_list(struct strlist **list, const char *list_str,
295 const char *list_name);
296
8b40f521 297#endif /* __PERF_SYMBOL */
This page took 0.196459 seconds and 5 git commands to generate.