3 #include <linux/kernel.h> 5 #include <sys/resource.h> 32 static const char origin[] = {
68 const char *last_slash;
74 last_slash = filename + len;
75 while (last_slash != filename && *last_slash !=
'/')
78 strncpy(dso_dir, filename, last_slash - filename);
93 snprintf(filename, size,
115 snprintf(filename + len, size - len,
"%s.debug", dso->
long_name);
120 snprintf(filename + len, size - len,
"%s", dso->
long_name);
125 const char *last_slash;
129 while (last_slash != dso->
long_name && *last_slash !=
'/')
133 dir_size = last_slash - dso->
long_name + 2;
134 if (dir_size > (size - len)) {
138 len += scnprintf(filename + len, dir_size,
"%s", dso->
long_name);
139 len += scnprintf(filename + len , size - len,
".debug%s",
154 snprintf(filename + len, size - len,
"%.2s/%s.debug",
155 build_id_hex, build_id_hex + 2);
177 snprintf(filename, size,
"%s", dso->
long_name);
192 static const struct {
196 #ifdef HAVE_ZLIB_SUPPORT 199 #ifdef HAVE_LZMA_SUPPORT 219 int mode = cpumode & PERF_RECORD_MISC_CPUMODE_MASK;
221 WARN_ONCE(mode != cpumode,
222 "Internal error: passing unmasked cpumode (%x) to is_kernel_module",
226 case PERF_RECORD_MISC_USER:
227 case PERF_RECORD_MISC_HYPERVISOR:
228 case PERF_RECORD_MISC_GUEST_USER:
233 pr_err(
"Failed to check whether %s is a kernel module or not. Assume it is.",
274 fd = mkstemp(tmpbuf);
302 char *pathname,
size_t len)
313 strncpy(pathname, tmpbuf, len);
335 bool alloc_name,
bool alloc_ext)
337 const char *
name = strrchr(path,
'/');
338 const char *
ext = strrchr(path,
'.');
339 bool is_simple_name =
false;
341 memset(m, 0x0,
sizeof(*m));
342 name = name ? name + 1 : path;
352 if (name[0] ==
'[') {
353 is_simple_name =
true;
354 if ((strncmp(name,
"[kernel.kallsyms]", 17) == 0) ||
355 (strncmp(name,
"[guest.kernel.kallsyms", 22) == 0) ||
356 (strncmp(name,
"[vdso]", 6) == 0) ||
357 (strncmp(name,
"[vdso32]", 8) == 0) ||
358 (strncmp(name,
"[vdsox32]", 9) == 0) ||
359 (strncmp(name,
"[vsyscall]", 10) == 0)) {
367 if ((ext == NULL) || is_simple_name) {
369 m->
name = strdup(name);
370 return m->
name ? 0 : -ENOMEM;
382 m->
kmod = !strncmp(ext,
".ko", 3);
386 if (asprintf(&m->
name,
"[%.*s]", (
int) (ext - name), name) == -1)
389 if (asprintf(&m->
name,
"%s", name) == -1)
396 if (alloc_ext && m->
comp) {
397 m->
ext = strdup(ext + 4);
439 "DSO data fd counter out of bounds.");
456 str_error_r(errno, sbuf,
sizeof(sbuf)));
469 char *root_dir = (
char *)
"";
487 size_t len =
sizeof(newpath);
494 strcpy(name, newpath);
565 dso = list_first_entry(&dso__data_open,
struct dso,
data.open_entry);
575 if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
576 if (l.rlim_cur == RLIM_INFINITY)
579 limit = l.rlim_cur / 2;
581 pr_err(
"failed to get fd limit\n");
715 struct rb_node *next = rb_first(root);
717 pthread_mutex_lock(&dso->
lock);
722 next = rb_next(&cache->
rb_node);
723 rb_erase(&cache->
rb_node, root);
726 pthread_mutex_unlock(&dso->
lock);
732 struct rb_node *
const *p = &root->rb_node;
733 const struct rb_node *parent = NULL;
743 if (offset < cache->offset)
745 else if (offset >= end)
758 struct rb_node **p = &root->rb_node;
759 struct rb_node *parent = NULL;
763 pthread_mutex_lock(&dso->
lock);
771 if (offset < cache->offset)
773 else if (offset >= end)
779 rb_link_node(&
new->rb_node, parent, p);
780 rb_insert_color(&
new->rb_node, root);
784 pthread_mutex_unlock(&dso->
lock);
792 u64 cache_offset = offset - cache->
offset;
793 u64 cache_size =
min(cache->
size - cache_offset, size);
795 memcpy(data, cache->
data + cache_offset, cache_size);
834 cache->
offset = cache_offset;
929 if (fstat(dso->
data.
fd, &st) < 0) {
931 pr_err(
"dso cache fstat failed: %s\n",
932 str_error_r(errno, sbuf,
sizeof(sbuf)));
969 if (offset + size < offset)
972 return cached_read(dso, machine, offset, data, size);
1009 u64 offset = map->
map_ip(map, addr);
1052 struct rb_node **p = &root->
rb_node;
1053 struct rb_node *parent = NULL;
1061 struct dso *
this = rb_entry(*p,
struct dso,
rb_node);
1071 if (!dso || (dso ==
this))
1078 rc = strcmp(dso->
short_name, this->short_name);
1080 pr_err(
"Duplicated dso name: %s\n", name);
1085 p = &parent->rb_left;
1087 p = &parent->rb_right;
1091 rb_link_node(&dso->
rb_node, parent, p);
1092 rb_insert_color(&dso->
rb_node, root);
1115 rb_erase(&dso->
rb_node, root);
1151 char *base, *lname = strdup(dso->
long_name);
1161 base = strdup(basename(lname));
1174 return strlen(
"[unknown]");
1198 struct dso *
dso = calloc(1,
sizeof(*dso) + strlen(name) + 1);
1201 strcpy(dso->
name, name);
1223 INIT_LIST_HEAD(&dso->
node);
1225 pthread_mutex_init(&dso->
lock, NULL);
1226 refcount_set(&dso->
refcnt, 1);
1234 if (!RB_EMPTY_NODE(&dso->
rb_node))
1235 pr_err(
"DSO %s is still in rbtree when being deleted!\n",
1259 pthread_mutex_destroy(&dso->
lock);
1266 refcount_inc(&dso->
refcnt);
1272 if (dso && refcount_dec_and_test(&dso->
refcnt))
1293 sprintf(path,
"%s/sys/kernel/notes", machine->
root_dir);
1300 const char *root_dir)
1309 snprintf(filename,
sizeof(filename),
1310 "%s/sys/module/%.*s/notes/.note.gnu.build-id",
1311 root_dir, (
int)strlen(name) - 1, name);
1322 bool have_build_id =
false;
1326 list_for_each_entry(pos, head,
node) {
1330 have_build_id =
true;
1336 have_build_id =
true;
1342 return have_build_id;
1347 list_add_tail(&dso->
node, &dsos->
head);
1384 list_for_each_entry(pos, &dsos->
head,
node)
1431 bool (
skip)(
struct dso *
dso,
int parm),
int parm)
1436 list_for_each_entry(pos, head,
node) {
1440 ret += fprintf(fp,
" %s\n", pos->
long_name);
1450 list_for_each_entry(pos, head,
node) {
1462 return fprintf(fp,
"%s", sbuild_id);
1468 size_t ret = fprintf(fp,
"dso: %s (", dso->
short_name);
1471 ret += fprintf(fp,
"%s, ", dso->
long_name);
1472 ret += fprintf(fp,
"%sloaded, ",
dso__loaded(dso) ?
"" :
"NOT ");
1474 ret += fprintf(fp,
")\n");
1475 for (nd = rb_first(&dso->
symbols); nd; nd = rb_next(nd)) {
1503 static const char *dso_load__error_str[] = {
1504 "Internal tools/perf/ library error",
1506 "Can not read build id",
1507 "Mismatching build id",
1508 "Decompression failure",
1511 BUG_ON(buflen == 0);
1514 const char *
err = str_error_r(errnum, buf, buflen);
1517 scnprintf(buf, buflen,
"%s", err);
1526 scnprintf(buf, buflen,
"%s", dso_load__error_str[idx]);
char dso__symtab_origin(const struct dso *dso)
enum dso_type dso__type(struct dso *dso, struct machine *machine)
u64(* map_ip)(struct map *, u64)
static int open_dso(struct dso *dso, struct machine *machine)
enum dso_type dso__type_fd(int fd)
void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc)
struct dso * dsos__findnew(struct dsos *dsos, const char *name)
static ssize_t dso_cache__read(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size)
bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
static void check_data_close(void)
struct rb_root inlined_nodes
static bool machine__is_host(struct machine *machine)
static unsigned long flag
static void skip(int size)
static bool may_cache_fd(void)
void auxtrace_cache__free(struct auxtrace_cache *c)
static int __symbol__join_symfs(char *bf, size_t size, const char *path)
void dsos__add(struct dsos *dsos, struct dso *dso)
#define nsinfo__zput(nsi)
static void close_first_dso(void)
static ssize_t dso_cache_read(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size)
struct rb_root symbol_names
int filename__read_build_id(const char *filename, void *bf, size_t size)
static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf)
static int input(yyscan_t yyscanner)
int dso__strerror_load(struct dso *dso, char *buf, size_t buflen)
void reset_fd_limit(void)
int dso__data_get_fd(struct dso *dso, struct machine *machine)
void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated)
int lzma_decompress_to_file(const char *input, int output_fd)
bool dso__sorted_by_name(const struct dso *dso)
bool is_regular_file(const char *file)
void dso__data_close(struct dso *dso)
struct map * dso__new_map(const char *name)
int gzip_decompress_to_file(const char *input, int output_fd)
static void dso_cache__free(struct dso *dso)
void __dsos__add(struct dsos *dsos, struct dso *dso)
size_t __dsos__fprintf(struct list_head *head, FILE *fp)
int filename__read_debuglink(const char *filename, char *debuglink, size_t size)
int up_write(struct rw_semaphore *sem)
int dso__decompress_kmodule_path(struct dso *dso, const char *name, char *pathname, size_t len)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
struct list_head open_entry
void dso__put(struct dso *dso)
struct dso * machine__findnew_dso(struct machine *machine, const char *filename)
int __kmod_path__parse(struct kmod_path *m, const char *path, bool alloc_name, bool alloc_ext)
int down_read(struct rw_semaphore *sem)
enum dso_load_errno load_errno
static void dso__list_del(struct dso *dso)
int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir)
bool is_kernel_module(const char *pathname, int cpumode)
ssize_t dso__data_read_addr(struct dso *dso, struct map *map, struct machine *machine, u64 addr, u8 *data, ssize_t size)
struct dso * __dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
int dso__name_len(const struct dso *dso)
static int data_file_size(struct dso *dso, struct machine *machine)
static ssize_t dso_cache__memcpy(struct dso_cache *cache, u64 offset, u8 *data, u64 size)
static pthread_mutex_t dso__data_open_lock
void nsinfo__mountns_exit(struct nscookie *nc)
#define pr_debug(fmt,...)
static ssize_t cached_read(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size)
struct dso * __dsos__findnew(struct dsos *dsos, const char *name)
struct dso * machine__findnew_kernel(struct machine *machine, const char *name, const char *short_name, int dso_type)
bool dso__needs_decompress(struct dso *dso)
int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type, char *root_dir, char *filename, size_t size)
#define kmod_path__parse_ext(__m, __p)
bool dso__is_vdso(struct dso *dso)
static int do_open(char *name)
enum dso_swap_type needs_swap
struct dso * __dsos__addnew(struct dsos *dsos, const char *name)
static LIST_HEAD(dso__data_open)
struct dso * dso__get(struct dso *dso)
void dso__delete(struct dso *dso)
void symbols__delete(struct rb_root *symbols)
static rlim_t get_fd_limit(void)
static struct dso_cache * dso_cache__find(struct dso *dso, u64 offset)
void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
static void try_to_open_dso(struct dso *dso, struct machine *machine)
static void dso__list_add(struct dso *dso)
char * strxfrchar(char *s, char from, char to)
enum dso_kernel_type kernel
off_t dso__data_size(struct dso *dso, struct machine *machine)
static ssize_t data_read_offset(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size)
static const char *const debuglink_paths[]
x86 movsq based memcpy() in arch/x86/lib/memcpy_64.S") MEMCPY_FN(memcpy_erms
static struct dso * __dso__find_by_longname(struct rb_root *root, const char *name)
bool decompress_to_file(const char *ext, const char *filename, int output_fd)
bool dso__loaded(const struct dso *dso)
void inlines__tree_delete(struct rb_root *tree)
static int __open_dso(struct dso *dso, struct machine *machine)
void srcline__tree_delete(struct rb_root *tree)
size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
size_t dso__fprintf(struct dso *dso, FILE *fp)
struct auxtrace_cache * auxtrace_cache
static struct @9 output[OUTPUT_TYPE_MAX]
struct dso * dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
static struct dso_cache * dso_cache__insert(struct dso *dso, struct dso_cache *new)
struct dso * dso__new(const char *name)
static struct dso * __dso__findlink_by_longname(struct rb_root *root, struct dso *dso, const char *name)
u8 build_id[BUILD_ID_SIZE]
int(* decompress)(const char *input, int output)
static void close_data_fd(struct dso *dso)
int build_id__sprintf(const u8 *build_id, int len, char *bf)
#define DSO__DATA_CACHE_SIZE
void dso__free_a2l(struct dso *dso)
size_t symbol__fprintf(struct symbol *sym, FILE *fp)
void dso__set_build_id(struct dso *dso, void *build_id)
enum dso_binary_type symtab_type
void dso__set_module_info(struct dso *dso, struct kmod_path *m, struct machine *machine)
bool is_supported_compression(const char *ext)
void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
void dso__set_sorted_by_name(struct dso *dso)
#define kmod_path__parse(__m, __p)
int down_write(struct rw_semaphore *sem)
ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, u64 offset, u8 *data, ssize_t size)
char * dso__build_id_filename(const struct dso *dso, char *bf, size_t size, bool is_debug)
int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, bool(skip)(struct dso *dso, int parm), int parm)
#define DSO__DATA_CACHE_MASK
static const struct @68 compressions[]
static void dso__set_basename(struct dso *dso)
enum dso_binary_type binary_type
int up_read(struct rw_semaphore *sem)
void dso__data_put_fd(struct dso *dso __maybe_unused)
static void close_dso(struct dso *dso)
static long dso__data_open_cnt
bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by)
struct map * map__new2(u64 start, struct dso *dso)
void static void * zalloc(size_t size)
int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3)
static bool machine__is_default_guest(struct machine *machine)