probe-finder.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _PROBE_FINDER_H
  3. #define _PROBE_FINDER_H
  4. #include <stdbool.h>
  5. #include "intlist.h"
  6. #include "probe-event.h"
  7. #include "sane_ctype.h"
  8. #define MAX_PROBE_BUFFER 1024
  9. #define MAX_PROBES 128
  10. #define MAX_PROBE_ARGS 128
  11. #define PROBE_ARG_VARS "$vars"
  12. #define PROBE_ARG_PARAMS "$params"
  13. static inline int is_c_varname(const char *name)
  14. {
  15. /* TODO */
  16. return isalpha(name[0]) || name[0] == '_';
  17. }
  18. #ifdef HAVE_DWARF_SUPPORT
  19. #include "dwarf-aux.h"
  20. /* TODO: export debuginfo data structure even if no dwarf support */
  21. /* debug information structure */
  22. struct debuginfo {
  23. Dwarf *dbg;
  24. Dwfl_Module *mod;
  25. Dwfl *dwfl;
  26. Dwarf_Addr bias;
  27. };
  28. /* This also tries to open distro debuginfo */
  29. struct debuginfo *debuginfo__new(const char *path);
  30. void debuginfo__delete(struct debuginfo *dbg);
  31. /* Find probe_trace_events specified by perf_probe_event from debuginfo */
  32. int debuginfo__find_trace_events(struct debuginfo *dbg,
  33. struct perf_probe_event *pev,
  34. struct probe_trace_event **tevs);
  35. /* Find a perf_probe_point from debuginfo */
  36. int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
  37. struct perf_probe_point *ppt);
  38. int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
  39. bool adjust_offset);
  40. /* Find a line range */
  41. int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr);
  42. /* Find available variables */
  43. int debuginfo__find_available_vars_at(struct debuginfo *dbg,
  44. struct perf_probe_event *pev,
  45. struct variable_list **vls);
  46. /* Find a src file from a DWARF tag path */
  47. int get_real_path(const char *raw_path, const char *comp_dir,
  48. char **new_path);
  49. struct probe_finder {
  50. struct perf_probe_event *pev; /* Target probe event */
  51. /* Callback when a probe point is found */
  52. int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
  53. /* For function searching */
  54. int lno; /* Line number */
  55. Dwarf_Addr addr; /* Address */
  56. const char *fname; /* Real file name */
  57. Dwarf_Die cu_die; /* Current CU */
  58. Dwarf_Die sp_die;
  59. struct intlist *lcache; /* Line cache for lazy match */
  60. /* For variable searching */
  61. #if _ELFUTILS_PREREQ(0, 142)
  62. /* Call Frame Information from .eh_frame */
  63. Dwarf_CFI *cfi_eh;
  64. /* Call Frame Information from .debug_frame */
  65. Dwarf_CFI *cfi_dbg;
  66. #endif
  67. Dwarf_Op *fb_ops; /* Frame base attribute */
  68. unsigned int machine; /* Target machine arch */
  69. struct perf_probe_arg *pvar; /* Current target variable */
  70. struct probe_trace_arg *tvar; /* Current result variable */
  71. };
  72. struct trace_event_finder {
  73. struct probe_finder pf;
  74. Dwfl_Module *mod; /* For solving symbols */
  75. struct probe_trace_event *tevs; /* Found trace events */
  76. int ntevs; /* Number of trace events */
  77. int max_tevs; /* Max number of trace events */
  78. };
  79. struct available_var_finder {
  80. struct probe_finder pf;
  81. Dwfl_Module *mod; /* For solving symbols */
  82. struct variable_list *vls; /* Found variable lists */
  83. int nvls; /* Number of variable lists */
  84. int max_vls; /* Max no. of variable lists */
  85. bool child; /* Search child scopes */
  86. };
  87. struct line_finder {
  88. struct line_range *lr; /* Target line range */
  89. const char *fname; /* File name */
  90. int lno_s; /* Start line number */
  91. int lno_e; /* End line number */
  92. Dwarf_Die cu_die; /* Current CU */
  93. Dwarf_Die sp_die;
  94. int found;
  95. };
  96. #endif /* HAVE_DWARF_SUPPORT */
  97. #endif /*_PROBE_FINDER_H */