probe-finder.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef _PROBE_FINDER_H
  2. #define _PROBE_FINDER_H
  3. #define _stringify(n) #n
  4. #define stringify(n) _stringify(n)
  5. #ifdef DEBUG
  6. #define debug(fmt ...) \
  7. fprintf(stderr, "DBG(" __FILE__ ":" stringify(__LINE__) "): " fmt)
  8. #else
  9. #define debug(fmt ...) do {} while (0)
  10. #endif
  11. #define ERR_IF(cnd) \
  12. do { if (cnd) { \
  13. fprintf(stderr, "Error (" __FILE__ ":" stringify(__LINE__) \
  14. "): " stringify(cnd) "\n"); \
  15. exit(1); \
  16. } } while (0)
  17. #define MAX_PATH_LEN 256
  18. #define MAX_PROBE_BUFFER 1024
  19. #define MAX_PROBES 128
  20. static inline int is_c_varname(const char *name)
  21. {
  22. /* TODO */
  23. return isalpha(name[0]) || name[0] == '_';
  24. }
  25. struct probe_point {
  26. /* Inputs */
  27. char *file; /* File name */
  28. int line; /* Line number */
  29. char *function; /* Function name */
  30. int offset; /* Offset bytes */
  31. int nr_args; /* Number of arguments */
  32. char **args; /* Arguments */
  33. /* Output */
  34. int found; /* Number of found probe points */
  35. char *probes[MAX_PROBES]; /* Output buffers (will be allocated)*/
  36. };
  37. #ifndef NO_LIBDWARF
  38. extern int find_probepoint(int fd, struct probe_point *pp);
  39. #include <libdwarf/dwarf.h>
  40. #include <libdwarf/libdwarf.h>
  41. struct probe_finder {
  42. struct probe_point *pp; /* Target probe point */
  43. /* For function searching */
  44. Dwarf_Addr addr; /* Address */
  45. Dwarf_Unsigned fno; /* File number */
  46. Dwarf_Off inl_offs; /* Inline offset */
  47. /* For variable searching */
  48. Dwarf_Addr cu_base; /* Current CU base address */
  49. Dwarf_Locdesc fbloc; /* Location of Current Frame Base */
  50. const char *var; /* Current variable name */
  51. char *buf; /* Current output buffer */
  52. int len; /* Length of output buffer */
  53. };
  54. #endif /* NO_LIBDWARF */
  55. #endif /*_PROBE_FINDER_H */