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