projects/linux·blob master · refs

1009 lines · 26.2 KiB

1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __PERF_DSO
3#define __PERF_DSO
4
5#include <linux/refcount.h>
6#include <linux/types.h>
7#include <linux/rbtree.h>
8#include <sys/types.h>
9#include <stdbool.h>
10#include <stdio.h>
11#include <linux/bitops.h>
12#include <string.h>
13#include "build-id.h"
14#include "debuginfo.h"
15#include "mutex.h"
16#include <internal/rc_check.h>
17
18struct machine;
19struct map;
20struct perf_env;
21
22#define DSO__NAME_KALLSYMS "[kernel.kallsyms]"
23#define DSO__NAME_KCORE "[kernel.kcore]"
24#define DSO__NAME_GUEST_KALLSYMS "[guest.kernel.kallsyms]"
25#define DSO__NAME_GUEST_KALLSYMS_PID_PREFIX "[guest.kernel.kallsyms."
26
27/*
28 * Validate names of the form "[guest.kernel.kallsyms.<pid>]", where
29 * <pid> is the PID of the guest VM and varies per guest, so it
30 * cannot be matched with strcmp() against a fixed string.
31 *
32 * Every character after the fixed prefix must be a decimal digit,
33 * with ']' immediately terminating the digit run and nothing
34 * following it. This rules out '/', "..", or any other character
35 * being smuggled into the name.
36 */
37static inline bool is_guest_kallsyms_pid_name(const char *name)
38{
39 const size_t prefix_len = sizeof(DSO__NAME_GUEST_KALLSYMS_PID_PREFIX) - 1;
40 size_t digits;
41
42 if (strncmp(name, DSO__NAME_GUEST_KALLSYMS_PID_PREFIX, prefix_len) != 0)
43 return false;
44
45 digits = strspn(name + prefix_len, "0123456789");
46 if (digits == 0)
47 return false;
48
49 /* ']' must terminate the digit run, with nothing trailing it */
50 if (name[prefix_len + digits] != ']')
51 return false;
52
53 if (name[prefix_len + digits + 1] != '\0')
54 return false;
55
56 return true;
57}
58
59/**
60 * enum dso_binary_type - The kind of DSO generally associated with a memory
61 * region (struct map).
62 */
63enum dso_binary_type {
64 /** @DSO_BINARY_TYPE__KALLSYMS: Symbols from /proc/kallsyms file. */
65 DSO_BINARY_TYPE__KALLSYMS = 0,
66 /** @DSO_BINARY_TYPE__GUEST_KALLSYMS: Guest /proc/kallsyms file. */
67 DSO_BINARY_TYPE__GUEST_KALLSYMS,
68 /** @DSO_BINARY_TYPE__VMLINUX: Path to kernel /boot/vmlinux file. */
69 DSO_BINARY_TYPE__VMLINUX,
70 /** @DSO_BINARY_TYPE__GUEST_VMLINUX: Path to guest kernel /boot/vmlinux file. */
71 DSO_BINARY_TYPE__GUEST_VMLINUX,
72 /** @DSO_BINARY_TYPE__JAVA_JIT: Symbols from /tmp/perf.map file. */
73 DSO_BINARY_TYPE__JAVA_JIT,
74 /**
75 * @DSO_BINARY_TYPE__DEBUGLINK: Debug file readable from the file path
76 * in the .gnu_debuglink ELF section of the dso.
77 */
78 DSO_BINARY_TYPE__DEBUGLINK,
79 /**
80 * @DSO_BINARY_TYPE__BUILD_ID_CACHE: File named after buildid located in
81 * the buildid cache with an elf filename.
82 */
83 DSO_BINARY_TYPE__BUILD_ID_CACHE,
84 /**
85 * @DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: File named after buildid
86 * located in the buildid cache with a debug filename.
87 */
88 DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO,
89 /**
90 * @DSO_BINARY_TYPE__FEDORA_DEBUGINFO: Debug file in /usr/lib/debug
91 * with .debug suffix.
92 */
93 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
94 /** @DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: Debug file in /usr/lib/debug. */
95 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
96 /**
97 * @DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO: dso__long_name debuginfo
98 * file in /usr/lib/debug/lib rather than the expected
99 * /usr/lib/debug/usr/lib.
100 */
101 DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO,
102 /**
103 * @DSO_BINARY_TYPE__BUILDID_DEBUGINFO: File named after buildid located
104 * in /usr/lib/debug/.build-id/.
105 */
106 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
107 /**
108 * @DSO_BINARY_TYPE__GNU_DEBUGDATA: MiniDebuginfo where a compressed
109 * ELF file is placed in a .gnu_debugdata section.
110 */
111 DSO_BINARY_TYPE__GNU_DEBUGDATA,
112 /** @DSO_BINARY_TYPE__SYSTEM_PATH_DSO: A regular executable/shared-object file. */
113 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
114 /** @DSO_BINARY_TYPE__GUEST_KMODULE: Guest kernel module .ko file. */
115 DSO_BINARY_TYPE__GUEST_KMODULE,
116 /** @DSO_BINARY_TYPE__GUEST_KMODULE_COMP: Guest kernel module .ko.gz file. */
117 DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
118 /** @DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: Kernel module .ko file. */
119 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
120 /** @DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP: Kernel module .ko.gz file. */
121 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
122 /** @DSO_BINARY_TYPE__KCORE: /proc/kcore file. */
123 DSO_BINARY_TYPE__KCORE,
124 /** @DSO_BINARY_TYPE__GUEST_KCORE: Guest /proc/kcore file. */
125 DSO_BINARY_TYPE__GUEST_KCORE,
126 /**
127 * @DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: Openembedded/Yocto -dbg
128 * package debug info.
129 */
130 DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
131 /** @DSO_BINARY_TYPE__BPF_PROG_INFO: jitted BPF code. */
132 DSO_BINARY_TYPE__BPF_PROG_INFO,
133 /** @DSO_BINARY_TYPE__BPF_IMAGE: jitted BPF trampoline or dispatcher code. */
134 DSO_BINARY_TYPE__BPF_IMAGE,
135 /**
136 * @DSO_BINARY_TYPE__OOL: out of line code such as kprobe-replaced
137 * instructions or optimized kprobes or ftrace trampolines.
138 */
139 DSO_BINARY_TYPE__OOL,
140 /** @DSO_BINARY_TYPE__NOT_FOUND: Unknown DSO kind. */
141 DSO_BINARY_TYPE__NOT_FOUND,
142};
143
144enum dso_space_type {
145 DSO_SPACE__USER = 0,
146 DSO_SPACE__KERNEL,
147 DSO_SPACE__KERNEL_GUEST
148};
149
150enum dso_swap_type {
151 DSO_SWAP__UNSET,
152 DSO_SWAP__NO,
153 DSO_SWAP__YES,
154};
155
156enum dso_data_status {
157 DSO_DATA_STATUS_ERROR = -1,
158 DSO_DATA_STATUS_UNKNOWN = 0,
159 DSO_DATA_STATUS_OK = 1,
160};
161
162enum dso_data_status_seen {
163 DSO_DATA_STATUS_SEEN_ITRACE,
164};
165
166enum dso_type {
167 DSO__TYPE_UNKNOWN,
168 DSO__TYPE_64BIT,
169 DSO__TYPE_32BIT,
170 DSO__TYPE_X32BIT,
171};
172
173enum dso_load_errno {
174 DSO_LOAD_ERRNO__SUCCESS = 0,
175
176 /*
177 * Choose an arbitrary negative big number not to clash with standard
178 * errno since SUS requires the errno has distinct positive values.
179 * See 'Issue 6' in the link below.
180 *
181 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
182 */
183 __DSO_LOAD_ERRNO__START = -10000,
184
185 DSO_LOAD_ERRNO__INTERNAL_ERROR = __DSO_LOAD_ERRNO__START,
186
187 /* for symsrc__init() */
188 DSO_LOAD_ERRNO__INVALID_ELF,
189 DSO_LOAD_ERRNO__CANNOT_READ_BUILDID,
190 DSO_LOAD_ERRNO__MISMATCHING_BUILDID,
191
192 /* for decompress_kmodule */
193 DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE,
194
195 __DSO_LOAD_ERRNO__END,
196};
197
198#define DSO_SWAP_TYPE__SWAP(swap_type, type, val) \
199({ \
200 type ____r = val; \
201 BUG_ON(swap_type == DSO_SWAP__UNSET); \
202 if (swap_type == DSO_SWAP__YES) { \
203 switch (sizeof(____r)) { \
204 case 2: \
205 ____r = bswap_16(val); \
206 break; \
207 case 4: \
208 ____r = bswap_32(val); \
209 break; \
210 case 8: \
211 ____r = bswap_64(val); \
212 break; \
213 default: \
214 BUG_ON(1); \
215 } \
216 } \
217 ____r; \
218})
219
220#define DSO__SWAP(dso, type, val) DSO_SWAP_TYPE__SWAP(dso__needs_swap(dso), type, val)
221
222#define DSO__DATA_CACHE_SIZE 4096
223#define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
224
225/**
226 * struct dso_id
227 *
228 * Data about backing storage DSO, comes from PERF_RECORD_MMAP2 meta events,
229 * reading from /proc/pid/maps or synthesis of build_ids from DSOs. Possibly
230 * incomplete at any particular use.
231 */
232struct dso_id {
233 /* Data related to the mmap2 event or read from /proc/pid/maps. */
234 struct {
235 u32 maj;
236 u32 min;
237 u64 ino;
238 u64 ino_generation;
239 };
240 /** @mmap2_valid: Are the maj, min and ino fields valid? */
241 bool mmap2_valid;
242 /**
243 * @mmap2_ino_generation_valid: Is the ino_generation valid? Generally
244 * false for /proc/pid/maps mmap event.
245 */
246 bool mmap2_ino_generation_valid;
247 /**
248 * @build_id: A possibly populated build_id. build_id__is_defined checks
249 * whether it is populated.
250 */
251 struct build_id build_id;
252};
253
254struct dso_cache {
255 struct rb_node rb_node;
256 u64 offset;
257 u64 size;
258 char data[];
259};
260
261struct dso_data {
262 struct rb_root cache;
263 struct list_head open_entry;
264#ifdef REFCNT_CHECKING
265 struct dso *dso;
266#endif
267 int fd;
268 int status;
269 u32 status_seen;
270 u64 file_size;
271#ifdef HAVE_LIBUNWIND_SUPPORT
272 u64 elf_base_addr;
273 u64 debug_frame_offset;
274 u64 eh_frame_hdr_addr;
275 u64 eh_frame_hdr_offset;
276#endif
277};
278
279struct dso_bpf_prog {
280 u32 id;
281 u32 sub_id;
282 struct perf_env *env;
283};
284
285struct auxtrace_cache;
286
287DECLARE_RC_STRUCT(dso) {
288 struct mutex lock;
289 struct dsos *dsos;
290 struct rb_root_cached symbols;
291 struct symbol **symbol_names;
292 size_t symbol_names_len;
293 struct rb_root_cached inlined_nodes;
294 struct rb_root_cached srclines;
295 struct rb_root data_types;
296 struct rb_root global_vars;
297
298 struct {
299 u64 addr;
300 struct symbol *symbol;
301 } last_find_result;
302 u64 text_offset;
303 u64 text_end;
304 const char *short_name;
305 const char *long_name;
306 void *a2l;
307 void *libdw;
308 char *symsrc_filename;
309 struct nsinfo *nsinfo;
310 struct auxtrace_cache *auxtrace_cache;
311 union { /* Tool specific area */
312 void *priv;
313 u64 db_id;
314 };
315 /* bpf prog information */
316 struct dso_bpf_prog bpf_prog;
317 /* dso data file */
318 struct dso_data data;
319 struct dso_id id;
320 unsigned int a2l_fails;
321 int comp;
322 refcount_t refcnt;
323 enum dso_load_errno load_errno;
324 u16 long_name_len;
325 u16 short_name_len;
326 enum dso_binary_type symtab_type:8;
327 enum dso_binary_type binary_type:8;
328 enum dso_space_type kernel:2;
329 enum dso_swap_type needs_swap:2;
330 bool is_kmod:1;
331 u8 adjust_symbols:1;
332 u8 header_build_id:1;
333 u8 has_srcline:1;
334 u8 hit:1;
335 u8 annotate_warned:1;
336 u8 auxtrace_warned:1;
337 u8 debuginfo_warned:1;
338 u8 short_name_allocated:1;
339 u8 long_name_allocated:1;
340 u8 is_64_bit:1;
341 bool sorted_by_name;
342 bool loaded;
343 u8 rel;
344 char name[];
345};
346
347extern struct mutex _dso__data_open_lock;
348extern const struct dso_id dso_id_empty;
349
350int dso_id__cmp(const struct dso_id *a, const struct dso_id *b);
351
352/* dso__for_each_symbol - iterate over the symbols of given type
353 *
354 * @dso: the 'struct dso *' in which symbols are iterated
355 * @pos: the 'struct symbol *' to use as a loop cursor
356 * @n: the 'struct rb_node *' to use as a temporary storage
357 */
358#define dso__for_each_symbol(dso, pos, n) \
359 symbols__for_each_entry(dso__symbols(dso), pos, n)
360
361static inline void *dso__a2l(const struct dso *dso)
362{
363 return RC_CHK_ACCESS(dso)->a2l;
364}
365
366static inline void dso__set_a2l(struct dso *dso, void *val)
367{
368 RC_CHK_ACCESS(dso)->a2l = val;
369}
370
371static inline void *dso__libdw(const struct dso *dso)
372{
373 return RC_CHK_ACCESS(dso)->libdw;
374}
375
376static inline void dso__set_libdw(struct dso *dso, void *val)
377{
378 RC_CHK_ACCESS(dso)->libdw = val;
379}
380
381struct Dwfl;
382#ifdef HAVE_LIBDW_SUPPORT
383struct Dwfl *dso__libdw_dwfl(struct dso *dso);
384#else
385static inline struct Dwfl *dso__libdw_dwfl(struct dso *dso __maybe_unused)
386{
387 return NULL;
388}
389#endif
390
391static inline unsigned int dso__a2l_fails(const struct dso *dso)
392{
393 return RC_CHK_ACCESS(dso)->a2l_fails;
394}
395
396static inline void dso__set_a2l_fails(struct dso *dso, unsigned int val)
397{
398 RC_CHK_ACCESS(dso)->a2l_fails = val;
399}
400
401static inline bool dso__adjust_symbols(const struct dso *dso)
402{
403 return RC_CHK_ACCESS(dso)->adjust_symbols;
404}
405
406static inline void dso__set_adjust_symbols(struct dso *dso, bool val)
407{
408 RC_CHK_ACCESS(dso)->adjust_symbols = val;
409}
410
411static inline bool dso__annotate_warned(const struct dso *dso)
412{
413 return RC_CHK_ACCESS(dso)->annotate_warned;
414}
415
416static inline void dso__set_annotate_warned(struct dso *dso)
417{
418 RC_CHK_ACCESS(dso)->annotate_warned = 1;
419}
420
421static inline bool dso__debuginfo_warned(const struct dso *dso)
422{
423 return RC_CHK_ACCESS(dso)->debuginfo_warned;
424}
425
426static inline void dso__set_debuginfo_warned(struct dso *dso)
427{
428 RC_CHK_ACCESS(dso)->debuginfo_warned = 1;
429}
430
431static inline bool dso__auxtrace_warned(const struct dso *dso)
432{
433 return RC_CHK_ACCESS(dso)->auxtrace_warned;
434}
435
436static inline void dso__set_auxtrace_warned(struct dso *dso)
437{
438 RC_CHK_ACCESS(dso)->auxtrace_warned = 1;
439}
440
441static inline struct auxtrace_cache *dso__auxtrace_cache(struct dso *dso)
442{
443 return RC_CHK_ACCESS(dso)->auxtrace_cache;
444}
445
446static inline void dso__set_auxtrace_cache(struct dso *dso, struct auxtrace_cache *cache)
447{
448 RC_CHK_ACCESS(dso)->auxtrace_cache = cache;
449}
450
451static inline struct dso_bpf_prog *dso__bpf_prog(struct dso *dso)
452{
453 return &RC_CHK_ACCESS(dso)->bpf_prog;
454}
455
456static inline bool dso__has_srcline(const struct dso *dso)
457{
458 return RC_CHK_ACCESS(dso)->has_srcline;
459}
460
461static inline void dso__set_has_srcline(struct dso *dso, bool val)
462{
463 RC_CHK_ACCESS(dso)->has_srcline = val;
464}
465
466static inline int dso__comp(const struct dso *dso)
467{
468 return RC_CHK_ACCESS(dso)->comp;
469}
470
471static inline void dso__set_comp(struct dso *dso, int comp)
472{
473 RC_CHK_ACCESS(dso)->comp = comp;
474}
475
476static inline struct dso_data *dso__data(struct dso *dso)
477{
478 return &RC_CHK_ACCESS(dso)->data;
479}
480
481static inline u64 dso__db_id(const struct dso *dso)
482{
483 return RC_CHK_ACCESS(dso)->db_id;
484}
485
486static inline void dso__set_db_id(struct dso *dso, u64 db_id)
487{
488 RC_CHK_ACCESS(dso)->db_id = db_id;
489}
490
491static inline struct dsos *dso__dsos(struct dso *dso)
492{
493 return RC_CHK_ACCESS(dso)->dsos;
494}
495
496static inline void dso__set_dsos(struct dso *dso, struct dsos *dsos)
497{
498 RC_CHK_ACCESS(dso)->dsos = dsos;
499}
500
501static inline bool dso__header_build_id(struct dso *dso)
502{
503 return RC_CHK_ACCESS(dso)->header_build_id;
504}
505
506static inline void dso__set_header_build_id(struct dso *dso, bool val)
507{
508 RC_CHK_ACCESS(dso)->header_build_id = val;
509}
510
511static inline bool dso__hit(const struct dso *dso)
512{
513 return RC_CHK_ACCESS(dso)->hit;
514}
515
516static inline void dso__set_hit(struct dso *dso)
517{
518 RC_CHK_ACCESS(dso)->hit = 1;
519}
520
521static inline struct dso_id *dso__id(struct dso *dso)
522{
523 return &RC_CHK_ACCESS(dso)->id;
524}
525
526static inline const struct dso_id *dso__id_const(const struct dso *dso)
527{
528 return &RC_CHK_ACCESS(dso)->id;
529}
530
531static inline const struct build_id *dso__bid(const struct dso *dso)
532{
533 return &dso__id_const(dso)->build_id;
534}
535
536static inline bool dso__has_build_id(const struct dso *dso)
537{
538 return build_id__is_defined(dso__bid(dso));
539}
540
541static inline struct rb_root_cached *dso__inlined_nodes(struct dso *dso)
542{
543 return &RC_CHK_ACCESS(dso)->inlined_nodes;
544}
545
546static inline bool dso__is_64_bit(const struct dso *dso)
547{
548 return RC_CHK_ACCESS(dso)->is_64_bit;
549}
550
551static inline void dso__set_is_64_bit(struct dso *dso, bool is)
552{
553 RC_CHK_ACCESS(dso)->is_64_bit = is;
554}
555
556static inline bool dso__is_kmod(const struct dso *dso)
557{
558 return RC_CHK_ACCESS(dso)->is_kmod;
559}
560
561static inline void dso__set_is_kmod(struct dso *dso)
562{
563 RC_CHK_ACCESS(dso)->is_kmod = 1;
564}
565
566static inline enum dso_space_type dso__kernel(const struct dso *dso)
567{
568 return RC_CHK_ACCESS(dso)->kernel;
569}
570
571static inline void dso__set_kernel(struct dso *dso, enum dso_space_type kernel)
572{
573 RC_CHK_ACCESS(dso)->kernel = kernel;
574}
575
576static inline u64 dso__last_find_result_addr(const struct dso *dso)
577{
578 return RC_CHK_ACCESS(dso)->last_find_result.addr;
579}
580
581static inline void dso__set_last_find_result_addr(struct dso *dso, u64 addr)
582{
583 RC_CHK_ACCESS(dso)->last_find_result.addr = addr;
584}
585
586static inline struct symbol *dso__last_find_result_symbol(const struct dso *dso)
587{
588 return RC_CHK_ACCESS(dso)->last_find_result.symbol;
589}
590
591static inline void dso__set_last_find_result_symbol(struct dso *dso, struct symbol *symbol)
592{
593 RC_CHK_ACCESS(dso)->last_find_result.symbol = symbol;
594}
595
596static inline enum dso_load_errno *dso__load_errno(struct dso *dso)
597{
598 return &RC_CHK_ACCESS(dso)->load_errno;
599}
600
601static inline void dso__set_loaded(struct dso *dso)
602{
603 RC_CHK_ACCESS(dso)->loaded = true;
604}
605
606static inline struct mutex *dso__lock(struct dso *dso)
607{
608 return &RC_CHK_ACCESS(dso)->lock;
609}
610
611static inline const char *dso__long_name(const struct dso *dso)
612{
613 return RC_CHK_ACCESS(dso)->long_name;
614}
615
616static inline bool dso__long_name_allocated(const struct dso *dso)
617{
618 return RC_CHK_ACCESS(dso)->long_name_allocated;
619}
620
621static inline void dso__set_long_name_allocated(struct dso *dso, bool allocated)
622{
623 RC_CHK_ACCESS(dso)->long_name_allocated = allocated;
624}
625
626static inline u16 dso__long_name_len(const struct dso *dso)
627{
628 return RC_CHK_ACCESS(dso)->long_name_len;
629}
630
631static inline const char *dso__name(const struct dso *dso)
632{
633 return RC_CHK_ACCESS(dso)->name;
634}
635
636static inline enum dso_swap_type dso__needs_swap(const struct dso *dso)
637{
638 return RC_CHK_ACCESS(dso)->needs_swap;
639}
640
641static inline void dso__set_needs_swap(struct dso *dso, enum dso_swap_type type)
642{
643 RC_CHK_ACCESS(dso)->needs_swap = type;
644}
645
646static inline struct nsinfo *dso__nsinfo(struct dso *dso)
647{
648 return RC_CHK_ACCESS(dso)->nsinfo;
649}
650
651static inline const struct nsinfo *dso__nsinfo_const(const struct dso *dso)
652{
653 return RC_CHK_ACCESS(dso)->nsinfo;
654}
655
656static inline struct nsinfo **dso__nsinfo_ptr(struct dso *dso)
657{
658 return &RC_CHK_ACCESS(dso)->nsinfo;
659}
660
661void dso__set_nsinfo(struct dso *dso, struct nsinfo *nsi);
662
663static inline u8 dso__rel(const struct dso *dso)
664{
665 return RC_CHK_ACCESS(dso)->rel;
666}
667
668static inline void dso__set_rel(struct dso *dso, u8 rel)
669{
670 RC_CHK_ACCESS(dso)->rel = rel;
671}
672
673static inline const char *dso__short_name(const struct dso *dso)
674{
675 return RC_CHK_ACCESS(dso)->short_name;
676}
677
678static inline bool dso__short_name_allocated(const struct dso *dso)
679{
680 return RC_CHK_ACCESS(dso)->short_name_allocated;
681}
682
683static inline void dso__set_short_name_allocated(struct dso *dso, bool allocated)
684{
685 RC_CHK_ACCESS(dso)->short_name_allocated = allocated;
686}
687
688static inline u16 dso__short_name_len(const struct dso *dso)
689{
690 return RC_CHK_ACCESS(dso)->short_name_len;
691}
692
693static inline struct rb_root_cached *dso__srclines(struct dso *dso)
694{
695 return &RC_CHK_ACCESS(dso)->srclines;
696}
697
698static inline struct rb_root *dso__data_types(struct dso *dso)
699{
700 return &RC_CHK_ACCESS(dso)->data_types;
701}
702
703static inline struct rb_root *dso__global_vars(struct dso *dso)
704{
705 return &RC_CHK_ACCESS(dso)->global_vars;
706}
707
708static inline struct rb_root_cached *dso__symbols(struct dso *dso)
709{
710 return &RC_CHK_ACCESS(dso)->symbols;
711}
712
713static inline struct symbol **dso__symbol_names(struct dso *dso)
714{
715 return RC_CHK_ACCESS(dso)->symbol_names;
716}
717
718static inline void dso__set_symbol_names(struct dso *dso, struct symbol **names)
719{
720 RC_CHK_ACCESS(dso)->symbol_names = names;
721}
722
723static inline size_t dso__symbol_names_len(struct dso *dso)
724{
725 return RC_CHK_ACCESS(dso)->symbol_names_len;
726}
727
728static inline void dso__set_symbol_names_len(struct dso *dso, size_t len)
729{
730 RC_CHK_ACCESS(dso)->symbol_names_len = len;
731}
732
733static inline const char *dso__symsrc_filename(const struct dso *dso)
734{
735 return RC_CHK_ACCESS(dso)->symsrc_filename;
736}
737
738static inline void dso__set_symsrc_filename(struct dso *dso, char *val)
739{
740 RC_CHK_ACCESS(dso)->symsrc_filename = val;
741}
742
743static inline void dso__free_symsrc_filename(struct dso *dso)
744{
745 zfree(&RC_CHK_ACCESS(dso)->symsrc_filename);
746}
747
748static inline enum dso_binary_type dso__symtab_type(const struct dso *dso)
749{
750 return RC_CHK_ACCESS(dso)->symtab_type;
751}
752
753static inline void dso__set_symtab_type(struct dso *dso, enum dso_binary_type bt)
754{
755 RC_CHK_ACCESS(dso)->symtab_type = bt;
756}
757
758static inline u64 dso__text_end(const struct dso *dso)
759{
760 return RC_CHK_ACCESS(dso)->text_end;
761}
762
763static inline void dso__set_text_end(struct dso *dso, u64 val)
764{
765 RC_CHK_ACCESS(dso)->text_end = val;
766}
767
768static inline u64 dso__text_offset(const struct dso *dso)
769{
770 return RC_CHK_ACCESS(dso)->text_offset;
771}
772
773static inline void dso__set_text_offset(struct dso *dso, u64 val)
774{
775 RC_CHK_ACCESS(dso)->text_offset = val;
776}
777
778struct dso *dso__new_id(const char *name, const struct dso_id *id);
779struct dso *dso__new(const char *name);
780void dso__delete(struct dso *dso);
781
782int dso__cmp_id(struct dso *a, struct dso *b);
783void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
784void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
785void __dso__improve_id(struct dso *dso, const struct dso_id *id);
786
787int dso__name_len(const struct dso *dso);
788
789struct dso *dso__get(struct dso *dso);
790void dso__put(struct dso *dso) LOCKS_EXCLUDED(_dso__data_open_lock);
791
792static inline void __dso__zput(struct dso **dso)
793{
794 dso__put(*dso);
795 *dso = NULL;
796}
797
798#define dso__zput(dso) __dso__zput(&dso)
799
800bool dso__loaded(const struct dso *dso);
801
802static inline bool dso__has_symbols(const struct dso *dso)
803{
804 return !RB_EMPTY_ROOT(&RC_CHK_ACCESS(dso)->symbols.rb_root);
805}
806
807char *dso__filename_with_chroot(const struct dso *dso, const char *filename);
808
809bool dso__sorted_by_name(const struct dso *dso);
810void dso__set_sorted_by_name(struct dso *dso);
811void dso__sort_by_name(struct dso *dso);
812
813int dso__swap_init(struct dso *dso, unsigned char eidata);
814
815void dso__set_build_id(struct dso *dso, const struct build_id *bid);
816bool dso__build_id_equal(const struct dso *dso, const struct build_id *bid);
817void dso__read_running_kernel_build_id(struct dso *dso,
818 struct machine *machine);
819int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
820
821char dso__symtab_origin(const struct dso *dso);
822int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
823 const char *root_dir, char *filename, size_t size);
824bool is_kernel_module(const char *pathname, int cpumode);
825bool dso__needs_decompress(struct dso *dso);
826int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
827int dso__decompress_kmodule_path(struct dso *dso, const char *name,
828 char *pathname, size_t len);
829int filename__decompress(const char *name, char *pathname,
830 size_t len, int comp, int *err);
831
832#define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX"
833#define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME)
834
835struct kmod_path {
836 char *name;
837 int comp;
838 bool kmod;
839};
840
841int __kmod_path__parse(struct kmod_path *m, const char *path,
842 bool alloc_name);
843
844#define kmod_path__parse(__m, __p) __kmod_path__parse(__m, __p, false)
845#define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true)
846
847void dso__set_module_info(struct dso *dso, struct kmod_path *m,
848 struct machine *machine);
849
850/*
851 * The dso__data_* external interface provides following functions:
852 * dso__data_get_fd
853 * dso__data_put_fd
854 * dso__data_close
855 * dso__data_size
856 * dso__data_read_offset
857 * dso__data_read_addr
858 * dso__data_write_cache_offs
859 * dso__data_write_cache_addr
860 *
861 * Please refer to the dso.c object code for each function and
862 * arguments documentation. Following text tries to explain the
863 * dso file descriptor caching.
864 *
865 * The dso__data* interface allows caching of opened file descriptors
866 * to speed up the dso data accesses. The idea is to leave the file
867 * descriptor opened ideally for the whole life of the dso object.
868 *
869 * The current usage of the dso__data_* interface is as follows:
870 *
871 * Get DSO's fd:
872 * int fd;
873 * if (dso__data_get_fd(dso, machine, &fd)) {
874 * USE 'fd' SOMEHOW
875 * dso__data_put_fd(dso);
876 * }
877 *
878 * Read DSO's data:
879 * n = dso__data_read_offset(dso_0, &machine, 0, buf, BUFSIZE);
880 * n = dso__data_read_addr(dso_0, &machine, 0, buf, BUFSIZE);
881 *
882 * Eventually close DSO's fd:
883 * dso__data_close(dso);
884 *
885 * It is not necessary to close the DSO object data file. Each time new
886 * DSO data file is opened, the limit (RLIMIT_NOFILE/2) is checked. Once
887 * it is crossed, the oldest opened DSO object is closed.
888 *
889 * The dso__delete function calls close_dso function to ensure the
890 * data file descriptor gets closed/unmapped before the dso object
891 * is freed.
892 *
893 * TODO
894*/
895bool dso__data_get_fd(struct dso *dso, struct machine *machine, int *fd)
896 EXCLUSIVE_TRYLOCK_FUNCTION(true, _dso__data_open_lock);
897void dso__data_put_fd(struct dso *dso) UNLOCK_FUNCTION(_dso__data_open_lock);
898void dso__data_close(struct dso *dso) LOCKS_EXCLUDED(_dso__data_open_lock);
899
900int dso__data_file_size(struct dso *dso, struct machine *machine);
901off_t dso__data_size(struct dso *dso, struct machine *machine);
902ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
903 u64 offset, u8 *data, ssize_t size);
904uint16_t dso__read_e_machine_endian(struct dso *optional_dso, int fd, uint32_t *e_flags,
905 bool *is_big_endian);
906static inline uint16_t dso__read_e_machine(struct dso *optional_dso, int fd, uint32_t *e_flags)
907{
908 return dso__read_e_machine_endian(optional_dso, fd, e_flags, NULL);
909}
910uint16_t dso__e_machine_endian(struct dso *dso, struct machine *machine, uint32_t *e_flags,
911 bool *is_big_endian);
912static inline uint16_t dso__e_machine(struct dso *dso, struct machine *machine, uint32_t *e_flags)
913{
914 return dso__e_machine_endian(dso, machine, e_flags, NULL);
915}
916ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
917 struct machine *machine, u64 addr,
918 u8 *data, ssize_t size);
919bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by);
920ssize_t dso__data_write_cache_offs(struct dso *dso, struct machine *machine,
921 u64 offset, const u8 *data, ssize_t size);
922ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
923 struct machine *machine, u64 addr,
924 const u8 *data, ssize_t size);
925
926struct map *dso__new_map(const char *name);
927struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
928 const char *short_name, int dso_type);
929
930void dso__reset_find_symbol_cache(struct dso *dso);
931
932size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
933size_t dso__fprintf(struct dso *dso, FILE *fp);
934
935static inline enum dso_binary_type dso__binary_type(const struct dso *dso)
936{
937 return RC_CHK_ACCESS(dso)->binary_type;
938}
939
940static inline void dso__set_binary_type(struct dso *dso, enum dso_binary_type bt)
941{
942 RC_CHK_ACCESS(dso)->binary_type = bt;
943}
944
945static inline bool dso__is_vmlinux(const struct dso *dso)
946{
947 enum dso_binary_type bt = dso__binary_type(dso);
948
949 return bt == DSO_BINARY_TYPE__VMLINUX || bt == DSO_BINARY_TYPE__GUEST_VMLINUX;
950}
951
952static inline bool dso__is_kcore(const struct dso *dso)
953{
954 enum dso_binary_type bt = dso__binary_type(dso);
955
956 return bt == DSO_BINARY_TYPE__KCORE || bt == DSO_BINARY_TYPE__GUEST_KCORE;
957}
958
959static inline bool dso__is_kallsyms(const struct dso *dso)
960{
961 enum dso_binary_type bt = dso__binary_type(dso);
962 const char *name;
963
964 if (bt == DSO_BINARY_TYPE__KALLSYMS || bt == DSO_BINARY_TYPE__GUEST_KALLSYMS)
965 return true;
966
967 if (bt != DSO_BINARY_TYPE__NOT_FOUND)
968 return false;
969
970 if (!dso__kernel(dso))
971 return false;
972
973 name = dso__long_name(dso);
974 if (!name)
975 return false;
976
977 if (!strcmp(name, DSO__NAME_KALLSYMS))
978 return true;
979
980 if (!strcmp(name, DSO__NAME_GUEST_KALLSYMS))
981 return true;
982
983 return is_guest_kallsyms_pid_name(name);
984}
985
986bool dso__is_object_file(const struct dso *dso);
987
988void dso__free_a2l(struct dso *dso);
989
990enum dso_type dso__type(struct dso *dso, struct machine *machine);
991
992int dso__strerror_load(struct dso *dso, char *buf, size_t buflen);
993
994void reset_fd_limit(void);
995
996u64 dso__find_global_type(struct dso *dso, u64 addr);
997u64 dso__findnew_global_type(struct dso *dso, u64 addr, u64 offset);
998
999/* Check if dso name is of format "/tmp/perf-%d.map" */
1000bool perf_pid_map_tid(const char *dso_name, int *tid);
1001bool is_perf_pid_map_name(const char *dso_name);
1002
1003struct debuginfo *dso__debuginfo(struct dso *dso);
1004
1005const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
1006 const struct map *map, const struct symbol *sym,
1007 u8 **out_buf, u64 *out_buf_len, bool *is_64bit);
1008
1009#endif /* __PERF_DSO */