dso.h 24 KB

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