blob: 51c5a4a0813332326c11adbc6b1b052b1942641d [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 Melo00a192b2009-10-30 16:28:24 -020052extern unsigned int symbol__priv_size;
53
54static inline void *symbol__priv(struct symbol *self)
55{
56 return ((void *)self) - symbol__priv_size;
57}
58
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030059struct dso {
60 struct list_head node;
61 struct rb_root syms;
Paul Mackerras9cffa8d2009-06-19 22:21:42 +100062 struct symbol *(*find_symbol)(struct dso *, u64 ip);
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020063 u8 adjust_symbols:1;
64 u8 slen_calculated:1;
65 u8 loaded:1;
66 u8 has_build_id:1;
Arnaldo Carvalho de Melo94cb9e32009-08-06 14:43:17 -030067 unsigned char origin;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020068 u8 build_id[BUILD_ID_SIZE];
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -030069 const char *short_name;
70 char *long_name;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030071 char name[0];
72};
73
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020074struct dso *dso__new(const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030075void dso__delete(struct dso *self);
76
Paul Mackerras9cffa8d2009-06-19 22:21:42 +100077struct symbol *dso__find_symbol(struct dso *self, u64 ip);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030078
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020079int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter, int modules);
80struct dso *dsos__findnew(const char *name);
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -020081int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020082void dsos__fprintf(FILE *fp);
Arnaldo Carvalho de Melo9e03eb22009-11-16 16:32:44 -020083size_t dsos__fprintf_buildid(FILE *fp);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030084
Arnaldo Carvalho de Melo9e03eb22009-11-16 16:32:44 -020085size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030086size_t dso__fprintf(struct dso *self, FILE *fp);
Arnaldo Carvalho de Melo94cb9e32009-08-06 14:43:17 -030087char dso__symtab_origin(const struct dso *self);
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020088void dso__set_build_id(struct dso *self, void *build_id);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030089
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -020090int filename__read_build_id(const char *filename, void *bf, size_t size);
Frederic Weisbecker57f395a2009-11-11 04:51:04 +010091bool fetch_build_id_table(struct list_head *head);
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020092int build_id__sprintf(u8 *self, int len, char *bf);
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -020093
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020094int load_kernel(symbol_filter_t filter);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020095
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020096void symbol__init(unsigned int priv_size);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020097
98extern struct list_head dsos;
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -030099extern struct map *kernel_map;
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +0200100extern struct dso *vdso;
Ingo Molnar83a09442009-08-15 12:26:57 +0200101extern const char *vmlinux_name;
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +0200102extern int modules;
John Kacur8b40f522009-09-24 18:02:18 +0200103#endif /* __PERF_SYMBOL */