probe-finder.h 3.2 KB

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