blob: 8aded2356f7961458b8a3d18635a0ca4c66d2ae2 [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 Melo247648e2009-08-11 16:22:11 -030011#ifdef HAVE_CPLUS_DEMANGLE
12extern char *cplus_demangle(const char *, int);
13
14static inline char *bfd_demangle(void __used *v, const char *c, int i)
15{
16 return cplus_demangle(c, i);
17}
18#else
19#ifdef NO_DEMANGLE
20static inline char *bfd_demangle(void __used *v, const char __used *c,
21 int __used i)
22{
23 return NULL;
24}
25#else
26#include <bfd.h>
27#endif
28#endif
29
Marti Raudsepp84087122009-10-24 19:10:36 +030030/*
31 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
32 * for newer versions we can use mmap to reduce memory usage:
33 */
34#ifdef LIBELF_NO_MMAP
35# define PERF_ELF_C_READ_MMAP ELF_C_READ
36#else
37# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
38#endif
39
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030040#ifndef DMGL_PARAMS
41#define DMGL_PARAMS (1 << 0) /* Include function args */
42#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
43#endif
44
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030045struct symbol {
46 struct rb_node rb_node;
Paul Mackerras9cffa8d2009-06-19 22:21:42 +100047 u64 start;
48 u64 end;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030049 char name[0];
50};
51
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020052struct strlist;
53
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020054struct symbol_conf {
55 unsigned short priv_size;
56 bool try_vmlinux_path,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -020057 use_modules,
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -020058 sort_by_name,
59 show_nr_samples,
60 use_callchain,
61 exclude_other;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020062 const char *vmlinux_name,
63 *field_sep;
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020064 char *dso_list_str,
65 *comm_list_str,
66 *sym_list_str,
67 *col_width_list_str;
68 struct strlist *dso_list,
69 *comm_list,
70 *sym_list;
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020071};
72
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -020073extern struct symbol_conf symbol_conf;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020074
75static inline void *symbol__priv(struct symbol *self)
76{
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -020077 return ((void *)self) - symbol_conf.priv_size;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020078}
79
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020080struct addr_location {
81 struct thread *thread;
82 struct map *map;
83 struct symbol *sym;
84 u64 addr;
85 char level;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020086 bool filtered;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020087};
88
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030089struct dso {
90 struct list_head node;
Arnaldo Carvalho de Melo6a4694a2009-11-27 16:29:17 -020091 struct rb_root symbols[MAP__NR_TYPES];
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -020092 struct rb_root symbol_names[MAP__NR_TYPES];
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020093 u8 adjust_symbols:1;
94 u8 slen_calculated:1;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020095 u8 has_build_id:1;
Arnaldo Carvalho de Meloc338aee2009-11-20 20:51:27 -020096 u8 kernel:1;
Arnaldo Carvalho de Melo94cb9e32009-08-06 14:43:17 -030097 unsigned char origin;
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -020098 u8 sorted_by_name;
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -020099 u8 loaded;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200100 u8 build_id[BUILD_ID_SIZE];
Arnaldo Carvalho de Melocfc10d32009-11-17 15:40:53 -0200101 u16 long_name_len;
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -0300102 const char *short_name;
103 char *long_name;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300104 char name[0];
105};
106
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200107struct dso *dso__new(const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300108void dso__delete(struct dso *self);
109
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200110bool dso__loaded(const struct dso *self, enum map_type type);
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200111bool dso__sorted_by_name(const struct dso *self, enum map_type type);
112
113void dso__sort_by_name(struct dso *self, enum map_type type);
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200114
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -0200115struct perf_session;
116
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200117struct dso *dsos__findnew(const char *name);
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -0200118int dso__load(struct dso *self, struct map *map, struct perf_session *session,
119 symbol_filter_t filter);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +0200120void dsos__fprintf(FILE *fp);
Arnaldo Carvalho de Melo9e03eb22009-11-16 16:32:44 -0200121size_t dsos__fprintf_buildid(FILE *fp);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300122
Arnaldo Carvalho de Melo9e03eb22009-11-16 16:32:44 -0200123size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
Arnaldo Carvalho de Melo95011c62009-11-27 16:29:20 -0200124size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
Arnaldo Carvalho de Melo94cb9e32009-08-06 14:43:17 -0300125char dso__symtab_origin(const struct dso *self);
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200126void dso__set_build_id(struct dso *self, void *build_id);
Arnaldo Carvalho de Meloea08d8c2009-12-11 18:56:39 -0200127struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200128struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
129 const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300130
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200131int filename__read_build_id(const char *filename, void *bf, size_t size);
Arnaldo Carvalho de Melof1617b42009-11-18 20:20:52 -0200132int sysfs__read_build_id(const char *filename, void *bf, size_t size);
Arnaldo Carvalho de Meloe30a3d12009-11-18 20:20:51 -0200133bool dsos__read_build_ids(void);
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200134int build_id__sprintf(u8 *self, int len, char *bf);
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200135
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200136int symbol__init(void);
137int perf_session__create_kernel_maps(struct perf_session *self);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +0200138
Arnaldo Carvalho de Melob0da9542009-11-27 16:29:14 -0200139extern struct list_head dsos__user, dsos__kernel;
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +0200140extern struct dso *vdso;
John Kacur8b40f522009-09-24 18:02:18 +0200141#endif /* __PERF_SYMBOL */