^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __PERF_DSO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __PERF_DSO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <pthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "build-id.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct machine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct perf_env;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DSO__NAME_KALLSYMS "[kernel.kallsyms]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define DSO__NAME_KCORE "[kernel.kcore]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) enum dso_binary_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) DSO_BINARY_TYPE__KALLSYMS = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) DSO_BINARY_TYPE__GUEST_KALLSYMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) DSO_BINARY_TYPE__VMLINUX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) DSO_BINARY_TYPE__GUEST_VMLINUX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) DSO_BINARY_TYPE__JAVA_JIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) DSO_BINARY_TYPE__DEBUGLINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) DSO_BINARY_TYPE__BUILD_ID_CACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) DSO_BINARY_TYPE__GUEST_KMODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) DSO_BINARY_TYPE__KCORE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) DSO_BINARY_TYPE__GUEST_KCORE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) DSO_BINARY_TYPE__BPF_PROG_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) DSO_BINARY_TYPE__BPF_IMAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) DSO_BINARY_TYPE__OOL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) DSO_BINARY_TYPE__NOT_FOUND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) enum dso_space_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) DSO_SPACE__USER = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) DSO_SPACE__KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) DSO_SPACE__KERNEL_GUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) enum dso_swap_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) DSO_SWAP__UNSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) DSO_SWAP__NO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) DSO_SWAP__YES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) enum dso_data_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) DSO_DATA_STATUS_ERROR = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) DSO_DATA_STATUS_UNKNOWN = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) DSO_DATA_STATUS_OK = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) enum dso_data_status_seen {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) DSO_DATA_STATUS_SEEN_ITRACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) enum dso_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) DSO__TYPE_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) DSO__TYPE_64BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) DSO__TYPE_32BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) DSO__TYPE_X32BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) enum dso_load_errno {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) DSO_LOAD_ERRNO__SUCCESS = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Choose an arbitrary negative big number not to clash with standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * errno since SUS requires the errno has distinct positive values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * See 'Issue 6' in the link below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __DSO_LOAD_ERRNO__START = -10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) DSO_LOAD_ERRNO__INTERNAL_ERROR = __DSO_LOAD_ERRNO__START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* for symsrc__init() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) DSO_LOAD_ERRNO__INVALID_ELF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) DSO_LOAD_ERRNO__CANNOT_READ_BUILDID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) DSO_LOAD_ERRNO__MISMATCHING_BUILDID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* for decompress_kmodule */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __DSO_LOAD_ERRNO__END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define DSO__SWAP(dso, type, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) type ____r = val; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (dso->needs_swap == DSO_SWAP__YES) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) switch (sizeof(____r)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case 2: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ____r = bswap_16(val); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) case 4: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ____r = bswap_32(val); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case 8: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ____r = bswap_64(val); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) break; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) default: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) BUG_ON(1); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ____r; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define DSO__DATA_CACHE_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * Data about backing storage DSO, comes from PERF_RECORD_MMAP2 meta events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct dso_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u32 maj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u32 min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u64 ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u64 ino_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct dso_cache {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct rb_node rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u64 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) char data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct auxtrace_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct dso {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) pthread_mutex_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct rb_node rb_node; /* rbtree node sorted by long name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct rb_root *root; /* root of rbtree that rb_node is in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct rb_root_cached symbols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct rb_root_cached symbol_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct rb_root_cached inlined_nodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct rb_root_cached srclines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) u64 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct symbol *symbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } last_find_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void *a2l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) char *symsrc_filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) unsigned int a2l_fails;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) enum dso_space_type kernel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) enum dso_swap_type needs_swap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) enum dso_binary_type symtab_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) enum dso_binary_type binary_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) enum dso_load_errno load_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) u8 adjust_symbols:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) u8 has_build_id:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u8 has_srcline:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u8 hit:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u8 annotate_warned:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) u8 short_name_allocated:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) u8 long_name_allocated:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) u8 is_64_bit:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) bool sorted_by_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) bool loaded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u8 rel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct build_id bid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) u64 text_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) const char *short_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) const char *long_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) u16 long_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) u16 short_name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) void *dwfl; /* DWARF debug info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct auxtrace_cache *auxtrace_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* dso data file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct rb_root cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) u32 status_seen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) size_t file_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct list_head open_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) u64 debug_frame_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) u64 eh_frame_hdr_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) } data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* bpf prog information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u32 sub_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct perf_env *env;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) } bpf_prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) union { /* Tool specific area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) void *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u64 db_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct nsinfo *nsinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct dso_id id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) refcount_t refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) char name[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* dso__for_each_symbol - iterate over the symbols of given type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * @dso: the 'struct dso *' in which symbols itereated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @pos: the 'struct symbol *' to use as a loop cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @n: the 'struct rb_node *' to use as a temporary storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define dso__for_each_symbol(dso, pos, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) symbols__for_each_entry(&(dso)->symbols, pos, n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static inline void dso__set_loaded(struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) dso->loaded = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct dso *dso__new_id(const char *name, struct dso_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct dso *dso__new(const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) void dso__delete(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int dso__cmp_id(struct dso *a, struct dso *b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int dso__name_len(const struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct dso *dso__get(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void dso__put(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static inline void __dso__zput(struct dso **dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) dso__put(*dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *dso = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define dso__zput(dso) __dso__zput(&dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) bool dso__loaded(const struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline bool dso__has_symbols(const struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return !RB_EMPTY_ROOT(&dso->symbols.rb_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) bool dso__sorted_by_name(const struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) void dso__set_sorted_by_name(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) void dso__sort_by_name(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) void dso__set_build_id(struct dso *dso, struct build_id *bid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) bool dso__build_id_equal(const struct dso *dso, struct build_id *bid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) void dso__read_running_kernel_build_id(struct dso *dso,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct machine *machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) char dso__symtab_origin(const struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) char *root_dir, char *filename, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) bool is_kernel_module(const char *pathname, int cpumode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) bool dso__needs_decompress(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int dso__decompress_kmodule_path(struct dso *dso, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) char *pathname, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct kmod_path {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) bool kmod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int __kmod_path__parse(struct kmod_path *m, const char *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) bool alloc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #define kmod_path__parse(__m, __p) __kmod_path__parse(__m, __p, false)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) void dso__set_module_info(struct dso *dso, struct kmod_path *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct machine *machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * The dso__data_* external interface provides following functions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * dso__data_get_fd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * dso__data_put_fd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * dso__data_close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * dso__data_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * dso__data_read_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * dso__data_read_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * dso__data_write_cache_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * dso__data_write_cache_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * Please refer to the dso.c object code for each function and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * arguments documentation. Following text tries to explain the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * dso file descriptor caching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * The dso__data* interface allows caching of opened file descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * to speed up the dso data accesses. The idea is to leave the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * descriptor opened ideally for the whole life of the dso object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * The current usage of the dso__data_* interface is as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * Get DSO's fd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * int fd = dso__data_get_fd(dso, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * if (fd >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * USE 'fd' SOMEHOW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * dso__data_put_fd(dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * Read DSO's data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * n = dso__data_read_offset(dso_0, &machine, 0, buf, BUFSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * n = dso__data_read_addr(dso_0, &machine, 0, buf, BUFSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * Eventually close DSO's fd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * dso__data_close(dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * It is not necessary to close the DSO object data file. Each time new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * DSO data file is opened, the limit (RLIMIT_NOFILE/2) is checked. Once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * it is crossed, the oldest opened DSO object is closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * The dso__delete function calls close_dso function to ensure the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * data file descriptor gets closed/unmapped before the dso object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * TODO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int dso__data_get_fd(struct dso *dso, struct machine *machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) void dso__data_put_fd(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void dso__data_close(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int dso__data_file_size(struct dso *dso, struct machine *machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) off_t dso__data_size(struct dso *dso, struct machine *machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) u64 offset, u8 *data, ssize_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct machine *machine, u64 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) u8 *data, ssize_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ssize_t dso__data_write_cache_offs(struct dso *dso, struct machine *machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) u64 offset, const u8 *data, ssize_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct machine *machine, u64 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) const u8 *data, ssize_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct map *dso__new_map(const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) const char *short_name, int dso_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) void dso__reset_find_symbol_cache(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) size_t dso__fprintf(struct dso *dso, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static inline bool dso__is_vmlinux(struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return dso->binary_type == DSO_BINARY_TYPE__VMLINUX ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) dso->binary_type == DSO_BINARY_TYPE__GUEST_VMLINUX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static inline bool dso__is_kcore(struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return dso->binary_type == DSO_BINARY_TYPE__KCORE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) dso->binary_type == DSO_BINARY_TYPE__GUEST_KCORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static inline bool dso__is_kallsyms(struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return dso->kernel && dso->long_name[0] != '/';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) void dso__free_a2l(struct dso *dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) enum dso_type dso__type(struct dso *dso, struct machine *machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int dso__strerror_load(struct dso *dso, char *buf, size_t buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) void reset_fd_limit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) #endif /* __PERF_DSO */