probe-finder.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
  38. bool adjust_offset);
  39. /* Find a line range */
  40. int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr);
  41. /* Find available variables */
  42. int debuginfo__find_available_vars_at(struct debuginfo *dbg,
  43. struct perf_probe_event *pev,
  44. struct variable_list **vls);
  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. /* Call Frame Information from .eh_frame */
  62. Dwarf_CFI *cfi_eh;
  63. /* Call Frame Information from .debug_frame */
  64. Dwarf_CFI *cfi_dbg;
  65. #endif
  66. Dwarf_Op *fb_ops; /* Frame base attribute */
  67. unsigned int machine; /* Target machine arch */
  68. struct perf_probe_arg *pvar; /* Current target variable */
  69. struct probe_trace_arg *tvar; /* Current result variable */
  70. };
  71. struct trace_event_finder {
  72. struct probe_finder pf;
  73. Dwfl_Module *mod; /* For solving symbols */
  74. struct probe_trace_event *tevs; /* Found trace events */
  75. int ntevs; /* Number of trace events */
  76. int max_tevs; /* Max number of trace events */
  77. };
  78. struct available_var_finder {
  79. struct probe_finder pf;
  80. Dwfl_Module *mod; /* For solving symbols */
  81. struct variable_list *vls; /* Found variable lists */
  82. int nvls; /* Number of variable lists */
  83. int max_vls; /* Max no. of variable lists */
  84. bool child; /* Search child scopes */
  85. };
  86. struct line_finder {
  87. struct line_range *lr; /* Target line range */
  88. const char *fname; /* File name */
  89. int lno_s; /* Start line number */
  90. int lno_e; /* End line number */
  91. Dwarf_Die cu_die; /* Current CU */
  92. Dwarf_Die sp_die;
  93. int found;
  94. };
  95. #endif /* HAVE_DWARF_SUPPORT */
  96. #endif /*_PROBE_FINDER_H */