trace_probe.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Common header file for probe-based Dynamic events.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. *
  17. * This code was copied from kernel/trace/trace_kprobe.h written by
  18. * Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
  19. *
  20. * Updates to make this generic:
  21. * Copyright (C) IBM Corporation, 2010-2011
  22. * Author: Srikar Dronamraju
  23. */
  24. #include <linux/seq_file.h>
  25. #include <linux/slab.h>
  26. #include <linux/smp.h>
  27. #include <linux/debugfs.h>
  28. #include <linux/types.h>
  29. #include <linux/string.h>
  30. #include <linux/ctype.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/perf_event.h>
  33. #include <linux/kprobes.h>
  34. #include <linux/stringify.h>
  35. #include <linux/limits.h>
  36. #include <linux/uaccess.h>
  37. #include <asm/bitsperlong.h>
  38. #include "trace.h"
  39. #include "trace_output.h"
  40. #define MAX_TRACE_ARGS 128
  41. #define MAX_ARGSTR_LEN 63
  42. #define MAX_EVENT_NAME_LEN 64
  43. #define MAX_STRING_SIZE PATH_MAX
  44. /* Reserved field names */
  45. #define FIELD_STRING_IP "__probe_ip"
  46. #define FIELD_STRING_RETIP "__probe_ret_ip"
  47. #define FIELD_STRING_FUNC "__probe_func"
  48. #undef DEFINE_FIELD
  49. #define DEFINE_FIELD(type, item, name, is_signed) \
  50. do { \
  51. ret = trace_define_field(event_call, #type, name, \
  52. offsetof(typeof(field), item), \
  53. sizeof(field.item), is_signed, \
  54. FILTER_OTHER); \
  55. if (ret) \
  56. return ret; \
  57. } while (0)
  58. /* Flags for trace_probe */
  59. #define TP_FLAG_TRACE 1
  60. #define TP_FLAG_PROFILE 2
  61. #define TP_FLAG_REGISTERED 4
  62. #define TP_FLAG_UPROBE 8
  63. /* data_rloc: data relative location, compatible with u32 */
  64. #define make_data_rloc(len, roffs) \
  65. (((u32)(len) << 16) | ((u32)(roffs) & 0xffff))
  66. #define get_rloc_len(dl) ((u32)(dl) >> 16)
  67. #define get_rloc_offs(dl) ((u32)(dl) & 0xffff)
  68. /*
  69. * Convert data_rloc to data_loc:
  70. * data_rloc stores the offset from data_rloc itself, but data_loc
  71. * stores the offset from event entry.
  72. */
  73. #define convert_rloc_to_loc(dl, offs) ((u32)(dl) + (offs))
  74. /* Data fetch function type */
  75. typedef void (*fetch_func_t)(struct pt_regs *, void *, void *);
  76. /* Printing function type */
  77. typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *, void *);
  78. /* Fetch types */
  79. enum {
  80. FETCH_MTD_reg = 0,
  81. FETCH_MTD_stack,
  82. FETCH_MTD_retval,
  83. FETCH_MTD_memory,
  84. FETCH_MTD_symbol,
  85. FETCH_MTD_deref,
  86. FETCH_MTD_bitfield,
  87. FETCH_MTD_END,
  88. };
  89. /* Fetch type information table */
  90. struct fetch_type {
  91. const char *name; /* Name of type */
  92. size_t size; /* Byte size of type */
  93. int is_signed; /* Signed flag */
  94. print_type_func_t print; /* Print functions */
  95. const char *fmt; /* Fromat string */
  96. const char *fmttype; /* Name in format file */
  97. /* Fetch functions */
  98. fetch_func_t fetch[FETCH_MTD_END];
  99. };
  100. struct fetch_param {
  101. fetch_func_t fn;
  102. void *data;
  103. };
  104. struct probe_arg {
  105. struct fetch_param fetch;
  106. struct fetch_param fetch_size;
  107. unsigned int offset; /* Offset from argument entry */
  108. const char *name; /* Name of this argument */
  109. const char *comm; /* Command of this argument */
  110. const struct fetch_type *type; /* Type of this argument */
  111. };
  112. static inline __kprobes void call_fetch(struct fetch_param *fprm,
  113. struct pt_regs *regs, void *dest)
  114. {
  115. return fprm->fn(regs, fprm->data, dest);
  116. }
  117. /* Check the name is good for event/group/fields */
  118. static inline int is_good_name(const char *name)
  119. {
  120. if (!isalpha(*name) && *name != '_')
  121. return 0;
  122. while (*++name != '\0') {
  123. if (!isalpha(*name) && !isdigit(*name) && *name != '_')
  124. return 0;
  125. }
  126. return 1;
  127. }
  128. extern int traceprobe_parse_probe_arg(char *arg, ssize_t *size,
  129. struct probe_arg *parg, bool is_return, bool is_kprobe);
  130. extern int traceprobe_conflict_field_name(const char *name,
  131. struct probe_arg *args, int narg);
  132. extern void traceprobe_update_arg(struct probe_arg *arg);
  133. extern void traceprobe_free_probe_arg(struct probe_arg *arg);
  134. extern int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset);
  135. extern ssize_t traceprobe_probes_write(struct file *file,
  136. const char __user *buffer, size_t count, loff_t *ppos,
  137. int (*createfn)(int, char**));
  138. extern int traceprobe_command(const char *buf, int (*createfn)(int, char**));