Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
symbol.h
Go to the documentation of this file.
1 #ifndef __PERF_SYMBOL
2 #define __PERF_SYMBOL 1
3 
4 #include <linux/types.h>
5 #include <stdbool.h>
6 #include <stdint.h>
7 #include "map.h"
8 #include "../perf.h"
9 #include <linux/list.h>
10 #include <linux/rbtree.h>
11 #include <stdio.h>
12 #include <byteswap.h>
13 #include <libgen.h>
14 
15 #ifdef LIBELF_SUPPORT
16 #include <libelf.h>
17 #include <gelf.h>
18 #include <elf.h>
19 #endif
20 
21 #ifdef HAVE_CPLUS_DEMANGLE
22 extern char *cplus_demangle(const char *, int);
23 
24 static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i)
25 {
26  return cplus_demangle(c, i);
27 }
28 #else
29 #ifdef NO_DEMANGLE
30 static inline char *bfd_demangle(void __maybe_unused *v,
31  const char __maybe_unused *c,
32  int __maybe_unused i)
33 {
34  return NULL;
35 }
36 #else
37 #define PACKAGE 'perf'
38 #include <bfd.h>
39 #endif
40 #endif
41 
42 int hex2u64(const char *ptr, u64 *val);
43 char *strxfrchar(char *s, char from, char to);
44 
45 /*
46  * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
47  * for newer versions we can use mmap to reduce memory usage:
48  */
49 #ifdef LIBELF_MMAP
50 # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
51 #else
52 # define PERF_ELF_C_READ_MMAP ELF_C_READ
53 #endif
54 
55 #ifndef DMGL_PARAMS
56 #define DMGL_PARAMS (1 << 0) /* Include function args */
57 #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
58 #endif
59 
60 #define BUILD_ID_SIZE 20
61 
66 struct symbol {
67  struct rb_node rb_node;
72  bool ignore;
73  char name[0];
74 };
75 
76 void symbol__delete(struct symbol *sym);
77 
78 static inline size_t symbol__size(const struct symbol *sym)
79 {
80  return sym->end - sym->start + 1;
81 }
82 
83 struct strlist;
84 
85 struct symbol_conf {
86  unsigned short priv_size;
87  unsigned short nr_events;
100  annotate_src;
101  const char *vmlinux_name,
102  *kallsyms_name,
103  *source_prefix,
104  *field_sep;
108  const char *guestmount;
109  const char *dso_list_str,
110  *comm_list_str,
111  *sym_list_str,
113  struct strlist *dso_list,
114  *comm_list,
115  *sym_list,
116  *dso_from_list,
117  *dso_to_list,
118  *sym_from_list,
119  *sym_to_list;
120  const char *symfs;
121 };
122 
123 extern struct symbol_conf symbol_conf;
124 
125 static inline void *symbol__priv(struct symbol *sym)
126 {
127  return ((void *)sym) - symbol_conf.priv_size;
128 }
129 
131  const char *name;
134 };
135 
136 struct map_symbol {
137  struct map *map;
138  struct symbol *sym;
139  bool unfolded;
141 };
142 
144  struct map *map;
145  struct symbol *sym;
148 };
149 
150 struct branch_info {
154 };
155 
157  struct thread *thread;
158  struct map *map;
159  struct symbol *sym;
161  char level;
162  bool filtered;
165 };
166 
182 };
183 
188 };
189 
194 };
195 
196 #define DSO__DATA_CACHE_SIZE 4096
197 #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
198 
199 struct dso_cache {
200  struct rb_node rb_node;
203  char data[0];
204 };
205 
206 struct dso {
207  struct list_head node;
210  struct rb_root cache;
217  u8 hit:1;
224  const char *short_name;
225  char *long_name;
228  char name[0];
229 };
230 
231 struct symsrc {
232  char *name;
233  int fd;
235 
236 #ifdef LIBELF_SUPPORT
237  Elf *elf;
238  GElf_Ehdr ehdr;
239 
240  Elf_Scn *opdsec;
241  size_t opdidx;
242  GElf_Shdr opdshdr;
243 
244  Elf_Scn *symtab;
245  GElf_Shdr symshdr;
246 
247  Elf_Scn *dynsym;
248  size_t dynsym_idx;
249  GElf_Shdr dynshdr;
250 
251  bool adjust_symbols;
252 #endif
253 };
254 
255 void symsrc__destroy(struct symsrc *ss);
256 int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
257  enum dso_binary_type type);
258 bool symsrc__has_symtab(struct symsrc *ss);
259 bool symsrc__possibly_runtime(struct symsrc *ss);
260 
261 #define DSO__SWAP(dso, type, val) \
262 ({ \
263  type ____r = val; \
264  BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \
265  if (dso->needs_swap == DSO_SWAP__YES) { \
266  switch (sizeof(____r)) { \
267  case 2: \
268  ____r = bswap_16(val); \
269  break; \
270  case 4: \
271  ____r = bswap_32(val); \
272  break; \
273  case 8: \
274  ____r = bswap_64(val); \
275  break; \
276  default: \
277  BUG_ON(1); \
278  } \
279  } \
280  ____r; \
281 })
282 
283 struct dso *dso__new(const char *name);
284 void dso__delete(struct dso *dso);
285 
286 int dso__name_len(const struct dso *dso);
287 
288 bool dso__loaded(const struct dso *dso, enum map_type type);
289 bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
290 
291 static inline void dso__set_loaded(struct dso *dso, enum map_type type)
292 {
293  dso->loaded |= (1 << type);
294 }
295 
296 void dso__sort_by_name(struct dso *dso, enum map_type type);
297 
298 void dsos__add(struct list_head *head, struct dso *dso);
299 struct dso *dsos__find(struct list_head *head, const char *name);
300 struct dso *__dsos__findnew(struct list_head *head, const char *name);
301 
302 int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
303 int dso__load_vmlinux(struct dso *dso, struct map *map,
304  const char *vmlinux, symbol_filter_t filter);
305 int dso__load_vmlinux_path(struct dso *dso, struct map *map,
307 int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
309 int machine__load_kallsyms(struct machine *machine, const char *filename,
313 
314 size_t __dsos__fprintf(struct list_head *head, FILE *fp);
315 
317  FILE *fp, bool with_hits);
318 size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
319 size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
320  FILE *fp, bool with_hits);
321 size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
322 size_t dso__fprintf_symbols_by_name(struct dso *dso,
323  enum map_type type, FILE *fp);
324 size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
325 
326 char dso__symtab_origin(const struct dso *dso);
327 void dso__set_long_name(struct dso *dso, char *name);
328 void dso__set_build_id(struct dso *dso, void *build_id);
329 bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
331  struct machine *machine);
332 struct map *dso__new_map(const char *name);
333 struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
334  u64 addr);
335 struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
336  const char *name);
337 
338 int filename__read_build_id(const char *filename, void *bf, size_t size);
339 int sysfs__read_build_id(const char *filename, void *bf, size_t size);
340 bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
341 int build_id__sprintf(const u8 *build_id, int len, char *bf);
342 int kallsyms__parse(const char *filename, void *arg,
343  int (*process_symbol)(void *arg, const char *name,
344  char type, u64 start));
345 int filename__read_debuglink(const char *filename, char *debuglink,
346  size_t size);
347 
351 
352 int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
353 int machines__create_guest_kernel_maps(struct rb_root *machines);
354 void machines__destroy_guest_kernel_maps(struct rb_root *machines);
355 
356 int symbol__init(void);
357 void symbol__exit(void);
358 void symbol__elf_init(void);
359 struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
360 size_t symbol__fprintf_symname_offs(const struct symbol *sym,
361  const struct addr_location *al, FILE *fp);
362 size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
364 
365 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
366 
368  char *root_dir, char *file, size_t size);
369 
370 int dso__data_fd(struct dso *dso, struct machine *machine);
373 ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
374  struct machine *machine, u64 addr,
375  u8 *data, ssize_t size);
376 int dso__test_data(void);
377 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
378  struct symsrc *runtime_ss, symbol_filter_t filter,
379  int kmodule);
380 int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
381  struct map *map, symbol_filter_t filter);
382 
383 void symbols__insert(struct rb_root *symbols, struct symbol *sym);
385 void symbols__fixup_end(struct rb_root *symbols);
386 void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
387 
388 #endif /* __PERF_SYMBOL */