Commit | Line | Data |
---|---|---|
cdd059d7 JO |
1 | #ifndef __PERF_DSO |
2 | #define __PERF_DSO | |
3 | ||
4 | #include <linux/types.h> | |
5 | #include <linux/rbtree.h> | |
39b12f78 | 6 | #include <stdbool.h> |
d944c4ee | 7 | #include <linux/types.h> |
cdd059d7 | 8 | #include "map.h" |
86c98cab | 9 | #include "build-id.h" |
cdd059d7 JO |
10 | |
11 | enum dso_binary_type { | |
12 | DSO_BINARY_TYPE__KALLSYMS = 0, | |
13 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | |
14 | DSO_BINARY_TYPE__VMLINUX, | |
15 | DSO_BINARY_TYPE__GUEST_VMLINUX, | |
16 | DSO_BINARY_TYPE__JAVA_JIT, | |
17 | DSO_BINARY_TYPE__DEBUGLINK, | |
18 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | |
19 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | |
20 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | |
21 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | |
22 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | |
23 | DSO_BINARY_TYPE__GUEST_KMODULE, | |
24 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | |
8e0cf965 AH |
25 | DSO_BINARY_TYPE__KCORE, |
26 | DSO_BINARY_TYPE__GUEST_KCORE, | |
9cd00941 | 27 | DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO, |
cdd059d7 JO |
28 | DSO_BINARY_TYPE__NOT_FOUND, |
29 | }; | |
30 | ||
31 | enum dso_kernel_type { | |
32 | DSO_TYPE_USER = 0, | |
33 | DSO_TYPE_KERNEL, | |
34 | DSO_TYPE_GUEST_KERNEL | |
35 | }; | |
36 | ||
37 | enum dso_swap_type { | |
38 | DSO_SWAP__UNSET, | |
39 | DSO_SWAP__NO, | |
40 | DSO_SWAP__YES, | |
41 | }; | |
42 | ||
c27697d6 AH |
43 | enum dso_data_status { |
44 | DSO_DATA_STATUS_ERROR = -1, | |
45 | DSO_DATA_STATUS_UNKNOWN = 0, | |
46 | DSO_DATA_STATUS_OK = 1, | |
47 | }; | |
48 | ||
cdd059d7 JO |
49 | #define DSO__SWAP(dso, type, val) \ |
50 | ({ \ | |
51 | type ____r = val; \ | |
52 | BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \ | |
53 | if (dso->needs_swap == DSO_SWAP__YES) { \ | |
54 | switch (sizeof(____r)) { \ | |
55 | case 2: \ | |
56 | ____r = bswap_16(val); \ | |
57 | break; \ | |
58 | case 4: \ | |
59 | ____r = bswap_32(val); \ | |
60 | break; \ | |
61 | case 8: \ | |
62 | ____r = bswap_64(val); \ | |
63 | break; \ | |
64 | default: \ | |
65 | BUG_ON(1); \ | |
66 | } \ | |
67 | } \ | |
68 | ____r; \ | |
69 | }) | |
70 | ||
71 | #define DSO__DATA_CACHE_SIZE 4096 | |
72 | #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) | |
73 | ||
74 | struct dso_cache { | |
75 | struct rb_node rb_node; | |
76 | u64 offset; | |
77 | u64 size; | |
78 | char data[0]; | |
79 | }; | |
80 | ||
81 | struct dso { | |
82 | struct list_head node; | |
83 | struct rb_root symbols[MAP__NR_TYPES]; | |
84 | struct rb_root symbol_names[MAP__NR_TYPES]; | |
454ff00f | 85 | void *a2l; |
0058aef6 | 86 | char *symsrc_filename; |
906049c8 | 87 | unsigned int a2l_fails; |
cdd059d7 JO |
88 | enum dso_kernel_type kernel; |
89 | enum dso_swap_type needs_swap; | |
90 | enum dso_binary_type symtab_type; | |
5f70619d | 91 | enum dso_binary_type binary_type; |
cdd059d7 JO |
92 | u8 adjust_symbols:1; |
93 | u8 has_build_id:1; | |
2cc9d0ef | 94 | u8 has_srcline:1; |
cdd059d7 JO |
95 | u8 hit:1; |
96 | u8 annotate_warned:1; | |
c7282f2e ACM |
97 | u8 short_name_allocated:1; |
98 | u8 long_name_allocated:1; | |
c6d8f2a4 | 99 | u8 is_64_bit:1; |
cdd059d7 JO |
100 | u8 sorted_by_name; |
101 | u8 loaded; | |
0131c4ec | 102 | u8 rel; |
cdd059d7 JO |
103 | u8 build_id[BUILD_ID_SIZE]; |
104 | const char *short_name; | |
bf4414ae | 105 | const char *long_name; |
cdd059d7 JO |
106 | u16 long_name_len; |
107 | u16 short_name_len; | |
ca40e2af JO |
108 | |
109 | /* dso data file */ | |
110 | struct { | |
111 | struct rb_root cache; | |
53fa8eaa | 112 | int fd; |
c27697d6 | 113 | int status; |
c3fbd2a6 | 114 | size_t file_size; |
eba5102d | 115 | struct list_head open_entry; |
ca40e2af JO |
116 | } data; |
117 | ||
cdd059d7 JO |
118 | char name[0]; |
119 | }; | |
120 | ||
eb948e50 MH |
121 | /* dso__for_each_symbol - iterate over the symbols of given type |
122 | * | |
123 | * @dso: the 'struct dso *' in which symbols itereated | |
124 | * @pos: the 'struct symbol *' to use as a loop cursor | |
125 | * @n: the 'struct rb_node *' to use as a temporary storage | |
126 | * @type: the 'enum map_type' type of symbols | |
127 | */ | |
128 | #define dso__for_each_symbol(dso, pos, n, type) \ | |
129 | symbols__for_each_entry(&(dso)->symbols[(type)], pos, n) | |
130 | ||
cdd059d7 JO |
131 | static inline void dso__set_loaded(struct dso *dso, enum map_type type) |
132 | { | |
133 | dso->loaded |= (1 << type); | |
134 | } | |
135 | ||
136 | struct dso *dso__new(const char *name); | |
137 | void dso__delete(struct dso *dso); | |
138 | ||
58a98c9c | 139 | void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated); |
bf4414ae | 140 | void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated); |
cdd059d7 JO |
141 | |
142 | int dso__name_len(const struct dso *dso); | |
143 | ||
144 | bool dso__loaded(const struct dso *dso, enum map_type type); | |
145 | ||
146 | bool dso__sorted_by_name(const struct dso *dso, enum map_type type); | |
147 | void dso__set_sorted_by_name(struct dso *dso, enum map_type type); | |
148 | void dso__sort_by_name(struct dso *dso, enum map_type type); | |
149 | ||
150 | void dso__set_build_id(struct dso *dso, void *build_id); | |
151 | bool dso__build_id_equal(const struct dso *dso, u8 *build_id); | |
152 | void dso__read_running_kernel_build_id(struct dso *dso, | |
153 | struct machine *machine); | |
154 | int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir); | |
155 | ||
156 | char dso__symtab_origin(const struct dso *dso); | |
ee4e9625 ACM |
157 | int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type, |
158 | char *root_dir, char *filename, size_t size); | |
cdd059d7 | 159 | |
c1f9aa0a JO |
160 | /* |
161 | * The dso__data_* external interface provides following functions: | |
162 | * dso__data_fd | |
163 | * dso__data_close | |
164 | * dso__data_read_offset | |
165 | * dso__data_read_addr | |
166 | * | |
167 | * Please refer to the dso.c object code for each function and | |
168 | * arguments documentation. Following text tries to explain the | |
169 | * dso file descriptor caching. | |
170 | * | |
171 | * The dso__data* interface allows caching of opened file descriptors | |
172 | * to speed up the dso data accesses. The idea is to leave the file | |
173 | * descriptor opened ideally for the whole life of the dso object. | |
174 | * | |
175 | * The current usage of the dso__data_* interface is as follows: | |
176 | * | |
177 | * Get DSO's fd: | |
178 | * int fd = dso__data_fd(dso, machine); | |
179 | * USE 'fd' SOMEHOW | |
180 | * | |
181 | * Read DSO's data: | |
182 | * n = dso__data_read_offset(dso_0, &machine, 0, buf, BUFSIZE); | |
183 | * n = dso__data_read_addr(dso_0, &machine, 0, buf, BUFSIZE); | |
184 | * | |
185 | * Eventually close DSO's fd: | |
186 | * dso__data_close(dso); | |
187 | * | |
188 | * It is not necessary to close the DSO object data file. Each time new | |
189 | * DSO data file is opened, the limit (RLIMIT_NOFILE/2) is checked. Once | |
190 | * it is crossed, the oldest opened DSO object is closed. | |
191 | * | |
192 | * The dso__delete function calls close_dso function to ensure the | |
193 | * data file descriptor gets closed/unmapped before the dso object | |
194 | * is freed. | |
195 | * | |
196 | * TODO | |
197 | */ | |
cdd059d7 | 198 | int dso__data_fd(struct dso *dso, struct machine *machine); |
53fa8eaa JO |
199 | void dso__data_close(struct dso *dso); |
200 | ||
cdd059d7 JO |
201 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, |
202 | u64 offset, u8 *data, ssize_t size); | |
203 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | |
204 | struct machine *machine, u64 addr, | |
205 | u8 *data, ssize_t size); | |
206 | ||
207 | struct map *dso__new_map(const char *name); | |
208 | struct dso *dso__kernel_findnew(struct machine *machine, const char *name, | |
209 | const char *short_name, int dso_type); | |
210 | ||
211 | void dsos__add(struct list_head *head, struct dso *dso); | |
3344996e | 212 | struct dso *dsos__find(const struct list_head *head, const char *name, |
f9ceffb6 | 213 | bool cmp_short); |
cdd059d7 JO |
214 | struct dso *__dsos__findnew(struct list_head *head, const char *name); |
215 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); | |
216 | ||
217 | size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | |
417c2ff6 | 218 | bool (skip)(struct dso *dso, int parm), int parm); |
cdd059d7 JO |
219 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); |
220 | ||
221 | size_t dso__fprintf_buildid(struct dso *dso, FILE *fp); | |
222 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | |
223 | enum map_type type, FILE *fp); | |
224 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); | |
39b12f78 AH |
225 | |
226 | static inline bool dso__is_vmlinux(struct dso *dso) | |
227 | { | |
5f70619d ACM |
228 | return dso->binary_type == DSO_BINARY_TYPE__VMLINUX || |
229 | dso->binary_type == DSO_BINARY_TYPE__GUEST_VMLINUX; | |
39b12f78 AH |
230 | } |
231 | ||
8e0cf965 AH |
232 | static inline bool dso__is_kcore(struct dso *dso) |
233 | { | |
5f70619d ACM |
234 | return dso->binary_type == DSO_BINARY_TYPE__KCORE || |
235 | dso->binary_type == DSO_BINARY_TYPE__GUEST_KCORE; | |
8e0cf965 AH |
236 | } |
237 | ||
454ff00f AH |
238 | void dso__free_a2l(struct dso *dso); |
239 | ||
cdd059d7 | 240 | #endif /* __PERF_DSO */ |