blob: e6a59e5c2beaddb5a2440228772457f3cb52ac47 [file] [log] [blame]
John Kacur8b40f522009-09-24 18:02:18 +02001#ifndef __PERF_SYMBOL
2#define __PERF_SYMBOL 1
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -03003
4#include <linux/types.h>
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -02005#include <stdbool.h>
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +02006#include "types.h"
Arnaldo Carvalho de Melo5da50252009-07-01 14:46:08 -03007#include <linux/list.h>
Arnaldo Carvalho de Melo43cbcd82009-07-01 12:28:37 -03008#include <linux/rbtree.h>
Frederic Weisbecker66e274f2009-08-12 11:07:25 +02009#include "event.h"
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030010
Arnaldo Carvalho de Melo4cf40132009-12-27 21:37:06 -020011#define DEBUG_CACHE_DIR ".debug"
12
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030013#ifdef HAVE_CPLUS_DEMANGLE
14extern char *cplus_demangle(const char *, int);
15
16static inline char *bfd_demangle(void __used *v, const char *c, int i)
17{
18 return cplus_demangle(c, i);
19}
20#else
21#ifdef NO_DEMANGLE
22static inline char *bfd_demangle(void __used *v, const char __used *c,
23 int __used i)
24{
25 return NULL;
26}
27#else
28#include <bfd.h>
29#endif
30#endif
31
Marti Raudsepp84087122009-10-24 19:10:36 +030032/*
33 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
34 * for newer versions we can use mmap to reduce memory usage:
35 */
36#ifdef LIBELF_NO_MMAP
37# define PERF_ELF_C_READ_MMAP ELF_C_READ
38#else
39# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
40#endif
41
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030042#ifndef DMGL_PARAMS
43#define DMGL_PARAMS (1 << 0) /* Include function args */
44#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
45#endif
46
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030047struct symbol {
48 struct rb_node rb_node;
Paul Mackerras9cffa8d2009-06-19 22:21:42 +100049 u64 start;
50 u64 end;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030051 char name[0];
52};
53
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020054struct strlist;
55
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020056struct symbol_conf {
57 unsigned short priv_size;
58 bool try_vmlinux_path,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -020059 use_modules,
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -020060 sort_by_name,
61 show_nr_samples,
62 use_callchain,
Arnaldo Carvalho de Melof7d87442009-12-27 21:37:04 -020063 exclude_other,
64 full_paths;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020065 const char *vmlinux_name,
66 *field_sep;
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020067 char *dso_list_str,
68 *comm_list_str,
69 *sym_list_str,
70 *col_width_list_str;
71 struct strlist *dso_list,
72 *comm_list,
73 *sym_list;
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020074};
75
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -020076extern struct symbol_conf symbol_conf;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020077
78static inline void *symbol__priv(struct symbol *self)
79{
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -020080 return ((void *)self) - symbol_conf.priv_size;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020081}
82
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020083struct ref_reloc_sym {
84 const char *name;
85 u64 addr;
86 u64 unrelocated_addr;
87};
88
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020089struct addr_location {
90 struct thread *thread;
91 struct map *map;
92 struct symbol *sym;
93 u64 addr;
94 char level;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020095 bool filtered;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020096};
97
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030098struct dso {
99 struct list_head node;
Arnaldo Carvalho de Melo6a4694a2009-11-27 16:29:17 -0200100 struct rb_root symbols[MAP__NR_TYPES];
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200101 struct rb_root symbol_names[MAP__NR_TYPES];
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200102 u8 adjust_symbols:1;
103 u8 slen_calculated:1;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200104 u8 has_build_id:1;
Arnaldo Carvalho de Meloc338aee2009-11-20 20:51:27 -0200105 u8 kernel:1;
Arnaldo Carvalho de Melo88d3d9b72010-01-14 23:45:30 -0200106 u8 hit:1;
Arnaldo Carvalho de Melo94cb9e32009-08-06 14:43:17 -0300107 unsigned char origin;
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200108 u8 sorted_by_name;
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200109 u8 loaded;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200110 u8 build_id[BUILD_ID_SIZE];
Arnaldo Carvalho de Melocfc10d32009-11-17 15:40:53 -0200111 u16 long_name_len;
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -0300112 const char *short_name;
113 char *long_name;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300114 char name[0];
115};
116
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200117struct dso *dso__new(const char *name);
Arnaldo Carvalho de Melofd1d9082010-01-27 21:05:51 -0200118struct dso *dso__new_kernel(const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300119void dso__delete(struct dso *self);
120
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200121bool dso__loaded(const struct dso *self, enum map_type type);
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200122bool dso__sorted_by_name(const struct dso *self, enum map_type type);
123
124void dso__sort_by_name(struct dso *self, enum map_type type);
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200125
Arnaldo Carvalho de Meloa89e5abe2010-01-07 19:59:39 -0200126extern struct list_head dsos__user, dsos__kernel;
127
128struct dso *__dsos__findnew(struct list_head *head, const char *name);
129
130static inline struct dso *dsos__findnew(const char *name)
131{
132 return __dsos__findnew(&dsos__user, name);
133}
134
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200135int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
Arnaldo Carvalho de Meloa19afe42010-01-27 21:05:50 -0200136int dso__load_vmlinux_path(struct dso *self, struct map *map,
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200137 symbol_filter_t filter);
138int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
139 symbol_filter_t filter);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +0200140void dsos__fprintf(FILE *fp);
Arnaldo Carvalho de Melo88d3d9b72010-01-14 23:45:30 -0200141size_t dsos__fprintf_buildid(FILE *fp, bool with_hits);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300142
Arnaldo Carvalho de Melo9e03eb22009-11-16 16:32:44 -0200143size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
Arnaldo Carvalho de Melo95011c62009-11-27 16:29:20 -0200144size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
Arnaldo Carvalho de Melo94cb9e32009-08-06 14:43:17 -0300145char dso__symtab_origin(const struct dso *self);
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200146void dso__set_long_name(struct dso *self, char *name);
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200147void dso__set_build_id(struct dso *self, void *build_id);
Arnaldo Carvalho de Melofd1d9082010-01-27 21:05:51 -0200148void dso__read_running_kernel_build_id(struct dso *self);
Arnaldo Carvalho de Meloea08d8c2009-12-11 18:56:39 -0200149struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200150struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
151 const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300152
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200153int filename__read_build_id(const char *filename, void *bf, size_t size);
Arnaldo Carvalho de Melof1617b42009-11-18 20:20:52 -0200154int sysfs__read_build_id(const char *filename, void *bf, size_t size);
Arnaldo Carvalho de Meloe30a3d12009-11-18 20:20:51 -0200155bool dsos__read_build_ids(void);
Arnaldo Carvalho de Meloef12a142010-01-20 15:28:45 -0200156int build_id__sprintf(const u8 *self, int len, char *bf);
Arnaldo Carvalho de Melo9e201442010-01-14 18:30:06 -0200157int kallsyms__parse(const char *filename, void *arg,
158 int (*process_symbol)(void *arg, const char *name,
159 char type, u64 start));
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200160
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200161int symbol__init(void);
Arnaldo Carvalho de Melo36a3e642010-01-04 16:19:27 -0200162bool symbol_type__is_a(char symbol_type, enum map_type map_type);
163
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +0200164extern struct dso *vdso;
John Kacur8b40f522009-09-24 18:02:18 +0200165#endif /* __PERF_SYMBOL */