blob: 582b5d344aa36d484d55c07a98c845a68e41c808 [file] [log] [blame]
Jiri Olsacdd059d2012-10-27 23:18:32 +02001#include "symbol.h"
2#include "dso.h"
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -03003#include "machine.h"
Jiri Olsacdd059d2012-10-27 23:18:32 +02004#include "util.h"
5#include "debug.h"
6
7char dso__symtab_origin(const struct dso *dso)
8{
9 static const char origin[] = {
Ricardo Ribalda Delgado9cd00942013-09-18 15:56:14 +020010 [DSO_BINARY_TYPE__KALLSYMS] = 'k',
11 [DSO_BINARY_TYPE__VMLINUX] = 'v',
12 [DSO_BINARY_TYPE__JAVA_JIT] = 'j',
13 [DSO_BINARY_TYPE__DEBUGLINK] = 'l',
14 [DSO_BINARY_TYPE__BUILD_ID_CACHE] = 'B',
15 [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f',
16 [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u',
17 [DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO] = 'o',
18 [DSO_BINARY_TYPE__BUILDID_DEBUGINFO] = 'b',
19 [DSO_BINARY_TYPE__SYSTEM_PATH_DSO] = 'd',
20 [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE] = 'K',
21 [DSO_BINARY_TYPE__GUEST_KALLSYMS] = 'g',
22 [DSO_BINARY_TYPE__GUEST_KMODULE] = 'G',
23 [DSO_BINARY_TYPE__GUEST_VMLINUX] = 'V',
Jiri Olsacdd059d2012-10-27 23:18:32 +020024 };
25
26 if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND)
27 return '!';
28 return origin[dso->symtab_type];
29}
30
Arnaldo Carvalho de Melo33449962013-12-10 15:46:29 -030031int dso__binary_type_file(const struct dso *dso, enum dso_binary_type type,
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030032 char *root_dir, char *filename, size_t size)
Jiri Olsacdd059d2012-10-27 23:18:32 +020033{
34 char build_id_hex[BUILD_ID_SIZE * 2 + 1];
35 int ret = 0;
36
37 switch (type) {
38 case DSO_BINARY_TYPE__DEBUGLINK: {
39 char *debuglink;
40
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030041 strncpy(filename, dso->long_name, size);
42 debuglink = filename + dso->long_name_len;
43 while (debuglink != filename && *debuglink != '/')
Jiri Olsacdd059d2012-10-27 23:18:32 +020044 debuglink--;
45 if (*debuglink == '/')
46 debuglink++;
47 filename__read_debuglink(dso->long_name, debuglink,
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030048 size - (debuglink - filename));
Jiri Olsacdd059d2012-10-27 23:18:32 +020049 }
50 break;
51 case DSO_BINARY_TYPE__BUILD_ID_CACHE:
52 /* skip the locally configured cache if a symfs is given */
53 if (symbol_conf.symfs[0] ||
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030054 (dso__build_id_filename(dso, filename, size) == NULL))
Jiri Olsacdd059d2012-10-27 23:18:32 +020055 ret = -1;
56 break;
57
58 case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030059 snprintf(filename, size, "%s/usr/lib/debug%s.debug",
Jiri Olsacdd059d2012-10-27 23:18:32 +020060 symbol_conf.symfs, dso->long_name);
61 break;
62
63 case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030064 snprintf(filename, size, "%s/usr/lib/debug%s",
Jiri Olsacdd059d2012-10-27 23:18:32 +020065 symbol_conf.symfs, dso->long_name);
66 break;
67
Ricardo Ribalda Delgado9cd00942013-09-18 15:56:14 +020068 case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
69 {
Arnaldo Carvalho de Melobf4414a2013-12-10 15:19:23 -030070 const char *last_slash;
Ricardo Ribalda Delgado9cd00942013-09-18 15:56:14 +020071 size_t len;
72 size_t dir_size;
73
74 last_slash = dso->long_name + dso->long_name_len;
75 while (last_slash != dso->long_name && *last_slash != '/')
76 last_slash--;
77
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030078 len = scnprintf(filename, size, "%s", symbol_conf.symfs);
Ricardo Ribalda Delgado9cd00942013-09-18 15:56:14 +020079 dir_size = last_slash - dso->long_name + 2;
80 if (dir_size > (size - len)) {
81 ret = -1;
82 break;
83 }
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030084 len += scnprintf(filename + len, dir_size, "%s", dso->long_name);
85 len += scnprintf(filename + len , size - len, ".debug%s",
Ricardo Ribalda Delgado9cd00942013-09-18 15:56:14 +020086 last_slash);
87 break;
88 }
89
Jiri Olsacdd059d2012-10-27 23:18:32 +020090 case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
91 if (!dso->has_build_id) {
92 ret = -1;
93 break;
94 }
95
96 build_id__sprintf(dso->build_id,
97 sizeof(dso->build_id),
98 build_id_hex);
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -030099 snprintf(filename, size,
Jiri Olsacdd059d2012-10-27 23:18:32 +0200100 "%s/usr/lib/debug/.build-id/%.2s/%s.debug",
101 symbol_conf.symfs, build_id_hex, build_id_hex + 2);
102 break;
103
Adrian Hunter39b12f782013-08-07 14:38:47 +0300104 case DSO_BINARY_TYPE__VMLINUX:
105 case DSO_BINARY_TYPE__GUEST_VMLINUX:
Jiri Olsacdd059d2012-10-27 23:18:32 +0200106 case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -0300107 snprintf(filename, size, "%s%s",
Jiri Olsacdd059d2012-10-27 23:18:32 +0200108 symbol_conf.symfs, dso->long_name);
109 break;
110
111 case DSO_BINARY_TYPE__GUEST_KMODULE:
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -0300112 snprintf(filename, size, "%s%s%s", symbol_conf.symfs,
Jiri Olsacdd059d2012-10-27 23:18:32 +0200113 root_dir, dso->long_name);
114 break;
115
116 case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -0300117 snprintf(filename, size, "%s%s", symbol_conf.symfs,
Jiri Olsacdd059d2012-10-27 23:18:32 +0200118 dso->long_name);
119 break;
120
Adrian Hunter8e0cf962013-08-07 14:38:51 +0300121 case DSO_BINARY_TYPE__KCORE:
122 case DSO_BINARY_TYPE__GUEST_KCORE:
Arnaldo Carvalho de Melo7d2a5122013-12-10 16:02:50 -0300123 snprintf(filename, size, "%s", dso->long_name);
Adrian Hunter8e0cf962013-08-07 14:38:51 +0300124 break;
125
Jiri Olsacdd059d2012-10-27 23:18:32 +0200126 default:
127 case DSO_BINARY_TYPE__KALLSYMS:
Jiri Olsacdd059d2012-10-27 23:18:32 +0200128 case DSO_BINARY_TYPE__GUEST_KALLSYMS:
Jiri Olsacdd059d2012-10-27 23:18:32 +0200129 case DSO_BINARY_TYPE__JAVA_JIT:
130 case DSO_BINARY_TYPE__NOT_FOUND:
131 ret = -1;
132 break;
133 }
134
135 return ret;
136}
137
138static int open_dso(struct dso *dso, struct machine *machine)
139{
140 char *root_dir = (char *) "";
141 char *name;
142 int fd;
143
144 name = malloc(PATH_MAX);
145 if (!name)
146 return -ENOMEM;
147
148 if (machine)
149 root_dir = machine->root_dir;
150
151 if (dso__binary_type_file(dso, dso->data_type,
152 root_dir, name, PATH_MAX)) {
153 free(name);
154 return -EINVAL;
155 }
156
157 fd = open(name, O_RDONLY);
158 free(name);
159 return fd;
160}
161
162int dso__data_fd(struct dso *dso, struct machine *machine)
163{
164 static enum dso_binary_type binary_type_data[] = {
165 DSO_BINARY_TYPE__BUILD_ID_CACHE,
166 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
167 DSO_BINARY_TYPE__NOT_FOUND,
168 };
169 int i = 0;
170
171 if (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND)
172 return open_dso(dso, machine);
173
174 do {
175 int fd;
176
177 dso->data_type = binary_type_data[i++];
178
179 fd = open_dso(dso, machine);
180 if (fd >= 0)
181 return fd;
182
183 } while (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND);
184
185 return -EINVAL;
186}
187
188static void
189dso_cache__free(struct rb_root *root)
190{
191 struct rb_node *next = rb_first(root);
192
193 while (next) {
194 struct dso_cache *cache;
195
196 cache = rb_entry(next, struct dso_cache, rb_node);
197 next = rb_next(&cache->rb_node);
198 rb_erase(&cache->rb_node, root);
199 free(cache);
200 }
201}
202
Arnaldo Carvalho de Melo33449962013-12-10 15:46:29 -0300203static struct dso_cache *dso_cache__find(const struct rb_root *root, u64 offset)
Jiri Olsacdd059d2012-10-27 23:18:32 +0200204{
Arnaldo Carvalho de Melo33449962013-12-10 15:46:29 -0300205 struct rb_node * const *p = &root->rb_node;
206 const struct rb_node *parent = NULL;
Jiri Olsacdd059d2012-10-27 23:18:32 +0200207 struct dso_cache *cache;
208
209 while (*p != NULL) {
210 u64 end;
211
212 parent = *p;
213 cache = rb_entry(parent, struct dso_cache, rb_node);
214 end = cache->offset + DSO__DATA_CACHE_SIZE;
215
216 if (offset < cache->offset)
217 p = &(*p)->rb_left;
218 else if (offset >= end)
219 p = &(*p)->rb_right;
220 else
221 return cache;
222 }
223 return NULL;
224}
225
226static void
227dso_cache__insert(struct rb_root *root, struct dso_cache *new)
228{
229 struct rb_node **p = &root->rb_node;
230 struct rb_node *parent = NULL;
231 struct dso_cache *cache;
232 u64 offset = new->offset;
233
234 while (*p != NULL) {
235 u64 end;
236
237 parent = *p;
238 cache = rb_entry(parent, struct dso_cache, rb_node);
239 end = cache->offset + DSO__DATA_CACHE_SIZE;
240
241 if (offset < cache->offset)
242 p = &(*p)->rb_left;
243 else if (offset >= end)
244 p = &(*p)->rb_right;
245 }
246
247 rb_link_node(&new->rb_node, parent, p);
248 rb_insert_color(&new->rb_node, root);
249}
250
251static ssize_t
252dso_cache__memcpy(struct dso_cache *cache, u64 offset,
253 u8 *data, u64 size)
254{
255 u64 cache_offset = offset - cache->offset;
256 u64 cache_size = min(cache->size - cache_offset, size);
257
258 memcpy(data, cache->data + cache_offset, cache_size);
259 return cache_size;
260}
261
262static ssize_t
263dso_cache__read(struct dso *dso, struct machine *machine,
264 u64 offset, u8 *data, ssize_t size)
265{
266 struct dso_cache *cache;
267 ssize_t ret;
268 int fd;
269
270 fd = dso__data_fd(dso, machine);
271 if (fd < 0)
272 return -1;
273
274 do {
275 u64 cache_offset;
276
277 ret = -ENOMEM;
278
279 cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE);
280 if (!cache)
281 break;
282
283 cache_offset = offset & DSO__DATA_CACHE_MASK;
284 ret = -EINVAL;
285
286 if (-1 == lseek(fd, cache_offset, SEEK_SET))
287 break;
288
289 ret = read(fd, cache->data, DSO__DATA_CACHE_SIZE);
290 if (ret <= 0)
291 break;
292
293 cache->offset = cache_offset;
294 cache->size = ret;
295 dso_cache__insert(&dso->cache, cache);
296
297 ret = dso_cache__memcpy(cache, offset, data, size);
298
299 } while (0);
300
301 if (ret <= 0)
302 free(cache);
303
304 close(fd);
305 return ret;
306}
307
308static ssize_t dso_cache_read(struct dso *dso, struct machine *machine,
309 u64 offset, u8 *data, ssize_t size)
310{
311 struct dso_cache *cache;
312
313 cache = dso_cache__find(&dso->cache, offset);
314 if (cache)
315 return dso_cache__memcpy(cache, offset, data, size);
316 else
317 return dso_cache__read(dso, machine, offset, data, size);
318}
319
320ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
321 u64 offset, u8 *data, ssize_t size)
322{
323 ssize_t r = 0;
324 u8 *p = data;
325
326 do {
327 ssize_t ret;
328
329 ret = dso_cache_read(dso, machine, offset, p, size);
330 if (ret < 0)
331 return ret;
332
333 /* Reached EOF, return what we have. */
334 if (!ret)
335 break;
336
337 BUG_ON(ret > size);
338
339 r += ret;
340 p += ret;
341 offset += ret;
342 size -= ret;
343
344 } while (size);
345
346 return r;
347}
348
349ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
350 struct machine *machine, u64 addr,
351 u8 *data, ssize_t size)
352{
353 u64 offset = map->map_ip(map, addr);
354 return dso__data_read_offset(dso, machine, offset, data, size);
355}
356
357struct map *dso__new_map(const char *name)
358{
359 struct map *map = NULL;
360 struct dso *dso = dso__new(name);
361
362 if (dso)
363 map = map__new2(0, dso, MAP__FUNCTION);
364
365 return map;
366}
367
368struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
369 const char *short_name, int dso_type)
370{
371 /*
372 * The kernel dso could be created by build_id processing.
373 */
374 struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name);
375
376 /*
377 * We need to run this in all cases, since during the build_id
378 * processing we had no idea this was the kernel dso.
379 */
380 if (dso != NULL) {
Adrian Hunter58a98c92013-12-10 11:11:46 -0300381 dso__set_short_name(dso, short_name, false);
Jiri Olsacdd059d2012-10-27 23:18:32 +0200382 dso->kernel = dso_type;
383 }
384
385 return dso;
386}
387
Arnaldo Carvalho de Melobf4414a2013-12-10 15:19:23 -0300388void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated)
Jiri Olsacdd059d2012-10-27 23:18:32 +0200389{
390 if (name == NULL)
391 return;
Arnaldo Carvalho de Melo7e155d42013-12-10 15:08:44 -0300392
393 if (dso->long_name_allocated)
Arnaldo Carvalho de Melobf4414a2013-12-10 15:19:23 -0300394 free((char *)dso->long_name);
Arnaldo Carvalho de Melo7e155d42013-12-10 15:08:44 -0300395
396 dso->long_name = name;
397 dso->long_name_len = strlen(name);
398 dso->long_name_allocated = name_allocated;
Jiri Olsacdd059d2012-10-27 23:18:32 +0200399}
400
Adrian Hunter58a98c92013-12-10 11:11:46 -0300401void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
Jiri Olsacdd059d2012-10-27 23:18:32 +0200402{
403 if (name == NULL)
404 return;
Adrian Hunter58a98c92013-12-10 11:11:46 -0300405
406 if (dso->short_name_allocated)
407 free((char *)dso->short_name);
408
409 dso->short_name = name;
410 dso->short_name_len = strlen(name);
411 dso->short_name_allocated = name_allocated;
Jiri Olsacdd059d2012-10-27 23:18:32 +0200412}
413
414static void dso__set_basename(struct dso *dso)
415{
Arnaldo Carvalho de Melobf4414a2013-12-10 15:19:23 -0300416 dso__set_short_name(dso, basename((char *)dso->long_name), false);
Jiri Olsacdd059d2012-10-27 23:18:32 +0200417}
418
419int dso__name_len(const struct dso *dso)
420{
421 if (!dso)
422 return strlen("[unknown]");
423 if (verbose)
424 return dso->long_name_len;
425
426 return dso->short_name_len;
427}
428
429bool dso__loaded(const struct dso *dso, enum map_type type)
430{
431 return dso->loaded & (1 << type);
432}
433
434bool dso__sorted_by_name(const struct dso *dso, enum map_type type)
435{
436 return dso->sorted_by_name & (1 << type);
437}
438
439void dso__set_sorted_by_name(struct dso *dso, enum map_type type)
440{
441 dso->sorted_by_name |= (1 << type);
442}
443
444struct dso *dso__new(const char *name)
445{
446 struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1);
447
448 if (dso != NULL) {
449 int i;
450 strcpy(dso->name, name);
Arnaldo Carvalho de Melo7e155d42013-12-10 15:08:44 -0300451 dso__set_long_name(dso, dso->name, false);
Adrian Hunter58a98c92013-12-10 11:11:46 -0300452 dso__set_short_name(dso, dso->name, false);
Jiri Olsacdd059d2012-10-27 23:18:32 +0200453 for (i = 0; i < MAP__NR_TYPES; ++i)
454 dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
455 dso->cache = RB_ROOT;
456 dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
457 dso->data_type = DSO_BINARY_TYPE__NOT_FOUND;
458 dso->loaded = 0;
Adrian Hunter0131c4e2013-08-07 14:38:50 +0300459 dso->rel = 0;
Jiri Olsacdd059d2012-10-27 23:18:32 +0200460 dso->sorted_by_name = 0;
461 dso->has_build_id = 0;
Namhyung Kim2cc9d0e2013-09-11 14:09:31 +0900462 dso->has_srcline = 1;
Adrian Hunter906049c82013-12-03 09:23:10 +0200463 dso->a2l_fails = 1;
Jiri Olsacdd059d2012-10-27 23:18:32 +0200464 dso->kernel = DSO_TYPE_USER;
465 dso->needs_swap = DSO_SWAP__UNSET;
466 INIT_LIST_HEAD(&dso->node);
467 }
468
469 return dso;
470}
471
472void dso__delete(struct dso *dso)
473{
474 int i;
475 for (i = 0; i < MAP__NR_TYPES; ++i)
476 symbols__delete(&dso->symbols[i]);
Arnaldo Carvalho de Meloee021d42013-12-10 15:26:55 -0300477
478 if (dso->short_name_allocated) {
Jiri Olsacdd059d2012-10-27 23:18:32 +0200479 free((char *)dso->short_name);
Arnaldo Carvalho de Meloee021d42013-12-10 15:26:55 -0300480 dso->short_name = NULL;
481 dso->short_name_allocated = false;
482 }
483
484 if (dso->long_name_allocated) {
Arnaldo Carvalho de Melobf4414a2013-12-10 15:19:23 -0300485 free((char *)dso->long_name);
Arnaldo Carvalho de Meloee021d42013-12-10 15:26:55 -0300486 dso->long_name = NULL;
487 dso->long_name_allocated = false;
488 }
489
Jiri Olsacdd059d2012-10-27 23:18:32 +0200490 dso_cache__free(&dso->cache);
Adrian Hunter454ff002013-12-03 09:23:07 +0200491 dso__free_a2l(dso);
Adrian Hunter0058aef2013-12-03 09:23:08 +0200492 free(dso->symsrc_filename);
Arnaldo Carvalho de Meloee021d42013-12-10 15:26:55 -0300493 dso->symsrc_filename = NULL;
Jiri Olsacdd059d2012-10-27 23:18:32 +0200494 free(dso);
495}
496
497void dso__set_build_id(struct dso *dso, void *build_id)
498{
499 memcpy(dso->build_id, build_id, sizeof(dso->build_id));
500 dso->has_build_id = 1;
501}
502
503bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
504{
505 return memcmp(dso->build_id, build_id, sizeof(dso->build_id)) == 0;
506}
507
508void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
509{
510 char path[PATH_MAX];
511
512 if (machine__is_default_guest(machine))
513 return;
514 sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
515 if (sysfs__read_build_id(path, dso->build_id,
516 sizeof(dso->build_id)) == 0)
517 dso->has_build_id = true;
518}
519
520int dso__kernel_module_get_build_id(struct dso *dso,
521 const char *root_dir)
522{
523 char filename[PATH_MAX];
524 /*
525 * kernel module short names are of the form "[module]" and
526 * we need just "module" here.
527 */
528 const char *name = dso->short_name + 1;
529
530 snprintf(filename, sizeof(filename),
531 "%s/sys/module/%.*s/notes/.note.gnu.build-id",
532 root_dir, (int)strlen(name) - 1, name);
533
534 if (sysfs__read_build_id(filename, dso->build_id,
535 sizeof(dso->build_id)) == 0)
536 dso->has_build_id = true;
537
538 return 0;
539}
540
541bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
542{
543 bool have_build_id = false;
544 struct dso *pos;
545
546 list_for_each_entry(pos, head, node) {
547 if (with_hits && !pos->hit)
548 continue;
549 if (pos->has_build_id) {
550 have_build_id = true;
551 continue;
552 }
553 if (filename__read_build_id(pos->long_name, pos->build_id,
554 sizeof(pos->build_id)) > 0) {
555 have_build_id = true;
556 pos->has_build_id = true;
557 }
558 }
559
560 return have_build_id;
561}
562
563void dsos__add(struct list_head *head, struct dso *dso)
564{
565 list_add_tail(&dso->node, head);
566}
567
Arnaldo Carvalho de Melo33449962013-12-10 15:46:29 -0300568struct dso *dsos__find(const struct list_head *head, const char *name, bool cmp_short)
Jiri Olsacdd059d2012-10-27 23:18:32 +0200569{
570 struct dso *pos;
571
Waiman Longf9ceffb2013-05-09 10:42:48 -0400572 if (cmp_short) {
573 list_for_each_entry(pos, head, node)
574 if (strcmp(pos->short_name, name) == 0)
575 return pos;
576 return NULL;
577 }
Jiri Olsacdd059d2012-10-27 23:18:32 +0200578 list_for_each_entry(pos, head, node)
579 if (strcmp(pos->long_name, name) == 0)
580 return pos;
581 return NULL;
582}
583
584struct dso *__dsos__findnew(struct list_head *head, const char *name)
585{
Waiman Longf9ceffb2013-05-09 10:42:48 -0400586 struct dso *dso = dsos__find(head, name, false);
Jiri Olsacdd059d2012-10-27 23:18:32 +0200587
588 if (!dso) {
589 dso = dso__new(name);
590 if (dso != NULL) {
591 dsos__add(head, dso);
592 dso__set_basename(dso);
593 }
594 }
595
596 return dso;
597}
598
599size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300600 bool (skip)(struct dso *dso, int parm), int parm)
Jiri Olsacdd059d2012-10-27 23:18:32 +0200601{
602 struct dso *pos;
603 size_t ret = 0;
604
605 list_for_each_entry(pos, head, node) {
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300606 if (skip && skip(pos, parm))
Jiri Olsacdd059d2012-10-27 23:18:32 +0200607 continue;
608 ret += dso__fprintf_buildid(pos, fp);
609 ret += fprintf(fp, " %s\n", pos->long_name);
610 }
611 return ret;
612}
613
614size_t __dsos__fprintf(struct list_head *head, FILE *fp)
615{
616 struct dso *pos;
617 size_t ret = 0;
618
619 list_for_each_entry(pos, head, node) {
620 int i;
621 for (i = 0; i < MAP__NR_TYPES; ++i)
622 ret += dso__fprintf(pos, i, fp);
623 }
624
625 return ret;
626}
627
628size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
629{
630 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
631
632 build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
633 return fprintf(fp, "%s", sbuild_id);
634}
635
636size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp)
637{
638 struct rb_node *nd;
639 size_t ret = fprintf(fp, "dso: %s (", dso->short_name);
640
641 if (dso->short_name != dso->long_name)
642 ret += fprintf(fp, "%s, ", dso->long_name);
643 ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type],
Stephane Eranian919d5902012-11-20 10:51:02 +0100644 dso__loaded(dso, type) ? "" : "NOT ");
Jiri Olsacdd059d2012-10-27 23:18:32 +0200645 ret += dso__fprintf_buildid(dso, fp);
646 ret += fprintf(fp, ")\n");
647 for (nd = rb_first(&dso->symbols[type]); nd; nd = rb_next(nd)) {
648 struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
649 ret += symbol__fprintf(pos, fp);
650 }
651
652 return ret;
653}