parse-events.y 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. %name-prefix "parse_events_"
  2. %parse-param {struct list_head *list_all}
  3. %parse-param {struct list_head *list_event}
  4. %parse-param {int *idx}
  5. %{
  6. #define YYDEBUG 1
  7. #include <linux/compiler.h>
  8. #include <linux/list.h>
  9. #include "types.h"
  10. #include "util.h"
  11. #include "parse-events.h"
  12. extern int parse_events_lex (void);
  13. #define ABORT_ON(val) \
  14. do { \
  15. if (val) \
  16. YYABORT; \
  17. } while (0)
  18. %}
  19. %token PE_VALUE PE_VALUE_SYM PE_RAW PE_TERM
  20. %token PE_NAME
  21. %token PE_MODIFIER_EVENT PE_MODIFIER_BP
  22. %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
  23. %token PE_PREFIX_MEM PE_PREFIX_RAW
  24. %token PE_ERROR
  25. %type <num> PE_VALUE
  26. %type <num> PE_VALUE_SYM
  27. %type <num> PE_RAW
  28. %type <num> PE_TERM
  29. %type <str> PE_NAME
  30. %type <str> PE_NAME_CACHE_TYPE
  31. %type <str> PE_NAME_CACHE_OP_RESULT
  32. %type <str> PE_MODIFIER_EVENT
  33. %type <str> PE_MODIFIER_BP
  34. %type <head> event_config
  35. %type <term> event_term
  36. %union
  37. {
  38. char *str;
  39. unsigned long num;
  40. struct list_head *head;
  41. struct parse_events__term *term;
  42. }
  43. %%
  44. events:
  45. events ',' event | event
  46. event:
  47. event_def PE_MODIFIER_EVENT
  48. {
  49. /*
  50. * Apply modifier on all events added by single event definition
  51. * (there could be more events added for multiple tracepoint
  52. * definitions via '*?'.
  53. */
  54. ABORT_ON(parse_events_modifier(list_event, $2));
  55. parse_events_update_lists(list_event, list_all);
  56. }
  57. |
  58. event_def
  59. {
  60. parse_events_update_lists(list_event, list_all);
  61. }
  62. event_def: event_pmu |
  63. event_legacy_symbol |
  64. event_legacy_cache sep_dc |
  65. event_legacy_mem |
  66. event_legacy_tracepoint sep_dc |
  67. event_legacy_numeric sep_dc |
  68. event_legacy_raw sep_dc
  69. event_pmu:
  70. PE_NAME '/' event_config '/'
  71. {
  72. ABORT_ON(parse_events_add_pmu(list_event, idx, $1, $3));
  73. parse_events__free_terms($3);
  74. }
  75. event_legacy_symbol:
  76. PE_VALUE_SYM '/' event_config '/'
  77. {
  78. int type = $1 >> 16;
  79. int config = $1 & 255;
  80. ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, $3));
  81. parse_events__free_terms($3);
  82. }
  83. |
  84. PE_VALUE_SYM sep_slash_dc
  85. {
  86. int type = $1 >> 16;
  87. int config = $1 & 255;
  88. ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, NULL));
  89. }
  90. event_legacy_cache:
  91. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
  92. {
  93. ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, $5));
  94. }
  95. |
  96. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
  97. {
  98. ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, NULL));
  99. }
  100. |
  101. PE_NAME_CACHE_TYPE
  102. {
  103. ABORT_ON(parse_events_add_cache(list_event, idx, $1, NULL, NULL));
  104. }
  105. event_legacy_mem:
  106. PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
  107. {
  108. ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, $4));
  109. }
  110. |
  111. PE_PREFIX_MEM PE_VALUE sep_dc
  112. {
  113. ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, NULL));
  114. }
  115. event_legacy_tracepoint:
  116. PE_NAME ':' PE_NAME
  117. {
  118. ABORT_ON(parse_events_add_tracepoint(list_event, idx, $1, $3));
  119. }
  120. event_legacy_numeric:
  121. PE_VALUE ':' PE_VALUE
  122. {
  123. ABORT_ON(parse_events_add_numeric(list_event, idx, $1, $3, NULL));
  124. }
  125. event_legacy_raw:
  126. PE_RAW
  127. {
  128. ABORT_ON(parse_events_add_numeric(list_event, idx, PERF_TYPE_RAW, $1, NULL));
  129. }
  130. event_config:
  131. event_config ',' event_term
  132. {
  133. struct list_head *head = $1;
  134. struct parse_events__term *term = $3;
  135. ABORT_ON(!head);
  136. list_add_tail(&term->list, head);
  137. $$ = $1;
  138. }
  139. |
  140. event_term
  141. {
  142. struct list_head *head = malloc(sizeof(*head));
  143. struct parse_events__term *term = $1;
  144. ABORT_ON(!head);
  145. INIT_LIST_HEAD(head);
  146. list_add_tail(&term->list, head);
  147. $$ = head;
  148. }
  149. event_term:
  150. PE_NAME '=' PE_NAME
  151. {
  152. struct parse_events__term *term;
  153. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_STR,
  154. $1, $3, 0));
  155. $$ = term;
  156. }
  157. |
  158. PE_NAME '=' PE_VALUE
  159. {
  160. struct parse_events__term *term;
  161. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_NUM,
  162. $1, NULL, $3));
  163. $$ = term;
  164. }
  165. |
  166. PE_NAME
  167. {
  168. struct parse_events__term *term;
  169. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_NUM,
  170. $1, NULL, 1));
  171. $$ = term;
  172. }
  173. |
  174. PE_TERM '=' PE_VALUE
  175. {
  176. struct parse_events__term *term;
  177. ABORT_ON(parse_events__new_term(&term, $1, NULL, NULL, $3));
  178. $$ = term;
  179. }
  180. |
  181. PE_TERM
  182. {
  183. struct parse_events__term *term;
  184. ABORT_ON(parse_events__new_term(&term, $1, NULL, NULL, 1));
  185. $$ = term;
  186. }
  187. sep_dc: ':' |
  188. sep_slash_dc: '/' | ':' |
  189. %%
  190. void parse_events_error(struct list_head *list_all __used,
  191. struct list_head *list_event __used,
  192. int *idx __used,
  193. char const *msg __used)
  194. {
  195. }