3 #include <sys/resource.h>
10 char dso__symtab_origin(const struct dso *dso)
12 static const char origin[] = {
13 [DSO_BINARY_TYPE__KALLSYMS] = 'k',
14 [DSO_BINARY_TYPE__VMLINUX] = 'v',
15 [DSO_BINARY_TYPE__JAVA_JIT] = 'j',
16 [DSO_BINARY_TYPE__DEBUGLINK] = 'l',
17 [DSO_BINARY_TYPE__BUILD_ID_CACHE] = 'B',
18 [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f',
19 [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u',
20 [DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO] = 'o',
21 [DSO_BINARY_TYPE__BUILDID_DEBUGINFO] = 'b',
22 [DSO_BINARY_TYPE__SYSTEM_PATH_DSO] = 'd',
23 [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE] = 'K',
24 [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP] = 'm',
25 [DSO_BINARY_TYPE__GUEST_KALLSYMS] = 'g',
26 [DSO_BINARY_TYPE__GUEST_KMODULE] = 'G',
27 [DSO_BINARY_TYPE__GUEST_KMODULE_COMP] = 'M',
28 [DSO_BINARY_TYPE__GUEST_VMLINUX] = 'V',
31 if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND)
33 return origin[dso->symtab_type];
36 int dso__read_binary_type_filename(const struct dso *dso,
37 enum dso_binary_type type,
38 char *root_dir, char *filename, size_t size)
40 char build_id_hex[BUILD_ID_SIZE * 2 + 1];
45 case DSO_BINARY_TYPE__DEBUGLINK: {
48 len = __symbol__join_symfs(filename, size, dso->long_name);
49 debuglink = filename + len;
50 while (debuglink != filename && *debuglink != '/')
52 if (*debuglink == '/')
54 ret = filename__read_debuglink(filename, debuglink,
55 size - (debuglink - filename));
58 case DSO_BINARY_TYPE__BUILD_ID_CACHE:
59 /* skip the locally configured cache if a symfs is given */
60 if (symbol_conf.symfs[0] ||
61 (dso__build_id_filename(dso, filename, size) == NULL))
65 case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
66 len = __symbol__join_symfs(filename, size, "/usr/lib/debug");
67 snprintf(filename + len, size - len, "%s.debug", dso->long_name);
70 case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
71 len = __symbol__join_symfs(filename, size, "/usr/lib/debug");
72 snprintf(filename + len, size - len, "%s", dso->long_name);
75 case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
77 const char *last_slash;
80 last_slash = dso->long_name + dso->long_name_len;
81 while (last_slash != dso->long_name && *last_slash != '/')
84 len = __symbol__join_symfs(filename, size, "");
85 dir_size = last_slash - dso->long_name + 2;
86 if (dir_size > (size - len)) {
90 len += scnprintf(filename + len, dir_size, "%s", dso->long_name);
91 len += scnprintf(filename + len , size - len, ".debug%s",
96 case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
97 if (!dso->has_build_id) {
102 build_id__sprintf(dso->build_id,
103 sizeof(dso->build_id),
105 len = __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/");
106 snprintf(filename + len, size - len, "%.2s/%s.debug",
107 build_id_hex, build_id_hex + 2);
110 case DSO_BINARY_TYPE__VMLINUX:
111 case DSO_BINARY_TYPE__GUEST_VMLINUX:
112 case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
113 __symbol__join_symfs(filename, size, dso->long_name);
116 case DSO_BINARY_TYPE__GUEST_KMODULE:
117 case DSO_BINARY_TYPE__GUEST_KMODULE_COMP:
118 path__join3(filename, size, symbol_conf.symfs,
119 root_dir, dso->long_name);
122 case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
123 case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP:
124 __symbol__join_symfs(filename, size, dso->long_name);
127 case DSO_BINARY_TYPE__KCORE:
128 case DSO_BINARY_TYPE__GUEST_KCORE:
129 snprintf(filename, size, "%s", dso->long_name);
133 case DSO_BINARY_TYPE__KALLSYMS:
134 case DSO_BINARY_TYPE__GUEST_KALLSYMS:
135 case DSO_BINARY_TYPE__JAVA_JIT:
136 case DSO_BINARY_TYPE__NOT_FOUND:
144 static const struct {
146 int (*decompress)(const char *input, int output);
148 #ifdef HAVE_ZLIB_SUPPORT
149 { "gz", gzip_decompress_to_file },
151 #ifdef HAVE_LZMA_SUPPORT
152 { "xz", lzma_decompress_to_file },
157 bool is_supported_compression(const char *ext)
161 for (i = 0; compressions[i].fmt; i++) {
162 if (!strcmp(ext, compressions[i].fmt))
168 bool is_kernel_module(const char *pathname)
172 if (kmod_path__parse(&m, pathname))
178 bool decompress_to_file(const char *ext, const char *filename, int output_fd)
182 for (i = 0; compressions[i].fmt; i++) {
183 if (!strcmp(ext, compressions[i].fmt))
184 return !compressions[i].decompress(filename,
190 bool dso__needs_decompress(struct dso *dso)
192 return dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
193 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
197 * Parses kernel module specified in @path and updates
200 * @comp - true if @path contains supported compression suffix,
202 * @kmod - true if @path contains '.ko' suffix in right position,
204 * @name - if (@alloc_name && @kmod) is true, it contains strdup-ed base name
205 * of the kernel module without suffixes, otherwise strudup-ed
207 * @ext - if (@alloc_ext && @comp) is true, it contains strdup-ed string
208 * the compression suffix
210 * Returns 0 if there's no strdup error, -ENOMEM otherwise.
212 int __kmod_path__parse(struct kmod_path *m, const char *path,
213 bool alloc_name, bool alloc_ext)
215 const char *name = strrchr(path, '/');
216 const char *ext = strrchr(path, '.');
218 memset(m, 0x0, sizeof(*m));
219 name = name ? name + 1 : path;
221 /* No extension, just return name. */
224 m->name = strdup(name);
225 return m->name ? 0 : -ENOMEM;
230 if (is_supported_compression(ext + 1)) {
235 /* Check .ko extension only if there's enough name left. */
237 m->kmod = !strncmp(ext, ".ko", 3);
241 if (asprintf(&m->name, "[%.*s]", (int) (ext - name), name) == -1)
244 if (asprintf(&m->name, "%s", name) == -1)
248 strxfrchar(m->name, '-', '_');
251 if (alloc_ext && m->comp) {
252 m->ext = strdup(ext + 4);
254 free((void *) m->name);
263 * Global list of open DSOs and the counter.
265 static LIST_HEAD(dso__data_open);
266 static long dso__data_open_cnt;
268 static void dso__list_add(struct dso *dso)
270 list_add_tail(&dso->data.open_entry, &dso__data_open);
271 dso__data_open_cnt++;
274 static void dso__list_del(struct dso *dso)
276 list_del(&dso->data.open_entry);
277 WARN_ONCE(dso__data_open_cnt <= 0,
278 "DSO data fd counter out of bounds.");
279 dso__data_open_cnt--;
282 static void close_first_dso(void);
284 static int do_open(char *name)
287 char sbuf[STRERR_BUFSIZE];
290 fd = open(name, O_RDONLY);
294 pr_debug("dso open failed: %s\n",
295 strerror_r(errno, sbuf, sizeof(sbuf)));
296 if (!dso__data_open_cnt || errno != EMFILE)
305 static int __open_dso(struct dso *dso, struct machine *machine)
308 char *root_dir = (char *)"";
309 char *name = malloc(PATH_MAX);
315 root_dir = machine->root_dir;
317 if (dso__read_binary_type_filename(dso, dso->binary_type,
318 root_dir, name, PATH_MAX)) {
328 static void check_data_close(void);
331 * dso_close - Open DSO data file
334 * Open @dso's data file descriptor and updates
335 * list/count of open DSO objects.
337 static int open_dso(struct dso *dso, struct machine *machine)
339 int fd = __open_dso(dso, machine);
344 * Check if we crossed the allowed number
345 * of opened DSOs and close one if needed.
353 static void close_data_fd(struct dso *dso)
355 if (dso->data.fd >= 0) {
358 dso->data.file_size = 0;
364 * dso_close - Close DSO data file
367 * Close @dso's data file descriptor and updates
368 * list/count of open DSO objects.
370 static void close_dso(struct dso *dso)
375 static void close_first_dso(void)
379 dso = list_first_entry(&dso__data_open, struct dso, data.open_entry);
383 static rlim_t get_fd_limit(void)
388 /* Allow half of the current open fd limit. */
389 if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
390 if (l.rlim_cur == RLIM_INFINITY)
393 limit = l.rlim_cur / 2;
395 pr_err("failed to get fd limit\n");
402 static bool may_cache_fd(void)
407 limit = get_fd_limit();
409 if (limit == RLIM_INFINITY)
412 return limit > (rlim_t) dso__data_open_cnt;
416 * Check and close LRU dso if we crossed allowed limit
417 * for opened dso file descriptors. The limit is half
418 * of the RLIMIT_NOFILE files opened.
420 static void check_data_close(void)
422 bool cache_fd = may_cache_fd();
429 * dso__data_close - Close DSO data file
432 * External interface to close @dso's data file descriptor.
434 void dso__data_close(struct dso *dso)
440 * dso__data_fd - Get dso's data file descriptor
442 * @machine: machine object
444 * External interface to find dso's file, open it and
445 * returns file descriptor.
447 int dso__data_fd(struct dso *dso, struct machine *machine)
449 enum dso_binary_type binary_type_data[] = {
450 DSO_BINARY_TYPE__BUILD_ID_CACHE,
451 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
452 DSO_BINARY_TYPE__NOT_FOUND,
456 if (dso->data.status == DSO_DATA_STATUS_ERROR)
459 if (dso->data.fd >= 0)
462 if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND) {
463 dso->data.fd = open_dso(dso, machine);
468 dso->binary_type = binary_type_data[i++];
470 dso->data.fd = open_dso(dso, machine);
471 if (dso->data.fd >= 0)
474 } while (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND);
476 if (dso->data.fd >= 0)
477 dso->data.status = DSO_DATA_STATUS_OK;
479 dso->data.status = DSO_DATA_STATUS_ERROR;
484 bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by)
488 if (dso->data.status_seen & flag)
491 dso->data.status_seen |= flag;
497 dso_cache__free(struct rb_root *root)
499 struct rb_node *next = rb_first(root);
502 struct dso_cache *cache;
504 cache = rb_entry(next, struct dso_cache, rb_node);
505 next = rb_next(&cache->rb_node);
506 rb_erase(&cache->rb_node, root);
511 static struct dso_cache *dso_cache__find(const struct rb_root *root, u64 offset)
513 struct rb_node * const *p = &root->rb_node;
514 const struct rb_node *parent = NULL;
515 struct dso_cache *cache;
521 cache = rb_entry(parent, struct dso_cache, rb_node);
522 end = cache->offset + DSO__DATA_CACHE_SIZE;
524 if (offset < cache->offset)
526 else if (offset >= end)
535 dso_cache__insert(struct rb_root *root, struct dso_cache *new)
537 struct rb_node **p = &root->rb_node;
538 struct rb_node *parent = NULL;
539 struct dso_cache *cache;
540 u64 offset = new->offset;
546 cache = rb_entry(parent, struct dso_cache, rb_node);
547 end = cache->offset + DSO__DATA_CACHE_SIZE;
549 if (offset < cache->offset)
551 else if (offset >= end)
555 rb_link_node(&new->rb_node, parent, p);
556 rb_insert_color(&new->rb_node, root);
560 dso_cache__memcpy(struct dso_cache *cache, u64 offset,
563 u64 cache_offset = offset - cache->offset;
564 u64 cache_size = min(cache->size - cache_offset, size);
566 memcpy(data, cache->data + cache_offset, cache_size);
571 dso_cache__read(struct dso *dso, u64 offset, u8 *data, ssize_t size)
573 struct dso_cache *cache;
581 cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE);
585 cache_offset = offset & DSO__DATA_CACHE_MASK;
587 ret = pread(dso->data.fd, cache->data, DSO__DATA_CACHE_SIZE, cache_offset);
591 cache->offset = cache_offset;
593 dso_cache__insert(&dso->data.cache, cache);
595 ret = dso_cache__memcpy(cache, offset, data, size);
605 static ssize_t dso_cache_read(struct dso *dso, u64 offset,
606 u8 *data, ssize_t size)
608 struct dso_cache *cache;
610 cache = dso_cache__find(&dso->data.cache, offset);
612 return dso_cache__memcpy(cache, offset, data, size);
614 return dso_cache__read(dso, offset, data, size);
618 * Reads and caches dso data DSO__DATA_CACHE_SIZE size chunks
619 * in the rb_tree. Any read to already cached data is served
622 static ssize_t cached_read(struct dso *dso, u64 offset, u8 *data, ssize_t size)
630 ret = dso_cache_read(dso, offset, p, size);
634 /* Reached EOF, return what we have. */
650 static int data_file_size(struct dso *dso)
653 char sbuf[STRERR_BUFSIZE];
655 if (!dso->data.file_size) {
656 if (fstat(dso->data.fd, &st)) {
657 pr_err("dso mmap failed, fstat: %s\n",
658 strerror_r(errno, sbuf, sizeof(sbuf)));
661 dso->data.file_size = st.st_size;
668 * dso__data_size - Return dso data size
670 * @machine: machine object
672 * Return: dso data size
674 off_t dso__data_size(struct dso *dso, struct machine *machine)
678 fd = dso__data_fd(dso, machine);
682 if (data_file_size(dso))
685 /* For now just estimate dso data size is close to file size */
686 return dso->data.file_size;
689 static ssize_t data_read_offset(struct dso *dso, u64 offset,
690 u8 *data, ssize_t size)
692 if (data_file_size(dso))
695 /* Check the offset sanity. */
696 if (offset > dso->data.file_size)
699 if (offset + size < offset)
702 return cached_read(dso, offset, data, size);
706 * dso__data_read_offset - Read data from dso file offset
708 * @machine: machine object
709 * @offset: file offset
710 * @data: buffer to store data
711 * @size: size of the @data buffer
713 * External interface to read data from dso file offset. Open
714 * dso data file and use cached_read to get the data.
716 ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
717 u64 offset, u8 *data, ssize_t size)
719 if (dso__data_fd(dso, machine) < 0)
722 return data_read_offset(dso, offset, data, size);
726 * dso__data_read_addr - Read data from dso address
728 * @machine: machine object
729 * @add: virtual memory address
730 * @data: buffer to store data
731 * @size: size of the @data buffer
733 * External interface to read data from dso address.
735 ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
736 struct machine *machine, u64 addr,
737 u8 *data, ssize_t size)
739 u64 offset = map->map_ip(map, addr);
740 return dso__data_read_offset(dso, machine, offset, data, size);
743 struct map *dso__new_map(const char *name)
745 struct map *map = NULL;
746 struct dso *dso = dso__new(name);
749 map = map__new2(0, dso, MAP__FUNCTION);
754 struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
755 const char *short_name, int dso_type)
758 * The kernel dso could be created by build_id processing.
760 struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name);
763 * We need to run this in all cases, since during the build_id
764 * processing we had no idea this was the kernel dso.
767 dso__set_short_name(dso, short_name, false);
768 dso->kernel = dso_type;
775 * Find a matching entry and/or link current entry to RB tree.
776 * Either one of the dso or name parameter must be non-NULL or the
777 * function will not work.
779 static struct dso *dso__findlink_by_longname(struct rb_root *root,
780 struct dso *dso, const char *name)
782 struct rb_node **p = &root->rb_node;
783 struct rb_node *parent = NULL;
786 name = dso->long_name;
788 * Find node with the matching name
791 struct dso *this = rb_entry(*p, struct dso, rb_node);
792 int rc = strcmp(name, this->long_name);
797 * In case the new DSO is a duplicate of an existing
798 * one, print an one-time warning & put the new entry
799 * at the end of the list of duplicates.
801 if (!dso || (dso == this))
802 return this; /* Find matching dso */
804 * The core kernel DSOs may have duplicated long name.
805 * In this case, the short name should be different.
806 * Comparing the short names to differentiate the DSOs.
808 rc = strcmp(dso->short_name, this->short_name);
810 pr_err("Duplicated dso name: %s\n", name);
815 p = &parent->rb_left;
817 p = &parent->rb_right;
820 /* Add new node and rebalance tree */
821 rb_link_node(&dso->rb_node, parent, p);
822 rb_insert_color(&dso->rb_node, root);
827 static inline struct dso *
828 dso__find_by_longname(const struct rb_root *root, const char *name)
830 return dso__findlink_by_longname((struct rb_root *)root, NULL, name);
833 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated)
838 if (dso->long_name_allocated)
839 free((char *)dso->long_name);
841 dso->long_name = name;
842 dso->long_name_len = strlen(name);
843 dso->long_name_allocated = name_allocated;
846 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
851 if (dso->short_name_allocated)
852 free((char *)dso->short_name);
854 dso->short_name = name;
855 dso->short_name_len = strlen(name);
856 dso->short_name_allocated = name_allocated;
859 static void dso__set_basename(struct dso *dso)
862 * basename() may modify path buffer, so we must pass
865 char *base, *lname = strdup(dso->long_name);
871 * basename() may return a pointer to internal
872 * storage which is reused in subsequent calls
873 * so copy the result.
875 base = strdup(basename(lname));
882 dso__set_short_name(dso, base, true);
885 int dso__name_len(const struct dso *dso)
888 return strlen("[unknown]");
890 return dso->long_name_len;
892 return dso->short_name_len;
895 bool dso__loaded(const struct dso *dso, enum map_type type)
897 return dso->loaded & (1 << type);
900 bool dso__sorted_by_name(const struct dso *dso, enum map_type type)
902 return dso->sorted_by_name & (1 << type);
905 void dso__set_sorted_by_name(struct dso *dso, enum map_type type)
907 dso->sorted_by_name |= (1 << type);
910 struct dso *dso__new(const char *name)
912 struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1);
916 strcpy(dso->name, name);
917 dso__set_long_name(dso, dso->name, false);
918 dso__set_short_name(dso, dso->name, false);
919 for (i = 0; i < MAP__NR_TYPES; ++i)
920 dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
921 dso->data.cache = RB_ROOT;
923 dso->data.status = DSO_DATA_STATUS_UNKNOWN;
924 dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
925 dso->binary_type = DSO_BINARY_TYPE__NOT_FOUND;
926 dso->is_64_bit = (sizeof(void *) == 8);
929 dso->sorted_by_name = 0;
930 dso->has_build_id = 0;
931 dso->has_srcline = 1;
933 dso->kernel = DSO_TYPE_USER;
934 dso->needs_swap = DSO_SWAP__UNSET;
935 RB_CLEAR_NODE(&dso->rb_node);
936 INIT_LIST_HEAD(&dso->node);
937 INIT_LIST_HEAD(&dso->data.open_entry);
943 void dso__delete(struct dso *dso)
947 if (!RB_EMPTY_NODE(&dso->rb_node))
948 pr_err("DSO %s is still in rbtree when being deleted!\n",
950 for (i = 0; i < MAP__NR_TYPES; ++i)
951 symbols__delete(&dso->symbols[i]);
953 if (dso->short_name_allocated) {
954 zfree((char **)&dso->short_name);
955 dso->short_name_allocated = false;
958 if (dso->long_name_allocated) {
959 zfree((char **)&dso->long_name);
960 dso->long_name_allocated = false;
963 dso__data_close(dso);
964 dso_cache__free(&dso->data.cache);
966 zfree(&dso->symsrc_filename);
970 void dso__set_build_id(struct dso *dso, void *build_id)
972 memcpy(dso->build_id, build_id, sizeof(dso->build_id));
973 dso->has_build_id = 1;
976 bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
978 return memcmp(dso->build_id, build_id, sizeof(dso->build_id)) == 0;
981 void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
985 if (machine__is_default_guest(machine))
987 sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
988 if (sysfs__read_build_id(path, dso->build_id,
989 sizeof(dso->build_id)) == 0)
990 dso->has_build_id = true;
993 int dso__kernel_module_get_build_id(struct dso *dso,
994 const char *root_dir)
996 char filename[PATH_MAX];
998 * kernel module short names are of the form "[module]" and
999 * we need just "module" here.
1001 const char *name = dso->short_name + 1;
1003 snprintf(filename, sizeof(filename),
1004 "%s/sys/module/%.*s/notes/.note.gnu.build-id",
1005 root_dir, (int)strlen(name) - 1, name);
1007 if (sysfs__read_build_id(filename, dso->build_id,
1008 sizeof(dso->build_id)) == 0)
1009 dso->has_build_id = true;
1014 bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
1016 bool have_build_id = false;
1019 list_for_each_entry(pos, head, node) {
1020 if (with_hits && !pos->hit)
1022 if (pos->has_build_id) {
1023 have_build_id = true;
1026 if (filename__read_build_id(pos->long_name, pos->build_id,
1027 sizeof(pos->build_id)) > 0) {
1028 have_build_id = true;
1029 pos->has_build_id = true;
1033 return have_build_id;
1036 void dsos__add(struct dsos *dsos, struct dso *dso)
1038 list_add_tail(&dso->node, &dsos->head);
1039 dso__findlink_by_longname(&dsos->root, dso, NULL);
1042 struct dso *dsos__find(const struct dsos *dsos, const char *name,
1048 list_for_each_entry(pos, &dsos->head, node)
1049 if (strcmp(pos->short_name, name) == 0)
1053 return dso__find_by_longname(&dsos->root, name);
1056 struct dso *dsos__addnew(struct dsos *dsos, const char *name)
1058 struct dso *dso = dso__new(name);
1061 dsos__add(dsos, dso);
1062 dso__set_basename(dso);
1067 struct dso *__dsos__findnew(struct dsos *dsos, const char *name)
1069 struct dso *dso = dsos__find(dsos, name, false);
1071 return dso ? dso : dsos__addnew(dsos, name);
1074 size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
1075 bool (skip)(struct dso *dso, int parm), int parm)
1080 list_for_each_entry(pos, head, node) {
1081 if (skip && skip(pos, parm))
1083 ret += dso__fprintf_buildid(pos, fp);
1084 ret += fprintf(fp, " %s\n", pos->long_name);
1089 size_t __dsos__fprintf(struct list_head *head, FILE *fp)
1094 list_for_each_entry(pos, head, node) {
1096 for (i = 0; i < MAP__NR_TYPES; ++i)
1097 ret += dso__fprintf(pos, i, fp);
1103 size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
1105 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
1107 build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
1108 return fprintf(fp, "%s", sbuild_id);
1111 size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp)
1114 size_t ret = fprintf(fp, "dso: %s (", dso->short_name);
1116 if (dso->short_name != dso->long_name)
1117 ret += fprintf(fp, "%s, ", dso->long_name);
1118 ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type],
1119 dso__loaded(dso, type) ? "" : "NOT ");
1120 ret += dso__fprintf_buildid(dso, fp);
1121 ret += fprintf(fp, ")\n");
1122 for (nd = rb_first(&dso->symbols[type]); nd; nd = rb_next(nd)) {
1123 struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
1124 ret += symbol__fprintf(pos, fp);
1130 enum dso_type dso__type(struct dso *dso, struct machine *machine)
1134 fd = dso__data_fd(dso, machine);
1136 return DSO__TYPE_UNKNOWN;
1138 return dso__type_fd(fd);
1141 int dso__strerror_load(struct dso *dso, char *buf, size_t buflen)
1143 int idx, errnum = dso->load_errno;
1145 * This must have a same ordering as the enum dso_load_errno.
1147 static const char *dso_load__error_str[] = {
1148 "Internal tools/perf/ library error",
1150 "Can not read build id",
1151 "Mismatching build id",
1152 "Decompression failure",
1155 BUG_ON(buflen == 0);
1158 const char *err = strerror_r(errnum, buf, buflen);
1161 scnprintf(buf, buflen, "%s", err);
1166 if (errnum < __DSO_LOAD_ERRNO__START || errnum >= __DSO_LOAD_ERRNO__END)
1169 idx = errnum - __DSO_LOAD_ERRNO__START;
1170 scnprintf(buf, buflen, "%s", dso_load__error_str[idx]);