diff options
author | Ingo Molnar <mingo@kernel.org> | 2012-10-30 03:35:33 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-10-30 03:35:33 -0400 |
commit | 8748dd9b998f06f7cf3a7ffdca27f05bc4835075 (patch) | |
tree | d480571278f5952b3f22e43ebb6c75cd0416db5a /tools/perf/util | |
parent | 9db55064940db1447976945d07402a923e818962 (diff) | |
parent | 0da2e9c24804d787cbc919b3e0d28ee7c00240ff (diff) |
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements, fixes and code move from Arnaldo Carvalho de Melo:
* Initialize 'page_size' variable in the python binding, this was sent
for perf/urgent by mistake, then when merging Ingo removed it, fixing
the problem for perf/urgent, but when perf/urgent was merged with
perf/core, where that initialization is needed, made the python
binding mmap call to fail, fix it by initializing page_size again.
* Add a browser for 'perf script' and make it available from the report
and annotate browsers. It does filtering to find the scripts that
handle events found in the perf.data file used. From Feng Tang
* Move some functions from symbol.c to more appropriate files, creating
dso.[ch] in the process, no code changes. From Jiri Olsa
* Fix mmap error output message for when perf_mmap fails and returns
!-EPERM, where the default for mmap_pages, INT_MAX, was causing a
!power of 2 error message, fix from Jiri Olsa.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/annotate.c | 1 | ||||
-rw-r--r-- | tools/perf/util/build-id.c | 15 | ||||
-rw-r--r-- | tools/perf/util/build-id.h | 7 | ||||
-rw-r--r-- | tools/perf/util/dso.c | 594 | ||||
-rw-r--r-- | tools/perf/util/dso.h | 148 | ||||
-rw-r--r-- | tools/perf/util/event.h | 3 | ||||
-rw-r--r-- | tools/perf/util/header.c | 11 | ||||
-rw-r--r-- | tools/perf/util/header.h | 1 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 7 | ||||
-rw-r--r-- | tools/perf/util/map.c | 1 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 10 | ||||
-rw-r--r-- | tools/perf/util/python.c | 2 | ||||
-rw-r--r-- | tools/perf/util/string.c | 18 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 657 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 141 | ||||
-rw-r--r-- | tools/perf/util/util.c | 33 | ||||
-rw-r--r-- | tools/perf/util/util.h | 2 |
17 files changed, 855 insertions, 796 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index f0a910371377..7a34dd18b74c 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include "debug.h" | 15 | #include "debug.h" |
16 | #include "annotate.h" | 16 | #include "annotate.h" |
17 | #include <pthread.h> | 17 | #include <pthread.h> |
18 | #include <linux/bitops.h> | ||
18 | 19 | ||
19 | const char *disassembler_style; | 20 | const char *disassembler_style; |
20 | const char *objdump_path; | 21 | const char *objdump_path; |
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 94ca117b8d6e..5295625c0c00 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
@@ -70,6 +70,21 @@ struct perf_tool build_id__mark_dso_hit_ops = { | |||
70 | .build_id = perf_event__process_build_id, | 70 | .build_id = perf_event__process_build_id, |
71 | }; | 71 | }; |
72 | 72 | ||
73 | int build_id__sprintf(const u8 *build_id, int len, char *bf) | ||
74 | { | ||
75 | char *bid = bf; | ||
76 | const u8 *raw = build_id; | ||
77 | int i; | ||
78 | |||
79 | for (i = 0; i < len; ++i) { | ||
80 | sprintf(bid, "%02x", *raw); | ||
81 | ++raw; | ||
82 | bid += 2; | ||
83 | } | ||
84 | |||
85 | return raw - build_id; | ||
86 | } | ||
87 | |||
73 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size) | 88 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size) |
74 | { | 89 | { |
75 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | 90 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; |
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 45c500bd5b9f..a811f5c62e18 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h | |||
@@ -1,10 +1,15 @@ | |||
1 | #ifndef PERF_BUILD_ID_H_ | 1 | #ifndef PERF_BUILD_ID_H_ |
2 | #define PERF_BUILD_ID_H_ 1 | 2 | #define PERF_BUILD_ID_H_ 1 |
3 | 3 | ||
4 | #include "session.h" | 4 | #define BUILD_ID_SIZE 20 |
5 | |||
6 | #include "tool.h" | ||
7 | #include "types.h" | ||
5 | 8 | ||
6 | extern struct perf_tool build_id__mark_dso_hit_ops; | 9 | extern struct perf_tool build_id__mark_dso_hit_ops; |
10 | struct dso; | ||
7 | 11 | ||
12 | int build_id__sprintf(const u8 *build_id, int len, char *bf); | ||
8 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size); | 13 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size); |
9 | 14 | ||
10 | int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event, | 15 | int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event, |
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c new file mode 100644 index 000000000000..db24a3f0c820 --- /dev/null +++ b/tools/perf/util/dso.c | |||
@@ -0,0 +1,594 @@ | |||
1 | #include "symbol.h" | ||
2 | #include "dso.h" | ||
3 | #include "util.h" | ||
4 | #include "debug.h" | ||
5 | |||
6 | char dso__symtab_origin(const struct dso *dso) | ||
7 | { | ||
8 | static const char origin[] = { | ||
9 | [DSO_BINARY_TYPE__KALLSYMS] = 'k', | ||
10 | [DSO_BINARY_TYPE__VMLINUX] = 'v', | ||
11 | [DSO_BINARY_TYPE__JAVA_JIT] = 'j', | ||
12 | [DSO_BINARY_TYPE__DEBUGLINK] = 'l', | ||
13 | [DSO_BINARY_TYPE__BUILD_ID_CACHE] = 'B', | ||
14 | [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f', | ||
15 | [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u', | ||
16 | [DSO_BINARY_TYPE__BUILDID_DEBUGINFO] = 'b', | ||
17 | [DSO_BINARY_TYPE__SYSTEM_PATH_DSO] = 'd', | ||
18 | [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE] = 'K', | ||
19 | [DSO_BINARY_TYPE__GUEST_KALLSYMS] = 'g', | ||
20 | [DSO_BINARY_TYPE__GUEST_KMODULE] = 'G', | ||
21 | [DSO_BINARY_TYPE__GUEST_VMLINUX] = 'V', | ||
22 | }; | ||
23 | |||
24 | if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND) | ||
25 | return '!'; | ||
26 | return origin[dso->symtab_type]; | ||
27 | } | ||
28 | |||
29 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
30 | char *root_dir, char *file, size_t size) | ||
31 | { | ||
32 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
33 | int ret = 0; | ||
34 | |||
35 | switch (type) { | ||
36 | case DSO_BINARY_TYPE__DEBUGLINK: { | ||
37 | char *debuglink; | ||
38 | |||
39 | strncpy(file, dso->long_name, size); | ||
40 | debuglink = file + dso->long_name_len; | ||
41 | while (debuglink != file && *debuglink != '/') | ||
42 | debuglink--; | ||
43 | if (*debuglink == '/') | ||
44 | debuglink++; | ||
45 | filename__read_debuglink(dso->long_name, debuglink, | ||
46 | size - (debuglink - file)); | ||
47 | } | ||
48 | break; | ||
49 | case DSO_BINARY_TYPE__BUILD_ID_CACHE: | ||
50 | /* skip the locally configured cache if a symfs is given */ | ||
51 | if (symbol_conf.symfs[0] || | ||
52 | (dso__build_id_filename(dso, file, size) == NULL)) | ||
53 | ret = -1; | ||
54 | break; | ||
55 | |||
56 | case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: | ||
57 | snprintf(file, size, "%s/usr/lib/debug%s.debug", | ||
58 | symbol_conf.symfs, dso->long_name); | ||
59 | break; | ||
60 | |||
61 | case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: | ||
62 | snprintf(file, size, "%s/usr/lib/debug%s", | ||
63 | symbol_conf.symfs, dso->long_name); | ||
64 | break; | ||
65 | |||
66 | case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: | ||
67 | if (!dso->has_build_id) { | ||
68 | ret = -1; | ||
69 | break; | ||
70 | } | ||
71 | |||
72 | build_id__sprintf(dso->build_id, | ||
73 | sizeof(dso->build_id), | ||
74 | build_id_hex); | ||
75 | snprintf(file, size, | ||
76 | "%s/usr/lib/debug/.build-id/%.2s/%s.debug", | ||
77 | symbol_conf.symfs, build_id_hex, build_id_hex + 2); | ||
78 | break; | ||
79 | |||
80 | case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: | ||
81 | snprintf(file, size, "%s%s", | ||
82 | symbol_conf.symfs, dso->long_name); | ||
83 | break; | ||
84 | |||
85 | case DSO_BINARY_TYPE__GUEST_KMODULE: | ||
86 | snprintf(file, size, "%s%s%s", symbol_conf.symfs, | ||
87 | root_dir, dso->long_name); | ||
88 | break; | ||
89 | |||
90 | case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: | ||
91 | snprintf(file, size, "%s%s", symbol_conf.symfs, | ||
92 | dso->long_name); | ||
93 | break; | ||
94 | |||
95 | default: | ||
96 | case DSO_BINARY_TYPE__KALLSYMS: | ||
97 | case DSO_BINARY_TYPE__VMLINUX: | ||
98 | case DSO_BINARY_TYPE__GUEST_KALLSYMS: | ||
99 | case DSO_BINARY_TYPE__GUEST_VMLINUX: | ||
100 | case DSO_BINARY_TYPE__JAVA_JIT: | ||
101 | case DSO_BINARY_TYPE__NOT_FOUND: | ||
102 | ret = -1; | ||
103 | break; | ||
104 | } | ||
105 | |||
106 | return ret; | ||
107 | } | ||
108 | |||
109 | static int open_dso(struct dso *dso, struct machine *machine) | ||
110 | { | ||
111 | char *root_dir = (char *) ""; | ||
112 | char *name; | ||
113 | int fd; | ||
114 | |||
115 | name = malloc(PATH_MAX); | ||
116 | if (!name) | ||
117 | return -ENOMEM; | ||
118 | |||
119 | if (machine) | ||
120 | root_dir = machine->root_dir; | ||
121 | |||
122 | if (dso__binary_type_file(dso, dso->data_type, | ||
123 | root_dir, name, PATH_MAX)) { | ||
124 | free(name); | ||
125 | return -EINVAL; | ||
126 | } | ||
127 | |||
128 | fd = open(name, O_RDONLY); | ||
129 | free(name); | ||
130 | return fd; | ||
131 | } | ||
132 | |||
133 | int dso__data_fd(struct dso *dso, struct machine *machine) | ||
134 | { | ||
135 | static enum dso_binary_type binary_type_data[] = { | ||
136 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
137 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
138 | DSO_BINARY_TYPE__NOT_FOUND, | ||
139 | }; | ||
140 | int i = 0; | ||
141 | |||
142 | if (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND) | ||
143 | return open_dso(dso, machine); | ||
144 | |||
145 | do { | ||
146 | int fd; | ||
147 | |||
148 | dso->data_type = binary_type_data[i++]; | ||
149 | |||
150 | fd = open_dso(dso, machine); | ||
151 | if (fd >= 0) | ||
152 | return fd; | ||
153 | |||
154 | } while (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND); | ||
155 | |||
156 | return -EINVAL; | ||
157 | } | ||
158 | |||
159 | static void | ||
160 | dso_cache__free(struct rb_root *root) | ||
161 | { | ||
162 | struct rb_node *next = rb_first(root); | ||
163 | |||
164 | while (next) { | ||
165 | struct dso_cache *cache; | ||
166 | |||
167 | cache = rb_entry(next, struct dso_cache, rb_node); | ||
168 | next = rb_next(&cache->rb_node); | ||
169 | rb_erase(&cache->rb_node, root); | ||
170 | free(cache); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | static struct dso_cache* | ||
175 | dso_cache__find(struct rb_root *root, u64 offset) | ||
176 | { | ||
177 | struct rb_node **p = &root->rb_node; | ||
178 | struct rb_node *parent = NULL; | ||
179 | struct dso_cache *cache; | ||
180 | |||
181 | while (*p != NULL) { | ||
182 | u64 end; | ||
183 | |||
184 | parent = *p; | ||
185 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
186 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
187 | |||
188 | if (offset < cache->offset) | ||
189 | p = &(*p)->rb_left; | ||
190 | else if (offset >= end) | ||
191 | p = &(*p)->rb_right; | ||
192 | else | ||
193 | return cache; | ||
194 | } | ||
195 | return NULL; | ||
196 | } | ||
197 | |||
198 | static void | ||
199 | dso_cache__insert(struct rb_root *root, struct dso_cache *new) | ||
200 | { | ||
201 | struct rb_node **p = &root->rb_node; | ||
202 | struct rb_node *parent = NULL; | ||
203 | struct dso_cache *cache; | ||
204 | u64 offset = new->offset; | ||
205 | |||
206 | while (*p != NULL) { | ||
207 | u64 end; | ||
208 | |||
209 | parent = *p; | ||
210 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
211 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
212 | |||
213 | if (offset < cache->offset) | ||
214 | p = &(*p)->rb_left; | ||
215 | else if (offset >= end) | ||
216 | p = &(*p)->rb_right; | ||
217 | } | ||
218 | |||
219 | rb_link_node(&new->rb_node, parent, p); | ||
220 | rb_insert_color(&new->rb_node, root); | ||
221 | } | ||
222 | |||
223 | static ssize_t | ||
224 | dso_cache__memcpy(struct dso_cache *cache, u64 offset, | ||
225 | u8 *data, u64 size) | ||
226 | { | ||
227 | u64 cache_offset = offset - cache->offset; | ||
228 | u64 cache_size = min(cache->size - cache_offset, size); | ||
229 | |||
230 | memcpy(data, cache->data + cache_offset, cache_size); | ||
231 | return cache_size; | ||
232 | } | ||
233 | |||
234 | static ssize_t | ||
235 | dso_cache__read(struct dso *dso, struct machine *machine, | ||
236 | u64 offset, u8 *data, ssize_t size) | ||
237 | { | ||
238 | struct dso_cache *cache; | ||
239 | ssize_t ret; | ||
240 | int fd; | ||
241 | |||
242 | fd = dso__data_fd(dso, machine); | ||
243 | if (fd < 0) | ||
244 | return -1; | ||
245 | |||
246 | do { | ||
247 | u64 cache_offset; | ||
248 | |||
249 | ret = -ENOMEM; | ||
250 | |||
251 | cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE); | ||
252 | if (!cache) | ||
253 | break; | ||
254 | |||
255 | cache_offset = offset & DSO__DATA_CACHE_MASK; | ||
256 | ret = -EINVAL; | ||
257 | |||
258 | if (-1 == lseek(fd, cache_offset, SEEK_SET)) | ||
259 | break; | ||
260 | |||
261 | ret = read(fd, cache->data, DSO__DATA_CACHE_SIZE); | ||
262 | if (ret <= 0) | ||
263 | break; | ||
264 | |||
265 | cache->offset = cache_offset; | ||
266 | cache->size = ret; | ||
267 | dso_cache__insert(&dso->cache, cache); | ||
268 | |||
269 | ret = dso_cache__memcpy(cache, offset, data, size); | ||
270 | |||
271 | } while (0); | ||
272 | |||
273 | if (ret <= 0) | ||
274 | free(cache); | ||
275 | |||
276 | close(fd); | ||
277 | return ret; | ||
278 | } | ||
279 | |||
280 | static ssize_t dso_cache_read(struct dso *dso, struct machine *machine, | ||
281 | u64 offset, u8 *data, ssize_t size) | ||
282 | { | ||
283 | struct dso_cache *cache; | ||
284 | |||
285 | cache = dso_cache__find(&dso->cache, offset); | ||
286 | if (cache) | ||
287 | return dso_cache__memcpy(cache, offset, data, size); | ||
288 | else | ||
289 | return dso_cache__read(dso, machine, offset, data, size); | ||
290 | } | ||
291 | |||
292 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
293 | u64 offset, u8 *data, ssize_t size) | ||
294 | { | ||
295 | ssize_t r = 0; | ||
296 | u8 *p = data; | ||
297 | |||
298 | do { | ||
299 | ssize_t ret; | ||
300 | |||
301 | ret = dso_cache_read(dso, machine, offset, p, size); | ||
302 | if (ret < 0) | ||
303 | return ret; | ||
304 | |||
305 | /* Reached EOF, return what we have. */ | ||
306 | if (!ret) | ||
307 | break; | ||
308 | |||
309 | BUG_ON(ret > size); | ||
310 | |||
311 | r += ret; | ||
312 | p += ret; | ||
313 | offset += ret; | ||
314 | size -= ret; | ||
315 | |||
316 | } while (size); | ||
317 | |||
318 | return r; | ||
319 | } | ||
320 | |||
321 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
322 | struct machine *machine, u64 addr, | ||
323 | u8 *data, ssize_t size) | ||
324 | { | ||
325 | u64 offset = map->map_ip(map, addr); | ||
326 | return dso__data_read_offset(dso, machine, offset, data, size); | ||
327 | } | ||
328 | |||
329 | struct map *dso__new_map(const char *name) | ||
330 | { | ||
331 | struct map *map = NULL; | ||
332 | struct dso *dso = dso__new(name); | ||
333 | |||
334 | if (dso) | ||
335 | map = map__new2(0, dso, MAP__FUNCTION); | ||
336 | |||
337 | return map; | ||
338 | } | ||
339 | |||
340 | struct dso *dso__kernel_findnew(struct machine *machine, const char *name, | ||
341 | const char *short_name, int dso_type) | ||
342 | { | ||
343 | /* | ||
344 | * The kernel dso could be created by build_id processing. | ||
345 | */ | ||
346 | struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name); | ||
347 | |||
348 | /* | ||
349 | * We need to run this in all cases, since during the build_id | ||
350 | * processing we had no idea this was the kernel dso. | ||
351 | */ | ||
352 | if (dso != NULL) { | ||
353 | dso__set_short_name(dso, short_name); | ||
354 | dso->kernel = dso_type; | ||
355 | } | ||
356 | |||
357 | return dso; | ||
358 | } | ||
359 | |||
360 | void dso__set_long_name(struct dso *dso, char *name) | ||
361 | { | ||
362 | if (name == NULL) | ||
363 | return; | ||
364 | dso->long_name = name; | ||
365 | dso->long_name_len = strlen(name); | ||
366 | } | ||
367 | |||
368 | void dso__set_short_name(struct dso *dso, const char *name) | ||
369 | { | ||
370 | if (name == NULL) | ||
371 | return; | ||
372 | dso->short_name = name; | ||
373 | dso->short_name_len = strlen(name); | ||
374 | } | ||
375 | |||
376 | static void dso__set_basename(struct dso *dso) | ||
377 | { | ||
378 | dso__set_short_name(dso, basename(dso->long_name)); | ||
379 | } | ||
380 | |||
381 | int dso__name_len(const struct dso *dso) | ||
382 | { | ||
383 | if (!dso) | ||
384 | return strlen("[unknown]"); | ||
385 | if (verbose) | ||
386 | return dso->long_name_len; | ||
387 | |||
388 | return dso->short_name_len; | ||
389 | } | ||
390 | |||
391 | bool dso__loaded(const struct dso *dso, enum map_type type) | ||
392 | { | ||
393 | return dso->loaded & (1 << type); | ||
394 | } | ||
395 | |||
396 | bool dso__sorted_by_name(const struct dso *dso, enum map_type type) | ||
397 | { | ||
398 | return dso->sorted_by_name & (1 << type); | ||
399 | } | ||
400 | |||
401 | void dso__set_sorted_by_name(struct dso *dso, enum map_type type) | ||
402 | { | ||
403 | dso->sorted_by_name |= (1 << type); | ||
404 | } | ||
405 | |||
406 | struct dso *dso__new(const char *name) | ||
407 | { | ||
408 | struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1); | ||
409 | |||
410 | if (dso != NULL) { | ||
411 | int i; | ||
412 | strcpy(dso->name, name); | ||
413 | dso__set_long_name(dso, dso->name); | ||
414 | dso__set_short_name(dso, dso->name); | ||
415 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
416 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; | ||
417 | dso->cache = RB_ROOT; | ||
418 | dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
419 | dso->data_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
420 | dso->loaded = 0; | ||
421 | dso->sorted_by_name = 0; | ||
422 | dso->has_build_id = 0; | ||
423 | dso->kernel = DSO_TYPE_USER; | ||
424 | dso->needs_swap = DSO_SWAP__UNSET; | ||
425 | INIT_LIST_HEAD(&dso->node); | ||
426 | } | ||
427 | |||
428 | return dso; | ||
429 | } | ||
430 | |||
431 | void dso__delete(struct dso *dso) | ||
432 | { | ||
433 | int i; | ||
434 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
435 | symbols__delete(&dso->symbols[i]); | ||
436 | if (dso->sname_alloc) | ||
437 | free((char *)dso->short_name); | ||
438 | if (dso->lname_alloc) | ||
439 | free(dso->long_name); | ||
440 | dso_cache__free(&dso->cache); | ||
441 | free(dso); | ||
442 | } | ||
443 | |||
444 | void dso__set_build_id(struct dso *dso, void *build_id) | ||
445 | { | ||
446 | memcpy(dso->build_id, build_id, sizeof(dso->build_id)); | ||
447 | dso->has_build_id = 1; | ||
448 | } | ||
449 | |||
450 | bool dso__build_id_equal(const struct dso *dso, u8 *build_id) | ||
451 | { | ||
452 | return memcmp(dso->build_id, build_id, sizeof(dso->build_id)) == 0; | ||
453 | } | ||
454 | |||
455 | void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine) | ||
456 | { | ||
457 | char path[PATH_MAX]; | ||
458 | |||
459 | if (machine__is_default_guest(machine)) | ||
460 | return; | ||
461 | sprintf(path, "%s/sys/kernel/notes", machine->root_dir); | ||
462 | if (sysfs__read_build_id(path, dso->build_id, | ||
463 | sizeof(dso->build_id)) == 0) | ||
464 | dso->has_build_id = true; | ||
465 | } | ||
466 | |||
467 | int dso__kernel_module_get_build_id(struct dso *dso, | ||
468 | const char *root_dir) | ||
469 | { | ||
470 | char filename[PATH_MAX]; | ||
471 | /* | ||
472 | * kernel module short names are of the form "[module]" and | ||
473 | * we need just "module" here. | ||
474 | */ | ||
475 | const char *name = dso->short_name + 1; | ||
476 | |||
477 | snprintf(filename, sizeof(filename), | ||
478 | "%s/sys/module/%.*s/notes/.note.gnu.build-id", | ||
479 | root_dir, (int)strlen(name) - 1, name); | ||
480 | |||
481 | if (sysfs__read_build_id(filename, dso->build_id, | ||
482 | sizeof(dso->build_id)) == 0) | ||
483 | dso->has_build_id = true; | ||
484 | |||
485 | return 0; | ||
486 | } | ||
487 | |||
488 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits) | ||
489 | { | ||
490 | bool have_build_id = false; | ||
491 | struct dso *pos; | ||
492 | |||
493 | list_for_each_entry(pos, head, node) { | ||
494 | if (with_hits && !pos->hit) | ||
495 | continue; | ||
496 | if (pos->has_build_id) { | ||
497 | have_build_id = true; | ||
498 | continue; | ||
499 | } | ||
500 | if (filename__read_build_id(pos->long_name, pos->build_id, | ||
501 | sizeof(pos->build_id)) > 0) { | ||
502 | have_build_id = true; | ||
503 | pos->has_build_id = true; | ||
504 | } | ||
505 | } | ||
506 | |||
507 | return have_build_id; | ||
508 | } | ||
509 | |||
510 | void dsos__add(struct list_head *head, struct dso *dso) | ||
511 | { | ||
512 | list_add_tail(&dso->node, head); | ||
513 | } | ||
514 | |||
515 | struct dso *dsos__find(struct list_head *head, const char *name) | ||
516 | { | ||
517 | struct dso *pos; | ||
518 | |||
519 | list_for_each_entry(pos, head, node) | ||
520 | if (strcmp(pos->long_name, name) == 0) | ||
521 | return pos; | ||
522 | return NULL; | ||
523 | } | ||
524 | |||
525 | struct dso *__dsos__findnew(struct list_head *head, const char *name) | ||
526 | { | ||
527 | struct dso *dso = dsos__find(head, name); | ||
528 | |||
529 | if (!dso) { | ||
530 | dso = dso__new(name); | ||
531 | if (dso != NULL) { | ||
532 | dsos__add(head, dso); | ||
533 | dso__set_basename(dso); | ||
534 | } | ||
535 | } | ||
536 | |||
537 | return dso; | ||
538 | } | ||
539 | |||
540 | size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | ||
541 | bool with_hits) | ||
542 | { | ||
543 | struct dso *pos; | ||
544 | size_t ret = 0; | ||
545 | |||
546 | list_for_each_entry(pos, head, node) { | ||
547 | if (with_hits && !pos->hit) | ||
548 | continue; | ||
549 | ret += dso__fprintf_buildid(pos, fp); | ||
550 | ret += fprintf(fp, " %s\n", pos->long_name); | ||
551 | } | ||
552 | return ret; | ||
553 | } | ||
554 | |||
555 | size_t __dsos__fprintf(struct list_head *head, FILE *fp) | ||
556 | { | ||
557 | struct dso *pos; | ||
558 | size_t ret = 0; | ||
559 | |||
560 | list_for_each_entry(pos, head, node) { | ||
561 | int i; | ||
562 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
563 | ret += dso__fprintf(pos, i, fp); | ||
564 | } | ||
565 | |||
566 | return ret; | ||
567 | } | ||
568 | |||
569 | size_t dso__fprintf_buildid(struct dso *dso, FILE *fp) | ||
570 | { | ||
571 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
572 | |||
573 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id); | ||
574 | return fprintf(fp, "%s", sbuild_id); | ||
575 | } | ||
576 | |||
577 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp) | ||
578 | { | ||
579 | struct rb_node *nd; | ||
580 | size_t ret = fprintf(fp, "dso: %s (", dso->short_name); | ||
581 | |||
582 | if (dso->short_name != dso->long_name) | ||
583 | ret += fprintf(fp, "%s, ", dso->long_name); | ||
584 | ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type], | ||
585 | dso->loaded ? "" : "NOT "); | ||
586 | ret += dso__fprintf_buildid(dso, fp); | ||
587 | ret += fprintf(fp, ")\n"); | ||
588 | for (nd = rb_first(&dso->symbols[type]); nd; nd = rb_next(nd)) { | ||
589 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); | ||
590 | ret += symbol__fprintf(pos, fp); | ||
591 | } | ||
592 | |||
593 | return ret; | ||
594 | } | ||
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h new file mode 100644 index 000000000000..e03276940b99 --- /dev/null +++ b/tools/perf/util/dso.h | |||
@@ -0,0 +1,148 @@ | |||
1 | #ifndef __PERF_DSO | ||
2 | #define __PERF_DSO | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | #include <linux/rbtree.h> | ||
6 | #include "types.h" | ||
7 | #include "map.h" | ||
8 | |||
9 | enum dso_binary_type { | ||
10 | DSO_BINARY_TYPE__KALLSYMS = 0, | ||
11 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | ||
12 | DSO_BINARY_TYPE__VMLINUX, | ||
13 | DSO_BINARY_TYPE__GUEST_VMLINUX, | ||
14 | DSO_BINARY_TYPE__JAVA_JIT, | ||
15 | DSO_BINARY_TYPE__DEBUGLINK, | ||
16 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
17 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | ||
18 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | ||
19 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | ||
20 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
21 | DSO_BINARY_TYPE__GUEST_KMODULE, | ||
22 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | ||
23 | DSO_BINARY_TYPE__NOT_FOUND, | ||
24 | }; | ||
25 | |||
26 | enum dso_kernel_type { | ||
27 | DSO_TYPE_USER = 0, | ||
28 | DSO_TYPE_KERNEL, | ||
29 | DSO_TYPE_GUEST_KERNEL | ||
30 | }; | ||
31 | |||
32 | enum dso_swap_type { | ||
33 | DSO_SWAP__UNSET, | ||
34 | DSO_SWAP__NO, | ||
35 | DSO_SWAP__YES, | ||
36 | }; | ||
37 | |||
38 | #define DSO__SWAP(dso, type, val) \ | ||
39 | ({ \ | ||
40 | type ____r = val; \ | ||
41 | BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \ | ||
42 | if (dso->needs_swap == DSO_SWAP__YES) { \ | ||
43 | switch (sizeof(____r)) { \ | ||
44 | case 2: \ | ||
45 | ____r = bswap_16(val); \ | ||
46 | break; \ | ||
47 | case 4: \ | ||
48 | ____r = bswap_32(val); \ | ||
49 | break; \ | ||
50 | case 8: \ | ||
51 | ____r = bswap_64(val); \ | ||
52 | break; \ | ||
53 | default: \ | ||
54 | BUG_ON(1); \ | ||
55 | } \ | ||
56 | } \ | ||
57 | ____r; \ | ||
58 | }) | ||
59 | |||
60 | #define DSO__DATA_CACHE_SIZE 4096 | ||
61 | #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) | ||
62 | |||
63 | struct dso_cache { | ||
64 | struct rb_node rb_node; | ||
65 | u64 offset; | ||
66 | u64 size; | ||
67 | char data[0]; | ||
68 | }; | ||
69 | |||
70 | struct dso { | ||
71 | struct list_head node; | ||
72 | struct rb_root symbols[MAP__NR_TYPES]; | ||
73 | struct rb_root symbol_names[MAP__NR_TYPES]; | ||
74 | struct rb_root cache; | ||
75 | enum dso_kernel_type kernel; | ||
76 | enum dso_swap_type needs_swap; | ||
77 | enum dso_binary_type symtab_type; | ||
78 | enum dso_binary_type data_type; | ||
79 | u8 adjust_symbols:1; | ||
80 | u8 has_build_id:1; | ||
81 | u8 hit:1; | ||
82 | u8 annotate_warned:1; | ||
83 | u8 sname_alloc:1; | ||
84 | u8 lname_alloc:1; | ||
85 | u8 sorted_by_name; | ||
86 | u8 loaded; | ||
87 | u8 build_id[BUILD_ID_SIZE]; | ||
88 | const char *short_name; | ||
89 | char *long_name; | ||
90 | u16 long_name_len; | ||
91 | u16 short_name_len; | ||
92 | char name[0]; | ||
93 | }; | ||
94 | |||
95 | static inline void dso__set_loaded(struct dso *dso, enum map_type type) | ||
96 | { | ||
97 | dso->loaded |= (1 << type); | ||
98 | } | ||
99 | |||
100 | struct dso *dso__new(const char *name); | ||
101 | void dso__delete(struct dso *dso); | ||
102 | |||
103 | void dso__set_short_name(struct dso *dso, const char *name); | ||
104 | void dso__set_long_name(struct dso *dso, char *name); | ||
105 | |||
106 | int dso__name_len(const struct dso *dso); | ||
107 | |||
108 | bool dso__loaded(const struct dso *dso, enum map_type type); | ||
109 | |||
110 | bool dso__sorted_by_name(const struct dso *dso, enum map_type type); | ||
111 | void dso__set_sorted_by_name(struct dso *dso, enum map_type type); | ||
112 | void dso__sort_by_name(struct dso *dso, enum map_type type); | ||
113 | |||
114 | void dso__set_build_id(struct dso *dso, void *build_id); | ||
115 | bool dso__build_id_equal(const struct dso *dso, u8 *build_id); | ||
116 | void dso__read_running_kernel_build_id(struct dso *dso, | ||
117 | struct machine *machine); | ||
118 | int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir); | ||
119 | |||
120 | char dso__symtab_origin(const struct dso *dso); | ||
121 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
122 | char *root_dir, char *file, size_t size); | ||
123 | |||
124 | int dso__data_fd(struct dso *dso, struct machine *machine); | ||
125 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
126 | u64 offset, u8 *data, ssize_t size); | ||
127 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
128 | struct machine *machine, u64 addr, | ||
129 | u8 *data, ssize_t size); | ||
130 | |||
131 | struct map *dso__new_map(const char *name); | ||
132 | struct dso *dso__kernel_findnew(struct machine *machine, const char *name, | ||
133 | const char *short_name, int dso_type); | ||
134 | |||
135 | void dsos__add(struct list_head *head, struct dso *dso); | ||
136 | struct dso *dsos__find(struct list_head *head, const char *name); | ||
137 | struct dso *__dsos__findnew(struct list_head *head, const char *name); | ||
138 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); | ||
139 | |||
140 | size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | ||
141 | bool with_hits); | ||
142 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); | ||
143 | |||
144 | size_t dso__fprintf_buildid(struct dso *dso, FILE *fp); | ||
145 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | ||
146 | enum map_type type, FILE *fp); | ||
147 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); | ||
148 | #endif /* __PERF_DSO */ | ||
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index da97aff5bd75..0d573ff4771a 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #include "../perf.h" | 7 | #include "../perf.h" |
8 | #include "map.h" | 8 | #include "map.h" |
9 | #include "build-id.h" | ||
9 | 10 | ||
10 | /* | 11 | /* |
11 | * PERF_SAMPLE_IP | PERF_SAMPLE_TID | * | 12 | * PERF_SAMPLE_IP | PERF_SAMPLE_TID | * |
@@ -96,8 +97,6 @@ struct perf_sample { | |||
96 | struct stack_dump user_stack; | 97 | struct stack_dump user_stack; |
97 | }; | 98 | }; |
98 | 99 | ||
99 | #define BUILD_ID_SIZE 20 | ||
100 | |||
101 | struct build_id_event { | 100 | struct build_id_event { |
102 | struct perf_event_header header; | 101 | struct perf_event_header header; |
103 | pid_t pid; | 102 | pid_t pid; |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 7daad237dea5..195a47a8f052 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "pmu.h" | 23 | #include "pmu.h" |
24 | #include "vdso.h" | 24 | #include "vdso.h" |
25 | #include "strbuf.h" | 25 | #include "strbuf.h" |
26 | #include "build-id.h" | ||
26 | 27 | ||
27 | static bool no_buildid_cache = false; | 28 | static bool no_buildid_cache = false; |
28 | 29 | ||
@@ -2340,6 +2341,16 @@ static int try_all_pipe_abis(uint64_t hdr_sz, struct perf_header *ph) | |||
2340 | return -1; | 2341 | return -1; |
2341 | } | 2342 | } |
2342 | 2343 | ||
2344 | bool is_perf_magic(u64 magic) | ||
2345 | { | ||
2346 | if (!memcmp(&magic, __perf_magic1, sizeof(magic)) | ||
2347 | || magic == __perf_magic2 | ||
2348 | || magic == __perf_magic2_sw) | ||
2349 | return true; | ||
2350 | |||
2351 | return false; | ||
2352 | } | ||
2353 | |||
2343 | static int check_magic_endian(u64 magic, uint64_t hdr_sz, | 2354 | static int check_magic_endian(u64 magic, uint64_t hdr_sz, |
2344 | bool is_pipe, struct perf_header *ph) | 2355 | bool is_pipe, struct perf_header *ph) |
2345 | { | 2356 | { |
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 879d215cdac9..5f1cd6884f37 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
@@ -154,6 +154,7 @@ int perf_event__synthesize_build_id(struct perf_tool *tool, | |||
154 | int perf_event__process_build_id(struct perf_tool *tool, | 154 | int perf_event__process_build_id(struct perf_tool *tool, |
155 | union perf_event *event, | 155 | union perf_event *event, |
156 | struct perf_session *session); | 156 | struct perf_session *session); |
157 | bool is_perf_magic(u64 magic); | ||
157 | 158 | ||
158 | /* | 159 | /* |
159 | * arch specific callback | 160 | * arch specific callback |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index c751624d4153..b87460971736 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -165,6 +165,7 @@ int hist_entry__tui_annotate(struct hist_entry *he, int evidx, | |||
165 | int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, | 165 | int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, |
166 | void(*timer)(void *arg), void *arg, | 166 | void(*timer)(void *arg), void *arg, |
167 | int refresh); | 167 | int refresh); |
168 | int script_browse(const char *script_opt); | ||
168 | #else | 169 | #else |
169 | static inline | 170 | static inline |
170 | int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, | 171 | int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, |
@@ -186,6 +187,12 @@ static inline int hist_entry__tui_annotate(struct hist_entry *self | |||
186 | { | 187 | { |
187 | return 0; | 188 | return 0; |
188 | } | 189 | } |
190 | |||
191 | static inline int script_browse(const char *script_opt) | ||
192 | { | ||
193 | return 0; | ||
194 | } | ||
195 | |||
189 | #define K_LEFT -1 | 196 | #define K_LEFT -1 |
190 | #define K_RIGHT -2 | 197 | #define K_RIGHT -2 |
191 | #endif | 198 | #endif |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 6109fa4d14cd..9b40c444039c 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "thread.h" | 10 | #include "thread.h" |
11 | #include "strlist.h" | 11 | #include "strlist.h" |
12 | #include "vdso.h" | 12 | #include "vdso.h" |
13 | #include "build-id.h" | ||
13 | 14 | ||
14 | const char *map_type__name[MAP__NR_TYPES] = { | 15 | const char *map_type__name[MAP__NR_TYPES] = { |
15 | [MAP__FUNCTION] = "Functions", | 16 | [MAP__FUNCTION] = "Functions", |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 3a3efcf3e4e9..c0b785b50849 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -827,8 +827,6 @@ int parse_events(struct perf_evlist *evlist, const char *str, | |||
827 | * Both call perf_evlist__delete in case of error, so we dont | 827 | * Both call perf_evlist__delete in case of error, so we dont |
828 | * need to bother. | 828 | * need to bother. |
829 | */ | 829 | */ |
830 | fprintf(stderr, "invalid or unsupported event: '%s'\n", str); | ||
831 | fprintf(stderr, "Run 'perf list' for a list of valid events\n"); | ||
832 | return ret; | 830 | return ret; |
833 | } | 831 | } |
834 | 832 | ||
@@ -836,7 +834,13 @@ int parse_events_option(const struct option *opt, const char *str, | |||
836 | int unset __maybe_unused) | 834 | int unset __maybe_unused) |
837 | { | 835 | { |
838 | struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; | 836 | struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; |
839 | return parse_events(evlist, str, unset); | 837 | int ret = parse_events(evlist, str, unset); |
838 | |||
839 | if (ret) { | ||
840 | fprintf(stderr, "invalid or unsupported event: '%s'\n", str); | ||
841 | fprintf(stderr, "Run 'perf list' for a list of valid events\n"); | ||
842 | } | ||
843 | return ret; | ||
840 | } | 844 | } |
841 | 845 | ||
842 | int parse_filter(const struct option *opt, const char *str, | 846 | int parse_filter(const struct option *opt, const char *str, |
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 9181bf212fb9..a2657fd96837 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c | |||
@@ -1015,6 +1015,8 @@ PyMODINIT_FUNC initperf(void) | |||
1015 | pyrf_cpu_map__setup_types() < 0) | 1015 | pyrf_cpu_map__setup_types() < 0) |
1016 | return; | 1016 | return; |
1017 | 1017 | ||
1018 | page_size = sysconf(_SC_PAGE_SIZE); | ||
1019 | |||
1018 | Py_INCREF(&pyrf_evlist__type); | 1020 | Py_INCREF(&pyrf_evlist__type); |
1019 | PyModule_AddObject(module, "evlist", (PyObject*)&pyrf_evlist__type); | 1021 | PyModule_AddObject(module, "evlist", (PyObject*)&pyrf_evlist__type); |
1020 | 1022 | ||
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index 32170590892d..346707df04b9 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -314,6 +314,24 @@ int strtailcmp(const char *s1, const char *s2) | |||
314 | } | 314 | } |
315 | 315 | ||
316 | /** | 316 | /** |
317 | * strxfrchar - Locate and replace character in @s | ||
318 | * @s: The string to be searched/changed. | ||
319 | * @from: Source character to be replaced. | ||
320 | * @to: Destination character. | ||
321 | * | ||
322 | * Return pointer to the changed string. | ||
323 | */ | ||
324 | char *strxfrchar(char *s, char from, char to) | ||
325 | { | ||
326 | char *p = s; | ||
327 | |||
328 | while ((p = strchr(p, from)) != NULL) | ||
329 | *p++ = to; | ||
330 | |||
331 | return s; | ||
332 | } | ||
333 | |||
334 | /** | ||
317 | * rtrim - Removes trailing whitespace from @s. | 335 | * rtrim - Removes trailing whitespace from @s. |
318 | * @s: The string to be stripped. | 336 | * @s: The string to be stripped. |
319 | * | 337 | * |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index e2e8c697cffe..624c65e6ab98 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #define KSYM_NAME_LEN 256 | 23 | #define KSYM_NAME_LEN 256 |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | static void dso_cache__free(struct rb_root *root); | ||
27 | static int dso__load_kernel_sym(struct dso *dso, struct map *map, | 26 | static int dso__load_kernel_sym(struct dso *dso, struct map *map, |
28 | symbol_filter_t filter); | 27 | symbol_filter_t filter); |
29 | static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map, | 28 | static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map, |
@@ -56,39 +55,6 @@ static enum dso_binary_type binary_type_symtab[] = { | |||
56 | 55 | ||
57 | #define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab) | 56 | #define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab) |
58 | 57 | ||
59 | static enum dso_binary_type binary_type_data[] = { | ||
60 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
61 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
62 | DSO_BINARY_TYPE__NOT_FOUND, | ||
63 | }; | ||
64 | |||
65 | #define DSO_BINARY_TYPE__DATA_CNT ARRAY_SIZE(binary_type_data) | ||
66 | |||
67 | int dso__name_len(const struct dso *dso) | ||
68 | { | ||
69 | if (!dso) | ||
70 | return strlen("[unknown]"); | ||
71 | if (verbose) | ||
72 | return dso->long_name_len; | ||
73 | |||
74 | return dso->short_name_len; | ||
75 | } | ||
76 | |||
77 | bool dso__loaded(const struct dso *dso, enum map_type type) | ||
78 | { | ||
79 | return dso->loaded & (1 << type); | ||
80 | } | ||
81 | |||
82 | bool dso__sorted_by_name(const struct dso *dso, enum map_type type) | ||
83 | { | ||
84 | return dso->sorted_by_name & (1 << type); | ||
85 | } | ||
86 | |||
87 | static void dso__set_sorted_by_name(struct dso *dso, enum map_type type) | ||
88 | { | ||
89 | dso->sorted_by_name |= (1 << type); | ||
90 | } | ||
91 | |||
92 | bool symbol_type__is_a(char symbol_type, enum map_type map_type) | 58 | bool symbol_type__is_a(char symbol_type, enum map_type map_type) |
93 | { | 59 | { |
94 | symbol_type = toupper(symbol_type); | 60 | symbol_type = toupper(symbol_type); |
@@ -270,7 +236,7 @@ void symbol__delete(struct symbol *sym) | |||
270 | free(((void *)sym) - symbol_conf.priv_size); | 236 | free(((void *)sym) - symbol_conf.priv_size); |
271 | } | 237 | } |
272 | 238 | ||
273 | static size_t symbol__fprintf(struct symbol *sym, FILE *fp) | 239 | size_t symbol__fprintf(struct symbol *sym, FILE *fp) |
274 | { | 240 | { |
275 | return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n", | 241 | return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n", |
276 | sym->start, sym->end, | 242 | sym->start, sym->end, |
@@ -301,53 +267,7 @@ size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp) | |||
301 | return symbol__fprintf_symname_offs(sym, NULL, fp); | 267 | return symbol__fprintf_symname_offs(sym, NULL, fp); |
302 | } | 268 | } |
303 | 269 | ||
304 | void dso__set_long_name(struct dso *dso, char *name) | 270 | void symbols__delete(struct rb_root *symbols) |
305 | { | ||
306 | if (name == NULL) | ||
307 | return; | ||
308 | dso->long_name = name; | ||
309 | dso->long_name_len = strlen(name); | ||
310 | } | ||
311 | |||
312 | static void dso__set_short_name(struct dso *dso, const char *name) | ||
313 | { | ||
314 | if (name == NULL) | ||
315 | return; | ||
316 | dso->short_name = name; | ||
317 | dso->short_name_len = strlen(name); | ||
318 | } | ||
319 | |||
320 | static void dso__set_basename(struct dso *dso) | ||
321 | { | ||
322 | dso__set_short_name(dso, basename(dso->long_name)); | ||
323 | } | ||
324 | |||
325 | struct dso *dso__new(const char *name) | ||
326 | { | ||
327 | struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1); | ||
328 | |||
329 | if (dso != NULL) { | ||
330 | int i; | ||
331 | strcpy(dso->name, name); | ||
332 | dso__set_long_name(dso, dso->name); | ||
333 | dso__set_short_name(dso, dso->name); | ||
334 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
335 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; | ||
336 | dso->cache = RB_ROOT; | ||
337 | dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
338 | dso->data_type = DSO_BINARY_TYPE__NOT_FOUND; | ||
339 | dso->loaded = 0; | ||
340 | dso->sorted_by_name = 0; | ||
341 | dso->has_build_id = 0; | ||
342 | dso->kernel = DSO_TYPE_USER; | ||
343 | dso->needs_swap = DSO_SWAP__UNSET; | ||
344 | INIT_LIST_HEAD(&dso->node); | ||
345 | } | ||
346 | |||
347 | return dso; | ||
348 | } | ||
349 | |||
350 | static void symbols__delete(struct rb_root *symbols) | ||
351 | { | 271 | { |
352 | struct symbol *pos; | 272 | struct symbol *pos; |
353 | struct rb_node *next = rb_first(symbols); | 273 | struct rb_node *next = rb_first(symbols); |
@@ -360,25 +280,6 @@ static void symbols__delete(struct rb_root *symbols) | |||
360 | } | 280 | } |
361 | } | 281 | } |
362 | 282 | ||
363 | void dso__delete(struct dso *dso) | ||
364 | { | ||
365 | int i; | ||
366 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
367 | symbols__delete(&dso->symbols[i]); | ||
368 | if (dso->sname_alloc) | ||
369 | free((char *)dso->short_name); | ||
370 | if (dso->lname_alloc) | ||
371 | free(dso->long_name); | ||
372 | dso_cache__free(&dso->cache); | ||
373 | free(dso); | ||
374 | } | ||
375 | |||
376 | void dso__set_build_id(struct dso *dso, void *build_id) | ||
377 | { | ||
378 | memcpy(dso->build_id, build_id, sizeof(dso->build_id)); | ||
379 | dso->has_build_id = 1; | ||
380 | } | ||
381 | |||
382 | void symbols__insert(struct rb_root *symbols, struct symbol *sym) | 283 | void symbols__insert(struct rb_root *symbols, struct symbol *sym) |
383 | { | 284 | { |
384 | struct rb_node **p = &symbols->rb_node; | 285 | struct rb_node **p = &symbols->rb_node; |
@@ -504,29 +405,6 @@ void dso__sort_by_name(struct dso *dso, enum map_type type) | |||
504 | &dso->symbols[type]); | 405 | &dso->symbols[type]); |
505 | } | 406 | } |
506 | 407 | ||
507 | int build_id__sprintf(const u8 *build_id, int len, char *bf) | ||
508 | { | ||
509 | char *bid = bf; | ||
510 | const u8 *raw = build_id; | ||
511 | int i; | ||
512 | |||
513 | for (i = 0; i < len; ++i) { | ||
514 | sprintf(bid, "%02x", *raw); | ||
515 | ++raw; | ||
516 | bid += 2; | ||
517 | } | ||
518 | |||
519 | return raw - build_id; | ||
520 | } | ||
521 | |||
522 | size_t dso__fprintf_buildid(struct dso *dso, FILE *fp) | ||
523 | { | ||
524 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
525 | |||
526 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id); | ||
527 | return fprintf(fp, "%s", sbuild_id); | ||
528 | } | ||
529 | |||
530 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | 408 | size_t dso__fprintf_symbols_by_name(struct dso *dso, |
531 | enum map_type type, FILE *fp) | 409 | enum map_type type, FILE *fp) |
532 | { | 410 | { |
@@ -542,25 +420,6 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso, | |||
542 | return ret; | 420 | return ret; |
543 | } | 421 | } |
544 | 422 | ||
545 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp) | ||
546 | { | ||
547 | struct rb_node *nd; | ||
548 | size_t ret = fprintf(fp, "dso: %s (", dso->short_name); | ||
549 | |||
550 | if (dso->short_name != dso->long_name) | ||
551 | ret += fprintf(fp, "%s, ", dso->long_name); | ||
552 | ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type], | ||
553 | dso->loaded ? "" : "NOT "); | ||
554 | ret += dso__fprintf_buildid(dso, fp); | ||
555 | ret += fprintf(fp, ")\n"); | ||
556 | for (nd = rb_first(&dso->symbols[type]); nd; nd = rb_next(nd)) { | ||
557 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); | ||
558 | ret += symbol__fprintf(pos, fp); | ||
559 | } | ||
560 | |||
561 | return ret; | ||
562 | } | ||
563 | |||
564 | int kallsyms__parse(const char *filename, void *arg, | 423 | int kallsyms__parse(const char *filename, void *arg, |
565 | int (*process_symbol)(void *arg, const char *name, | 424 | int (*process_symbol)(void *arg, const char *name, |
566 | char type, u64 start)) | 425 | char type, u64 start)) |
@@ -892,136 +751,6 @@ out_failure: | |||
892 | return -1; | 751 | return -1; |
893 | } | 752 | } |
894 | 753 | ||
895 | bool dso__build_id_equal(const struct dso *dso, u8 *build_id) | ||
896 | { | ||
897 | return memcmp(dso->build_id, build_id, sizeof(dso->build_id)) == 0; | ||
898 | } | ||
899 | |||
900 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits) | ||
901 | { | ||
902 | bool have_build_id = false; | ||
903 | struct dso *pos; | ||
904 | |||
905 | list_for_each_entry(pos, head, node) { | ||
906 | if (with_hits && !pos->hit) | ||
907 | continue; | ||
908 | if (pos->has_build_id) { | ||
909 | have_build_id = true; | ||
910 | continue; | ||
911 | } | ||
912 | if (filename__read_build_id(pos->long_name, pos->build_id, | ||
913 | sizeof(pos->build_id)) > 0) { | ||
914 | have_build_id = true; | ||
915 | pos->has_build_id = true; | ||
916 | } | ||
917 | } | ||
918 | |||
919 | return have_build_id; | ||
920 | } | ||
921 | |||
922 | char dso__symtab_origin(const struct dso *dso) | ||
923 | { | ||
924 | static const char origin[] = { | ||
925 | [DSO_BINARY_TYPE__KALLSYMS] = 'k', | ||
926 | [DSO_BINARY_TYPE__VMLINUX] = 'v', | ||
927 | [DSO_BINARY_TYPE__JAVA_JIT] = 'j', | ||
928 | [DSO_BINARY_TYPE__DEBUGLINK] = 'l', | ||
929 | [DSO_BINARY_TYPE__BUILD_ID_CACHE] = 'B', | ||
930 | [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f', | ||
931 | [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u', | ||
932 | [DSO_BINARY_TYPE__BUILDID_DEBUGINFO] = 'b', | ||
933 | [DSO_BINARY_TYPE__SYSTEM_PATH_DSO] = 'd', | ||
934 | [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE] = 'K', | ||
935 | [DSO_BINARY_TYPE__GUEST_KALLSYMS] = 'g', | ||
936 | [DSO_BINARY_TYPE__GUEST_KMODULE] = 'G', | ||
937 | [DSO_BINARY_TYPE__GUEST_VMLINUX] = 'V', | ||
938 | }; | ||
939 | |||
940 | if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND) | ||
941 | return '!'; | ||
942 | return origin[dso->symtab_type]; | ||
943 | } | ||
944 | |||
945 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
946 | char *root_dir, char *file, size_t size) | ||
947 | { | ||
948 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
949 | int ret = 0; | ||
950 | |||
951 | switch (type) { | ||
952 | case DSO_BINARY_TYPE__DEBUGLINK: { | ||
953 | char *debuglink; | ||
954 | |||
955 | strncpy(file, dso->long_name, size); | ||
956 | debuglink = file + dso->long_name_len; | ||
957 | while (debuglink != file && *debuglink != '/') | ||
958 | debuglink--; | ||
959 | if (*debuglink == '/') | ||
960 | debuglink++; | ||
961 | filename__read_debuglink(dso->long_name, debuglink, | ||
962 | size - (debuglink - file)); | ||
963 | } | ||
964 | break; | ||
965 | case DSO_BINARY_TYPE__BUILD_ID_CACHE: | ||
966 | /* skip the locally configured cache if a symfs is given */ | ||
967 | if (symbol_conf.symfs[0] || | ||
968 | (dso__build_id_filename(dso, file, size) == NULL)) | ||
969 | ret = -1; | ||
970 | break; | ||
971 | |||
972 | case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: | ||
973 | snprintf(file, size, "%s/usr/lib/debug%s.debug", | ||
974 | symbol_conf.symfs, dso->long_name); | ||
975 | break; | ||
976 | |||
977 | case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: | ||
978 | snprintf(file, size, "%s/usr/lib/debug%s", | ||
979 | symbol_conf.symfs, dso->long_name); | ||
980 | break; | ||
981 | |||
982 | case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: | ||
983 | if (!dso->has_build_id) { | ||
984 | ret = -1; | ||
985 | break; | ||
986 | } | ||
987 | |||
988 | build_id__sprintf(dso->build_id, | ||
989 | sizeof(dso->build_id), | ||
990 | build_id_hex); | ||
991 | snprintf(file, size, | ||
992 | "%s/usr/lib/debug/.build-id/%.2s/%s.debug", | ||
993 | symbol_conf.symfs, build_id_hex, build_id_hex + 2); | ||
994 | break; | ||
995 | |||
996 | case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: | ||
997 | snprintf(file, size, "%s%s", | ||
998 | symbol_conf.symfs, dso->long_name); | ||
999 | break; | ||
1000 | |||
1001 | case DSO_BINARY_TYPE__GUEST_KMODULE: | ||
1002 | snprintf(file, size, "%s%s%s", symbol_conf.symfs, | ||
1003 | root_dir, dso->long_name); | ||
1004 | break; | ||
1005 | |||
1006 | case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: | ||
1007 | snprintf(file, size, "%s%s", symbol_conf.symfs, | ||
1008 | dso->long_name); | ||
1009 | break; | ||
1010 | |||
1011 | default: | ||
1012 | case DSO_BINARY_TYPE__KALLSYMS: | ||
1013 | case DSO_BINARY_TYPE__VMLINUX: | ||
1014 | case DSO_BINARY_TYPE__GUEST_KALLSYMS: | ||
1015 | case DSO_BINARY_TYPE__GUEST_VMLINUX: | ||
1016 | case DSO_BINARY_TYPE__JAVA_JIT: | ||
1017 | case DSO_BINARY_TYPE__NOT_FOUND: | ||
1018 | ret = -1; | ||
1019 | break; | ||
1020 | } | ||
1021 | |||
1022 | return ret; | ||
1023 | } | ||
1024 | |||
1025 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | 754 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) |
1026 | { | 755 | { |
1027 | char *name; | 756 | char *name; |
@@ -1157,27 +886,6 @@ struct map *map_groups__find_by_name(struct map_groups *mg, | |||
1157 | return NULL; | 886 | return NULL; |
1158 | } | 887 | } |
1159 | 888 | ||
1160 | static int dso__kernel_module_get_build_id(struct dso *dso, | ||
1161 | const char *root_dir) | ||
1162 | { | ||
1163 | char filename[PATH_MAX]; | ||
1164 | /* | ||
1165 | * kernel module short names are of the form "[module]" and | ||
1166 | * we need just "module" here. | ||
1167 | */ | ||
1168 | const char *name = dso->short_name + 1; | ||
1169 | |||
1170 | snprintf(filename, sizeof(filename), | ||
1171 | "%s/sys/module/%.*s/notes/.note.gnu.build-id", | ||
1172 | root_dir, (int)strlen(name) - 1, name); | ||
1173 | |||
1174 | if (sysfs__read_build_id(filename, dso->build_id, | ||
1175 | sizeof(dso->build_id)) == 0) | ||
1176 | dso->has_build_id = true; | ||
1177 | |||
1178 | return 0; | ||
1179 | } | ||
1180 | |||
1181 | static int map_groups__set_modules_path_dir(struct map_groups *mg, | 889 | static int map_groups__set_modules_path_dir(struct map_groups *mg, |
1182 | const char *dir_name) | 890 | const char *dir_name) |
1183 | { | 891 | { |
@@ -1591,50 +1299,6 @@ out_try_fixup: | |||
1591 | return err; | 1299 | return err; |
1592 | } | 1300 | } |
1593 | 1301 | ||
1594 | void dsos__add(struct list_head *head, struct dso *dso) | ||
1595 | { | ||
1596 | list_add_tail(&dso->node, head); | ||
1597 | } | ||
1598 | |||
1599 | struct dso *dsos__find(struct list_head *head, const char *name) | ||
1600 | { | ||
1601 | struct dso *pos; | ||
1602 | |||
1603 | list_for_each_entry(pos, head, node) | ||
1604 | if (strcmp(pos->long_name, name) == 0) | ||
1605 | return pos; | ||
1606 | return NULL; | ||
1607 | } | ||
1608 | |||
1609 | struct dso *__dsos__findnew(struct list_head *head, const char *name) | ||
1610 | { | ||
1611 | struct dso *dso = dsos__find(head, name); | ||
1612 | |||
1613 | if (!dso) { | ||
1614 | dso = dso__new(name); | ||
1615 | if (dso != NULL) { | ||
1616 | dsos__add(head, dso); | ||
1617 | dso__set_basename(dso); | ||
1618 | } | ||
1619 | } | ||
1620 | |||
1621 | return dso; | ||
1622 | } | ||
1623 | |||
1624 | size_t __dsos__fprintf(struct list_head *head, FILE *fp) | ||
1625 | { | ||
1626 | struct dso *pos; | ||
1627 | size_t ret = 0; | ||
1628 | |||
1629 | list_for_each_entry(pos, head, node) { | ||
1630 | int i; | ||
1631 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
1632 | ret += dso__fprintf(pos, i, fp); | ||
1633 | } | ||
1634 | |||
1635 | return ret; | ||
1636 | } | ||
1637 | |||
1638 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp) | 1302 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp) |
1639 | { | 1303 | { |
1640 | struct rb_node *nd; | 1304 | struct rb_node *nd; |
@@ -1649,21 +1313,6 @@ size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp) | |||
1649 | return ret; | 1313 | return ret; |
1650 | } | 1314 | } |
1651 | 1315 | ||
1652 | static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | ||
1653 | bool with_hits) | ||
1654 | { | ||
1655 | struct dso *pos; | ||
1656 | size_t ret = 0; | ||
1657 | |||
1658 | list_for_each_entry(pos, head, node) { | ||
1659 | if (with_hits && !pos->hit) | ||
1660 | continue; | ||
1661 | ret += dso__fprintf_buildid(pos, fp); | ||
1662 | ret += fprintf(fp, " %s\n", pos->long_name); | ||
1663 | } | ||
1664 | return ret; | ||
1665 | } | ||
1666 | |||
1667 | size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, | 1316 | size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, |
1668 | bool with_hits) | 1317 | bool with_hits) |
1669 | { | 1318 | { |
@@ -1684,39 +1333,6 @@ size_t machines__fprintf_dsos_buildid(struct rb_root *machines, | |||
1684 | return ret; | 1333 | return ret; |
1685 | } | 1334 | } |
1686 | 1335 | ||
1687 | static struct dso* | ||
1688 | dso__kernel_findnew(struct machine *machine, const char *name, | ||
1689 | const char *short_name, int dso_type) | ||
1690 | { | ||
1691 | /* | ||
1692 | * The kernel dso could be created by build_id processing. | ||
1693 | */ | ||
1694 | struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name); | ||
1695 | |||
1696 | /* | ||
1697 | * We need to run this in all cases, since during the build_id | ||
1698 | * processing we had no idea this was the kernel dso. | ||
1699 | */ | ||
1700 | if (dso != NULL) { | ||
1701 | dso__set_short_name(dso, short_name); | ||
1702 | dso->kernel = dso_type; | ||
1703 | } | ||
1704 | |||
1705 | return dso; | ||
1706 | } | ||
1707 | |||
1708 | void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine) | ||
1709 | { | ||
1710 | char path[PATH_MAX]; | ||
1711 | |||
1712 | if (machine__is_default_guest(machine)) | ||
1713 | return; | ||
1714 | sprintf(path, "%s/sys/kernel/notes", machine->root_dir); | ||
1715 | if (sysfs__read_build_id(path, dso->build_id, | ||
1716 | sizeof(dso->build_id)) == 0) | ||
1717 | dso->has_build_id = true; | ||
1718 | } | ||
1719 | |||
1720 | static struct dso *machine__get_kernel(struct machine *machine) | 1336 | static struct dso *machine__get_kernel(struct machine *machine) |
1721 | { | 1337 | { |
1722 | const char *vmlinux_name = NULL; | 1338 | const char *vmlinux_name = NULL; |
@@ -2065,49 +1681,6 @@ int machines__create_kernel_maps(struct rb_root *machines, pid_t pid) | |||
2065 | return machine__create_kernel_maps(machine); | 1681 | return machine__create_kernel_maps(machine); |
2066 | } | 1682 | } |
2067 | 1683 | ||
2068 | static int hex(char ch) | ||
2069 | { | ||
2070 | if ((ch >= '0') && (ch <= '9')) | ||
2071 | return ch - '0'; | ||
2072 | if ((ch >= 'a') && (ch <= 'f')) | ||
2073 | return ch - 'a' + 10; | ||
2074 | if ((ch >= 'A') && (ch <= 'F')) | ||
2075 | return ch - 'A' + 10; | ||
2076 | return -1; | ||
2077 | } | ||
2078 | |||
2079 | /* | ||
2080 | * While we find nice hex chars, build a long_val. | ||
2081 | * Return number of chars processed. | ||
2082 | */ | ||
2083 | int hex2u64(const char *ptr, u64 *long_val) | ||
2084 | { | ||
2085 | const char *p = ptr; | ||
2086 | *long_val = 0; | ||
2087 | |||
2088 | while (*p) { | ||
2089 | const int hex_val = hex(*p); | ||
2090 | |||
2091 | if (hex_val < 0) | ||
2092 | break; | ||
2093 | |||
2094 | *long_val = (*long_val << 4) | hex_val; | ||
2095 | p++; | ||
2096 | } | ||
2097 | |||
2098 | return p - ptr; | ||
2099 | } | ||
2100 | |||
2101 | char *strxfrchar(char *s, char from, char to) | ||
2102 | { | ||
2103 | char *p = s; | ||
2104 | |||
2105 | while ((p = strchr(p, from)) != NULL) | ||
2106 | *p++ = to; | ||
2107 | |||
2108 | return s; | ||
2109 | } | ||
2110 | |||
2111 | int machines__create_guest_kernel_maps(struct rb_root *machines) | 1684 | int machines__create_guest_kernel_maps(struct rb_root *machines) |
2112 | { | 1685 | { |
2113 | int ret = 0; | 1686 | int ret = 0; |
@@ -2202,229 +1775,3 @@ int machine__load_vmlinux_path(struct machine *machine, enum map_type type, | |||
2202 | 1775 | ||
2203 | return ret; | 1776 | return ret; |
2204 | } | 1777 | } |
2205 | |||
2206 | struct map *dso__new_map(const char *name) | ||
2207 | { | ||
2208 | struct map *map = NULL; | ||
2209 | struct dso *dso = dso__new(name); | ||
2210 | |||
2211 | if (dso) | ||
2212 | map = map__new2(0, dso, MAP__FUNCTION); | ||
2213 | |||
2214 | return map; | ||
2215 | } | ||
2216 | |||
2217 | static int open_dso(struct dso *dso, struct machine *machine) | ||
2218 | { | ||
2219 | char *root_dir = (char *) ""; | ||
2220 | char *name; | ||
2221 | int fd; | ||
2222 | |||
2223 | name = malloc(PATH_MAX); | ||
2224 | if (!name) | ||
2225 | return -ENOMEM; | ||
2226 | |||
2227 | if (machine) | ||
2228 | root_dir = machine->root_dir; | ||
2229 | |||
2230 | if (dso__binary_type_file(dso, dso->data_type, | ||
2231 | root_dir, name, PATH_MAX)) { | ||
2232 | free(name); | ||
2233 | return -EINVAL; | ||
2234 | } | ||
2235 | |||
2236 | fd = open(name, O_RDONLY); | ||
2237 | free(name); | ||
2238 | return fd; | ||
2239 | } | ||
2240 | |||
2241 | int dso__data_fd(struct dso *dso, struct machine *machine) | ||
2242 | { | ||
2243 | int i = 0; | ||
2244 | |||
2245 | if (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND) | ||
2246 | return open_dso(dso, machine); | ||
2247 | |||
2248 | do { | ||
2249 | int fd; | ||
2250 | |||
2251 | dso->data_type = binary_type_data[i++]; | ||
2252 | |||
2253 | fd = open_dso(dso, machine); | ||
2254 | if (fd >= 0) | ||
2255 | return fd; | ||
2256 | |||
2257 | } while (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND); | ||
2258 | |||
2259 | return -EINVAL; | ||
2260 | } | ||
2261 | |||
2262 | static void | ||
2263 | dso_cache__free(struct rb_root *root) | ||
2264 | { | ||
2265 | struct rb_node *next = rb_first(root); | ||
2266 | |||
2267 | while (next) { | ||
2268 | struct dso_cache *cache; | ||
2269 | |||
2270 | cache = rb_entry(next, struct dso_cache, rb_node); | ||
2271 | next = rb_next(&cache->rb_node); | ||
2272 | rb_erase(&cache->rb_node, root); | ||
2273 | free(cache); | ||
2274 | } | ||
2275 | } | ||
2276 | |||
2277 | static struct dso_cache* | ||
2278 | dso_cache__find(struct rb_root *root, u64 offset) | ||
2279 | { | ||
2280 | struct rb_node **p = &root->rb_node; | ||
2281 | struct rb_node *parent = NULL; | ||
2282 | struct dso_cache *cache; | ||
2283 | |||
2284 | while (*p != NULL) { | ||
2285 | u64 end; | ||
2286 | |||
2287 | parent = *p; | ||
2288 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
2289 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
2290 | |||
2291 | if (offset < cache->offset) | ||
2292 | p = &(*p)->rb_left; | ||
2293 | else if (offset >= end) | ||
2294 | p = &(*p)->rb_right; | ||
2295 | else | ||
2296 | return cache; | ||
2297 | } | ||
2298 | return NULL; | ||
2299 | } | ||
2300 | |||
2301 | static void | ||
2302 | dso_cache__insert(struct rb_root *root, struct dso_cache *new) | ||
2303 | { | ||
2304 | struct rb_node **p = &root->rb_node; | ||
2305 | struct rb_node *parent = NULL; | ||
2306 | struct dso_cache *cache; | ||
2307 | u64 offset = new->offset; | ||
2308 | |||
2309 | while (*p != NULL) { | ||
2310 | u64 end; | ||
2311 | |||
2312 | parent = *p; | ||
2313 | cache = rb_entry(parent, struct dso_cache, rb_node); | ||
2314 | end = cache->offset + DSO__DATA_CACHE_SIZE; | ||
2315 | |||
2316 | if (offset < cache->offset) | ||
2317 | p = &(*p)->rb_left; | ||
2318 | else if (offset >= end) | ||
2319 | p = &(*p)->rb_right; | ||
2320 | } | ||
2321 | |||
2322 | rb_link_node(&new->rb_node, parent, p); | ||
2323 | rb_insert_color(&new->rb_node, root); | ||
2324 | } | ||
2325 | |||
2326 | static ssize_t | ||
2327 | dso_cache__memcpy(struct dso_cache *cache, u64 offset, | ||
2328 | u8 *data, u64 size) | ||
2329 | { | ||
2330 | u64 cache_offset = offset - cache->offset; | ||
2331 | u64 cache_size = min(cache->size - cache_offset, size); | ||
2332 | |||
2333 | memcpy(data, cache->data + cache_offset, cache_size); | ||
2334 | return cache_size; | ||
2335 | } | ||
2336 | |||
2337 | static ssize_t | ||
2338 | dso_cache__read(struct dso *dso, struct machine *machine, | ||
2339 | u64 offset, u8 *data, ssize_t size) | ||
2340 | { | ||
2341 | struct dso_cache *cache; | ||
2342 | ssize_t ret; | ||
2343 | int fd; | ||
2344 | |||
2345 | fd = dso__data_fd(dso, machine); | ||
2346 | if (fd < 0) | ||
2347 | return -1; | ||
2348 | |||
2349 | do { | ||
2350 | u64 cache_offset; | ||
2351 | |||
2352 | ret = -ENOMEM; | ||
2353 | |||
2354 | cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE); | ||
2355 | if (!cache) | ||
2356 | break; | ||
2357 | |||
2358 | cache_offset = offset & DSO__DATA_CACHE_MASK; | ||
2359 | ret = -EINVAL; | ||
2360 | |||
2361 | if (-1 == lseek(fd, cache_offset, SEEK_SET)) | ||
2362 | break; | ||
2363 | |||
2364 | ret = read(fd, cache->data, DSO__DATA_CACHE_SIZE); | ||
2365 | if (ret <= 0) | ||
2366 | break; | ||
2367 | |||
2368 | cache->offset = cache_offset; | ||
2369 | cache->size = ret; | ||
2370 | dso_cache__insert(&dso->cache, cache); | ||
2371 | |||
2372 | ret = dso_cache__memcpy(cache, offset, data, size); | ||
2373 | |||
2374 | } while (0); | ||
2375 | |||
2376 | if (ret <= 0) | ||
2377 | free(cache); | ||
2378 | |||
2379 | close(fd); | ||
2380 | return ret; | ||
2381 | } | ||
2382 | |||
2383 | static ssize_t dso_cache_read(struct dso *dso, struct machine *machine, | ||
2384 | u64 offset, u8 *data, ssize_t size) | ||
2385 | { | ||
2386 | struct dso_cache *cache; | ||
2387 | |||
2388 | cache = dso_cache__find(&dso->cache, offset); | ||
2389 | if (cache) | ||
2390 | return dso_cache__memcpy(cache, offset, data, size); | ||
2391 | else | ||
2392 | return dso_cache__read(dso, machine, offset, data, size); | ||
2393 | } | ||
2394 | |||
2395 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
2396 | u64 offset, u8 *data, ssize_t size) | ||
2397 | { | ||
2398 | ssize_t r = 0; | ||
2399 | u8 *p = data; | ||
2400 | |||
2401 | do { | ||
2402 | ssize_t ret; | ||
2403 | |||
2404 | ret = dso_cache_read(dso, machine, offset, p, size); | ||
2405 | if (ret < 0) | ||
2406 | return ret; | ||
2407 | |||
2408 | /* Reached EOF, return what we have. */ | ||
2409 | if (!ret) | ||
2410 | break; | ||
2411 | |||
2412 | BUG_ON(ret > size); | ||
2413 | |||
2414 | r += ret; | ||
2415 | p += ret; | ||
2416 | offset += ret; | ||
2417 | size -= ret; | ||
2418 | |||
2419 | } while (size); | ||
2420 | |||
2421 | return r; | ||
2422 | } | ||
2423 | |||
2424 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
2425 | struct machine *machine, u64 addr, | ||
2426 | u8 *data, ssize_t size) | ||
2427 | { | ||
2428 | u64 offset = map->map_ip(map, addr); | ||
2429 | return dso__data_read_offset(dso, machine, offset, data, size); | ||
2430 | } | ||
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 8b6ef7fac745..863b05bea5ff 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <byteswap.h> | 12 | #include <byteswap.h> |
13 | #include <libgen.h> | 13 | #include <libgen.h> |
14 | #include "build-id.h" | ||
14 | 15 | ||
15 | #ifdef LIBELF_SUPPORT | 16 | #ifdef LIBELF_SUPPORT |
16 | #include <libelf.h> | 17 | #include <libelf.h> |
@@ -18,6 +19,8 @@ | |||
18 | #include <elf.h> | 19 | #include <elf.h> |
19 | #endif | 20 | #endif |
20 | 21 | ||
22 | #include "dso.h" | ||
23 | |||
21 | #ifdef HAVE_CPLUS_DEMANGLE | 24 | #ifdef HAVE_CPLUS_DEMANGLE |
22 | extern char *cplus_demangle(const char *, int); | 25 | extern char *cplus_demangle(const char *, int); |
23 | 26 | ||
@@ -39,9 +42,6 @@ static inline char *bfd_demangle(void __maybe_unused *v, | |||
39 | #endif | 42 | #endif |
40 | #endif | 43 | #endif |
41 | 44 | ||
42 | int hex2u64(const char *ptr, u64 *val); | ||
43 | char *strxfrchar(char *s, char from, char to); | ||
44 | |||
45 | /* | 45 | /* |
46 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; | 46 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; |
47 | * for newer versions we can use mmap to reduce memory usage: | 47 | * for newer versions we can use mmap to reduce memory usage: |
@@ -57,8 +57,6 @@ char *strxfrchar(char *s, char from, char to); | |||
57 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ | 57 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ |
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | #define BUILD_ID_SIZE 20 | ||
61 | |||
62 | /** struct symbol - symtab entry | 60 | /** struct symbol - symtab entry |
63 | * | 61 | * |
64 | * @ignore - resolvable but tools ignore it (e.g. idle routines) | 62 | * @ignore - resolvable but tools ignore it (e.g. idle routines) |
@@ -74,6 +72,7 @@ struct symbol { | |||
74 | }; | 72 | }; |
75 | 73 | ||
76 | void symbol__delete(struct symbol *sym); | 74 | void symbol__delete(struct symbol *sym); |
75 | void symbols__delete(struct rb_root *symbols); | ||
77 | 76 | ||
78 | static inline size_t symbol__size(const struct symbol *sym) | 77 | static inline size_t symbol__size(const struct symbol *sym) |
79 | { | 78 | { |
@@ -164,70 +163,6 @@ struct addr_location { | |||
164 | s32 cpu; | 163 | s32 cpu; |
165 | }; | 164 | }; |
166 | 165 | ||
167 | enum dso_binary_type { | ||
168 | DSO_BINARY_TYPE__KALLSYMS = 0, | ||
169 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | ||
170 | DSO_BINARY_TYPE__VMLINUX, | ||
171 | DSO_BINARY_TYPE__GUEST_VMLINUX, | ||
172 | DSO_BINARY_TYPE__JAVA_JIT, | ||
173 | DSO_BINARY_TYPE__DEBUGLINK, | ||
174 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | ||
175 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | ||
176 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | ||
177 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | ||
178 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | ||
179 | DSO_BINARY_TYPE__GUEST_KMODULE, | ||
180 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | ||
181 | DSO_BINARY_TYPE__NOT_FOUND, | ||
182 | }; | ||
183 | |||
184 | enum dso_kernel_type { | ||
185 | DSO_TYPE_USER = 0, | ||
186 | DSO_TYPE_KERNEL, | ||
187 | DSO_TYPE_GUEST_KERNEL | ||
188 | }; | ||
189 | |||
190 | enum dso_swap_type { | ||
191 | DSO_SWAP__UNSET, | ||
192 | DSO_SWAP__NO, | ||
193 | DSO_SWAP__YES, | ||
194 | }; | ||
195 | |||
196 | #define DSO__DATA_CACHE_SIZE 4096 | ||
197 | #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) | ||
198 | |||
199 | struct dso_cache { | ||
200 | struct rb_node rb_node; | ||
201 | u64 offset; | ||
202 | u64 size; | ||
203 | char data[0]; | ||
204 | }; | ||
205 | |||
206 | struct dso { | ||
207 | struct list_head node; | ||
208 | struct rb_root symbols[MAP__NR_TYPES]; | ||
209 | struct rb_root symbol_names[MAP__NR_TYPES]; | ||
210 | struct rb_root cache; | ||
211 | enum dso_kernel_type kernel; | ||
212 | enum dso_swap_type needs_swap; | ||
213 | enum dso_binary_type symtab_type; | ||
214 | enum dso_binary_type data_type; | ||
215 | u8 adjust_symbols:1; | ||
216 | u8 has_build_id:1; | ||
217 | u8 hit:1; | ||
218 | u8 annotate_warned:1; | ||
219 | u8 sname_alloc:1; | ||
220 | u8 lname_alloc:1; | ||
221 | u8 sorted_by_name; | ||
222 | u8 loaded; | ||
223 | u8 build_id[BUILD_ID_SIZE]; | ||
224 | const char *short_name; | ||
225 | char *long_name; | ||
226 | u16 long_name_len; | ||
227 | u16 short_name_len; | ||
228 | char name[0]; | ||
229 | }; | ||
230 | |||
231 | struct symsrc { | 166 | struct symsrc { |
232 | char *name; | 167 | char *name; |
233 | int fd; | 168 | int fd; |
@@ -258,47 +193,6 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, | |||
258 | bool symsrc__has_symtab(struct symsrc *ss); | 193 | bool symsrc__has_symtab(struct symsrc *ss); |
259 | bool symsrc__possibly_runtime(struct symsrc *ss); | 194 | bool symsrc__possibly_runtime(struct symsrc *ss); |
260 | 195 | ||
261 | #define DSO__SWAP(dso, type, val) \ | ||
262 | ({ \ | ||
263 | type ____r = val; \ | ||
264 | BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \ | ||
265 | if (dso->needs_swap == DSO_SWAP__YES) { \ | ||
266 | switch (sizeof(____r)) { \ | ||
267 | case 2: \ | ||
268 | ____r = bswap_16(val); \ | ||
269 | break; \ | ||
270 | case 4: \ | ||
271 | ____r = bswap_32(val); \ | ||
272 | break; \ | ||
273 | case 8: \ | ||
274 | ____r = bswap_64(val); \ | ||
275 | break; \ | ||
276 | default: \ | ||
277 | BUG_ON(1); \ | ||
278 | } \ | ||
279 | } \ | ||
280 | ____r; \ | ||
281 | }) | ||
282 | |||
283 | struct dso *dso__new(const char *name); | ||
284 | void dso__delete(struct dso *dso); | ||
285 | |||
286 | int dso__name_len(const struct dso *dso); | ||
287 | |||
288 | bool dso__loaded(const struct dso *dso, enum map_type type); | ||
289 | bool dso__sorted_by_name(const struct dso *dso, enum map_type type); | ||
290 | |||
291 | static inline void dso__set_loaded(struct dso *dso, enum map_type type) | ||
292 | { | ||
293 | dso->loaded |= (1 << type); | ||
294 | } | ||
295 | |||
296 | void dso__sort_by_name(struct dso *dso, enum map_type type); | ||
297 | |||
298 | void dsos__add(struct list_head *head, struct dso *dso); | ||
299 | struct dso *dsos__find(struct list_head *head, const char *name); | ||
300 | struct dso *__dsos__findnew(struct list_head *head, const char *name); | ||
301 | |||
302 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter); | 196 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter); |
303 | int dso__load_vmlinux(struct dso *dso, struct map *map, | 197 | int dso__load_vmlinux(struct dso *dso, struct map *map, |
304 | const char *vmlinux, symbol_filter_t filter); | 198 | const char *vmlinux, symbol_filter_t filter); |
@@ -311,25 +205,12 @@ int machine__load_kallsyms(struct machine *machine, const char *filename, | |||
311 | int machine__load_vmlinux_path(struct machine *machine, enum map_type type, | 205 | int machine__load_vmlinux_path(struct machine *machine, enum map_type type, |
312 | symbol_filter_t filter); | 206 | symbol_filter_t filter); |
313 | 207 | ||
314 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); | ||
315 | |||
316 | size_t machine__fprintf_dsos_buildid(struct machine *machine, | 208 | size_t machine__fprintf_dsos_buildid(struct machine *machine, |
317 | FILE *fp, bool with_hits); | 209 | FILE *fp, bool with_hits); |
318 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); | 210 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); |
319 | size_t machines__fprintf_dsos_buildid(struct rb_root *machines, | 211 | size_t machines__fprintf_dsos_buildid(struct rb_root *machines, |
320 | FILE *fp, bool with_hits); | 212 | FILE *fp, bool with_hits); |
321 | size_t dso__fprintf_buildid(struct dso *dso, FILE *fp); | 213 | |
322 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | ||
323 | enum map_type type, FILE *fp); | ||
324 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); | ||
325 | |||
326 | char dso__symtab_origin(const struct dso *dso); | ||
327 | void dso__set_long_name(struct dso *dso, char *name); | ||
328 | void dso__set_build_id(struct dso *dso, void *build_id); | ||
329 | bool dso__build_id_equal(const struct dso *dso, u8 *build_id); | ||
330 | void dso__read_running_kernel_build_id(struct dso *dso, | ||
331 | struct machine *machine); | ||
332 | struct map *dso__new_map(const char *name); | ||
333 | struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, | 214 | struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, |
334 | u64 addr); | 215 | u64 addr); |
335 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, | 216 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, |
@@ -337,8 +218,6 @@ struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, | |||
337 | 218 | ||
338 | int filename__read_build_id(const char *filename, void *bf, size_t size); | 219 | int filename__read_build_id(const char *filename, void *bf, size_t size); |
339 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); | 220 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); |
340 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); | ||
341 | int build_id__sprintf(const u8 *build_id, int len, char *bf); | ||
342 | int kallsyms__parse(const char *filename, void *arg, | 221 | int kallsyms__parse(const char *filename, void *arg, |
343 | int (*process_symbol)(void *arg, const char *name, | 222 | int (*process_symbol)(void *arg, const char *name, |
344 | char type, u64 start)); | 223 | char type, u64 start)); |
@@ -360,19 +239,11 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name); | |||
360 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, | 239 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, |
361 | const struct addr_location *al, FILE *fp); | 240 | const struct addr_location *al, FILE *fp); |
362 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); | 241 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); |
242 | size_t symbol__fprintf(struct symbol *sym, FILE *fp); | ||
363 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); | 243 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |
364 | 244 | ||
365 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); | 245 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
366 | 246 | ||
367 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, | ||
368 | char *root_dir, char *file, size_t size); | ||
369 | |||
370 | int dso__data_fd(struct dso *dso, struct machine *machine); | ||
371 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | ||
372 | u64 offset, u8 *data, ssize_t size); | ||
373 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | ||
374 | struct machine *machine, u64 addr, | ||
375 | u8 *data, ssize_t size); | ||
376 | int dso__test_data(void); | 247 | int dso__test_data(void); |
377 | int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, | 248 | int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, |
378 | struct symsrc *runtime_ss, symbol_filter_t filter, | 249 | struct symsrc *runtime_ss, symbol_filter_t filter, |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 637b5cc54362..5906e8426cc7 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -166,6 +166,39 @@ size_t hex_width(u64 v) | |||
166 | return n; | 166 | return n; |
167 | } | 167 | } |
168 | 168 | ||
169 | static int hex(char ch) | ||
170 | { | ||
171 | if ((ch >= '0') && (ch <= '9')) | ||
172 | return ch - '0'; | ||
173 | if ((ch >= 'a') && (ch <= 'f')) | ||
174 | return ch - 'a' + 10; | ||
175 | if ((ch >= 'A') && (ch <= 'F')) | ||
176 | return ch - 'A' + 10; | ||
177 | return -1; | ||
178 | } | ||
179 | |||
180 | /* | ||
181 | * While we find nice hex chars, build a long_val. | ||
182 | * Return number of chars processed. | ||
183 | */ | ||
184 | int hex2u64(const char *ptr, u64 *long_val) | ||
185 | { | ||
186 | const char *p = ptr; | ||
187 | *long_val = 0; | ||
188 | |||
189 | while (*p) { | ||
190 | const int hex_val = hex(*p); | ||
191 | |||
192 | if (hex_val < 0) | ||
193 | break; | ||
194 | |||
195 | *long_val = (*long_val << 4) | hex_val; | ||
196 | p++; | ||
197 | } | ||
198 | |||
199 | return p - ptr; | ||
200 | } | ||
201 | |||
169 | /* Obtain a backtrace and print it to stdout. */ | 202 | /* Obtain a backtrace and print it to stdout. */ |
170 | #ifdef BACKTRACE_SUPPORT | 203 | #ifdef BACKTRACE_SUPPORT |
171 | void dump_stack(void) | 204 | void dump_stack(void) |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0d85209db8f1..c2330918110c 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -240,6 +240,7 @@ void argv_free(char **argv); | |||
240 | bool strglobmatch(const char *str, const char *pat); | 240 | bool strglobmatch(const char *str, const char *pat); |
241 | bool strlazymatch(const char *str, const char *pat); | 241 | bool strlazymatch(const char *str, const char *pat); |
242 | int strtailcmp(const char *s1, const char *s2); | 242 | int strtailcmp(const char *s1, const char *s2); |
243 | char *strxfrchar(char *s, char from, char to); | ||
243 | unsigned long convert_unit(unsigned long value, char *unit); | 244 | unsigned long convert_unit(unsigned long value, char *unit); |
244 | int readn(int fd, void *buf, size_t size); | 245 | int readn(int fd, void *buf, size_t size); |
245 | 246 | ||
@@ -262,6 +263,7 @@ bool is_power_of_2(unsigned long n) | |||
262 | } | 263 | } |
263 | 264 | ||
264 | size_t hex_width(u64 v); | 265 | size_t hex_width(u64 v); |
266 | int hex2u64(const char *ptr, u64 *val); | ||
265 | 267 | ||
266 | char *rtrim(char *s); | 268 | char *rtrim(char *s); |
267 | 269 | ||