1#ifndef __PERF_SYMBOL
2#define __PERF_SYMBOL 1
3
4/* ANDROID_CHANGE_BEGIN */
5#ifndef __APPLE__
6/* Suppress kernel-name space pollution in <linux/types.h> below */
7#include <features.h>
8#include <linux/types.h>
9#endif
10/* ANDROID_CHANGE_END */
11#include <stdbool.h>
12#include <stdint.h>
13#include "map.h"
14/* ANDROID_CHANGE_BEGIN */
15#if 0
16#include <linux/list.h>
17#include <linux/rbtree.h>
18#else
19#include "include/linux/list.h"
20#include "include/linux/rbtree.h"
21#endif
22/* ANDROID_CHANGE_END */
23#include <stdio.h>
24
25#ifdef HAVE_CPLUS_DEMANGLE
26extern char *cplus_demangle(const char *, int);
27
28static inline char *bfd_demangle(void __used *v, const char *c, int i)
29{
30	return cplus_demangle(c, i);
31}
32#else
33#ifdef NO_DEMANGLE
34static inline char *bfd_demangle(void __used *v, const char __used *c,
35				 int __used i)
36{
37	return NULL;
38}
39#else
40#include <bfd.h>
41#endif
42#endif
43
44int hex2u64(const char *ptr, u64 *val);
45char *strxfrchar(char *s, char from, char to);
46
47/*
48 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
49 * for newer versions we can use mmap to reduce memory usage:
50 */
51#ifdef LIBELF_NO_MMAP
52# define PERF_ELF_C_READ_MMAP ELF_C_READ
53#else
54# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
55#endif
56
57#ifndef DMGL_PARAMS
58#define DMGL_PARAMS      (1 << 0)       /* Include function args */
59#define DMGL_ANSI        (1 << 1)       /* Include const, volatile, etc */
60#endif
61
62#define BUILD_ID_SIZE 20
63
64/** struct symbol - symtab entry
65 *
66 * @ignore - resolvable but tools ignore it (e.g. idle routines)
67 */
68struct symbol {
69	struct rb_node	rb_node;
70	u64		start;
71	u64		end;
72	u16		namelen;
73	u8		binding;
74	bool		ignore;
75	char		name[0];
76};
77
78void symbol__delete(struct symbol *sym);
79
80struct strlist;
81
82struct symbol_conf {
83	unsigned short	priv_size;
84	bool		try_vmlinux_path,
85			use_modules,
86			sort_by_name,
87			show_nr_samples,
88			use_callchain,
89			exclude_other,
90			show_cpu_utilization,
91			initialized,
92			kptr_restrict;
93	const char	*vmlinux_name,
94			*kallsyms_name,
95			*source_prefix,
96			*field_sep;
97	const char	*default_guest_vmlinux_name,
98			*default_guest_kallsyms,
99			*default_guest_modules;
100	const char	*guestmount;
101	const char	*dso_list_str,
102			*comm_list_str,
103			*sym_list_str,
104			*col_width_list_str;
105       struct strlist	*dso_list,
106			*comm_list,
107			*sym_list;
108	const char	*symfs;
109};
110
111extern struct symbol_conf symbol_conf;
112
113static inline void *symbol__priv(struct symbol *sym)
114{
115	return ((void *)sym) - symbol_conf.priv_size;
116}
117
118struct ref_reloc_sym {
119	const char	*name;
120	u64		addr;
121	u64		unrelocated_addr;
122};
123
124struct map_symbol {
125	struct map    *map;
126	struct symbol *sym;
127	bool	      unfolded;
128	bool	      has_children;
129};
130
131struct addr_location {
132	struct thread *thread;
133	struct map    *map;
134	struct symbol *sym;
135	u64	      addr;
136	char	      level;
137	bool	      filtered;
138	u8	      cpumode;
139	s32	      cpu;
140};
141
142enum dso_kernel_type {
143	DSO_TYPE_USER = 0,
144	DSO_TYPE_KERNEL,
145	DSO_TYPE_GUEST_KERNEL
146};
147
148struct dso {
149	struct list_head node;
150	struct rb_root	 symbols[MAP__NR_TYPES];
151	struct rb_root	 symbol_names[MAP__NR_TYPES];
152	enum dso_kernel_type	kernel;
153	u8		 adjust_symbols:1;
154	u8		 has_build_id:1;
155	u8		 hit:1;
156	u8		 annotate_warned:1;
157	u8		 sname_alloc:1;
158	u8		 lname_alloc:1;
159	unsigned char	 symtab_type;
160	u8		 sorted_by_name;
161	u8		 loaded;
162	u8		 build_id[BUILD_ID_SIZE];
163	const char	 *short_name;
164	char	 	 *long_name;
165	u16		 long_name_len;
166	u16		 short_name_len;
167	char		 name[0];
168};
169
170struct dso *dso__new(const char *name);
171struct dso *dso__new_kernel(const char *name);
172void dso__delete(struct dso *dso);
173
174int dso__name_len(const struct dso *dso);
175
176bool dso__loaded(const struct dso *dso, enum map_type type);
177bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
178
179static inline void dso__set_loaded(struct dso *dso, enum map_type type)
180{
181	dso->loaded |= (1 << type);
182}
183
184void dso__sort_by_name(struct dso *dso, enum map_type type);
185
186struct dso *__dsos__findnew(struct list_head *head, const char *name);
187
188int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
189int dso__load_vmlinux(struct dso *dso, struct map *map,
190		      const char *vmlinux, symbol_filter_t filter);
191int dso__load_vmlinux_path(struct dso *dso, struct map *map,
192			   symbol_filter_t filter);
193int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
194		       symbol_filter_t filter);
195int machine__load_kallsyms(struct machine *machine, const char *filename,
196			   enum map_type type, symbol_filter_t filter);
197int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
198			       symbol_filter_t filter);
199
200size_t __dsos__fprintf(struct list_head *head, FILE *fp);
201
202size_t machine__fprintf_dsos_buildid(struct machine *machine,
203				     FILE *fp, bool with_hits);
204size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
205size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
206				      FILE *fp, bool with_hits);
207size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
208size_t dso__fprintf_symbols_by_name(struct dso *dso,
209				    enum map_type type, FILE *fp);
210size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
211
212enum symtab_type {
213	SYMTAB__KALLSYMS = 0,
214	SYMTAB__GUEST_KALLSYMS,
215	SYMTAB__JAVA_JIT,
216	SYMTAB__BUILD_ID_CACHE,
217	SYMTAB__FEDORA_DEBUGINFO,
218	SYMTAB__UBUNTU_DEBUGINFO,
219	SYMTAB__BUILDID_DEBUGINFO,
220	SYMTAB__SYSTEM_PATH_DSO,
221	SYMTAB__GUEST_KMODULE,
222	SYMTAB__SYSTEM_PATH_KMODULE,
223	SYMTAB__NOT_FOUND,
224};
225
226char dso__symtab_origin(const struct dso *dso);
227void dso__set_long_name(struct dso *dso, char *name);
228void dso__set_build_id(struct dso *dso, void *build_id);
229void dso__read_running_kernel_build_id(struct dso *dso,
230				       struct machine *machine);
231struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
232				u64 addr);
233struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
234					const char *name);
235
236int filename__read_build_id(const char *filename, void *bf, size_t size);
237int sysfs__read_build_id(const char *filename, void *bf, size_t size);
238bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
239int build_id__sprintf(const u8 *build_id, int len, char *bf);
240int kallsyms__parse(const char *filename, void *arg,
241		    int (*process_symbol)(void *arg, const char *name,
242					  char type, u64 start, u64 end));
243
244void machine__destroy_kernel_maps(struct machine *machine);
245int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
246int machine__create_kernel_maps(struct machine *machine);
247
248int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
249int machines__create_guest_kernel_maps(struct rb_root *machines);
250void machines__destroy_guest_kernel_maps(struct rb_root *machines);
251
252int symbol__init(void);
253void symbol__exit(void);
254bool symbol_type__is_a(char symbol_type, enum map_type map_type);
255
256size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
257
258#endif /* __PERF_SYMBOL */
259