478f5ab37787443824661a8486ccc96101af3f33
[linux-2.6.git] / tools / perf / util / symbol.h
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 <linux/list.h>
9 #include <linux/rbtree.h>
10 #include <stdio.h>
11
12 #define DEBUG_CACHE_DIR ".debug"
13
14 #ifdef HAVE_CPLUS_DEMANGLE
15 extern char *cplus_demangle(const char *, int);
16
17 static inline char *bfd_demangle(void __used *v, const char *c, int i)
18 {
19         return cplus_demangle(c, i);
20 }
21 #else
22 #ifdef NO_DEMANGLE
23 static inline char *bfd_demangle(void __used *v, const char __used *c,
24                                  int __used i)
25 {
26         return NULL;
27 }
28 #else
29 #include <bfd.h>
30 #endif
31 #endif
32
33 int hex2u64(const char *ptr, u64 *val);
34 char *strxfrchar(char *s, char from, char to);
35
36 /*
37  * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
38  * for newer versions we can use mmap to reduce memory usage:
39  */
40 #ifdef LIBELF_NO_MMAP
41 # define PERF_ELF_C_READ_MMAP ELF_C_READ
42 #else
43 # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
44 #endif
45
46 #ifndef DMGL_PARAMS
47 #define DMGL_PARAMS      (1 << 0)       /* Include function args */
48 #define DMGL_ANSI        (1 << 1)       /* Include const, volatile, etc */
49 #endif
50
51 #define BUILD_ID_SIZE 20
52
53 struct symbol {
54         struct rb_node  rb_node;
55         u64             start;
56         u64             end;
57         char            name[0];
58 };
59
60 void symbol__delete(struct symbol *self);
61
62 struct strlist;
63
64 struct symbol_conf {
65         unsigned short  priv_size;
66         bool            try_vmlinux_path,
67                         use_modules,
68                         sort_by_name,
69                         show_nr_samples,
70                         use_callchain,
71                         exclude_other,
72                         full_paths,
73                         show_cpu_utilization;
74         const char      *vmlinux_name,
75                         *field_sep;
76         const char      *default_guest_vmlinux_name,
77                         *default_guest_kallsyms,
78                         *default_guest_modules;
79         const char      *guestmount;
80         char            *dso_list_str,
81                         *comm_list_str,
82                         *sym_list_str,
83                         *col_width_list_str;
84        struct strlist   *dso_list,
85                         *comm_list,
86                         *sym_list;
87 };
88
89 extern struct symbol_conf symbol_conf;
90
91 static inline void *symbol__priv(struct symbol *self)
92 {
93         return ((void *)self) - symbol_conf.priv_size;
94 }
95
96 struct ref_reloc_sym {
97         const char      *name;
98         u64             addr;
99         u64             unrelocated_addr;
100 };
101
102 struct map_symbol {
103         struct map    *map;
104         struct symbol *sym;
105 };
106
107 struct addr_location {
108         struct thread *thread;
109         struct map    *map;
110         struct symbol *sym;
111         u64           addr;
112         char          level;
113         bool          filtered;
114         unsigned int  cpumode;
115 };
116
117 enum dso_kernel_type {
118         DSO_TYPE_USER = 0,
119         DSO_TYPE_KERNEL,
120         DSO_TYPE_GUEST_KERNEL
121 };
122
123 struct dso {
124         struct list_head node;
125         struct rb_root   symbols[MAP__NR_TYPES];
126         struct rb_root   symbol_names[MAP__NR_TYPES];
127         u8               adjust_symbols:1;
128         u8               slen_calculated:1;
129         u8               has_build_id:1;
130         enum dso_kernel_type    kernel;
131         u8               hit:1;
132         u8               annotate_warned:1;
133         unsigned char    origin;
134         u8               sorted_by_name;
135         u8               loaded;
136         u8               build_id[BUILD_ID_SIZE];
137         const char       *short_name;
138         char             *long_name;
139         u16              long_name_len;
140         u16              short_name_len;
141         char             name[0];
142 };
143
144 struct dso *dso__new(const char *name);
145 struct dso *dso__new_kernel(const char *name);
146 void dso__delete(struct dso *self);
147
148 bool dso__loaded(const struct dso *self, enum map_type type);
149 bool dso__sorted_by_name(const struct dso *self, enum map_type type);
150
151 static inline void dso__set_loaded(struct dso *self, enum map_type type)
152 {
153         self->loaded |= (1 << type);
154 }
155
156 void dso__sort_by_name(struct dso *self, enum map_type type);
157
158 struct dso *__dsos__findnew(struct list_head *head, const char *name);
159
160 int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
161 int dso__load_vmlinux_path(struct dso *self, struct map *map,
162                            symbol_filter_t filter);
163 int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
164                        symbol_filter_t filter);
165 void dsos__fprintf(struct rb_root *kerninfo_root, FILE *fp);
166 size_t dsos__fprintf_buildid(struct rb_root *kerninfo_root,
167                 FILE *fp, bool with_hits);
168
169 size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
170 size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
171
172 enum dso_origin {
173         DSO__ORIG_KERNEL = 0,
174         DSO__ORIG_GUEST_KERNEL,
175         DSO__ORIG_JAVA_JIT,
176         DSO__ORIG_BUILD_ID_CACHE,
177         DSO__ORIG_FEDORA,
178         DSO__ORIG_UBUNTU,
179         DSO__ORIG_BUILDID,
180         DSO__ORIG_DSO,
181         DSO__ORIG_GUEST_KMODULE,
182         DSO__ORIG_KMODULE,
183         DSO__ORIG_NOT_FOUND,
184 };
185
186 char dso__symtab_origin(const struct dso *self);
187 void dso__set_long_name(struct dso *self, char *name);
188 void dso__set_build_id(struct dso *self, void *build_id);
189 void dso__read_running_kernel_build_id(struct dso *self,
190                 struct kernel_info *kerninfo);
191 struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
192 struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
193                                         const char *name);
194
195 int filename__read_build_id(const char *filename, void *bf, size_t size);
196 int sysfs__read_build_id(const char *filename, void *bf, size_t size);
197 bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
198 int build_id__sprintf(const u8 *self, int len, char *bf);
199 int kallsyms__parse(const char *filename, void *arg,
200                     int (*process_symbol)(void *arg, const char *name,
201                                           char type, u64 start));
202
203 int __map_groups__create_kernel_maps(struct map_groups *self,
204                         struct map *vmlinux_maps[MAP__NR_TYPES],
205                         struct dso *kernel);
206 int map_groups__create_kernel_maps(struct rb_root *kerninfo_root, pid_t pid);
207 int map_groups__create_guest_kernel_maps(struct rb_root *kerninfo_root);
208
209 int symbol__init(void);
210 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
211
212 size_t vmlinux_path__fprintf(FILE *fp);
213
214 #endif /* __PERF_SYMBOL */