probe-finder.h 3.2 KB

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