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