1 %define api.pure full 1 %define api.pure full 2 %parse-param {void *_parse_state} 2 %parse-param {void *_parse_state} 3 %parse-param {void *scanner} 3 %parse-param {void *scanner} 4 %lex-param {void* scanner} 4 %lex-param {void* scanner} 5 %locations 5 %locations 6 6 7 %{ 7 %{ 8 8 9 #ifndef NDEBUG << 10 #define YYDEBUG 1 9 #define YYDEBUG 1 11 #endif << 12 10 13 #include <errno.h> !! 11 #include <fnmatch.h> >> 12 #include <stdio.h> 14 #include <linux/compiler.h> 13 #include <linux/compiler.h> 15 #include <linux/types.h> 14 #include <linux/types.h> >> 15 #include <linux/zalloc.h> 16 #include "pmu.h" 16 #include "pmu.h" 17 #include "pmus.h" << 18 #include "evsel.h" 17 #include "evsel.h" 19 #include "parse-events.h" 18 #include "parse-events.h" 20 #include "parse-events-bison.h" 19 #include "parse-events-bison.h" 21 20 22 int parse_events_lex(YYSTYPE * yylval_param, Y << 23 void parse_events_error(YYLTYPE *loc, void *pa 21 void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); 24 22 25 #define PE_ABORT(val) \ !! 23 #define ABORT_ON(val) \ 26 do { \ 24 do { \ 27 if (val == -ENOMEM) \ !! 25 if (val) \ 28 YYNOMEM; \ !! 26 YYABORT; \ 29 YYABORT; \ << 30 } while (0) 27 } while (0) 31 28 32 static struct list_head* alloc_list(void) 29 static struct list_head* alloc_list(void) 33 { 30 { 34 struct list_head *list; 31 struct list_head *list; 35 32 36 list = malloc(sizeof(*list)); 33 list = malloc(sizeof(*list)); 37 if (!list) 34 if (!list) 38 return NULL; 35 return NULL; 39 36 40 INIT_LIST_HEAD(list); 37 INIT_LIST_HEAD(list); 41 return list; 38 return list; 42 } 39 } 43 40 44 static void free_list_evsel(struct list_head* 41 static void free_list_evsel(struct list_head* list_evsel) 45 { 42 { 46 struct evsel *evsel, *tmp; 43 struct evsel *evsel, *tmp; 47 44 48 list_for_each_entry_safe(evsel, tmp, l 45 list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) { 49 list_del_init(&evsel->core.nod 46 list_del_init(&evsel->core.node); 50 evsel__delete(evsel); 47 evsel__delete(evsel); 51 } 48 } 52 free(list_evsel); 49 free(list_evsel); 53 } 50 } 54 51 >> 52 static void inc_group_count(struct list_head *list, >> 53 struct parse_events_state *parse_state) >> 54 { >> 55 /* Count groups only have more than 1 members */ >> 56 if (!list_is_last(list->next, list)) >> 57 parse_state->nr_groups++; >> 58 } >> 59 55 %} 60 %} 56 61 57 %token PE_START_EVENTS PE_START_TERMS 62 %token PE_START_EVENTS PE_START_TERMS 58 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_S !! 63 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM 59 %token PE_VALUE_SYM_TOOL 64 %token PE_VALUE_SYM_TOOL 60 %token PE_EVENT_NAME 65 %token PE_EVENT_NAME 61 %token PE_RAW PE_NAME !! 66 %token PE_NAME 62 %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_ !! 67 %token PE_BPF_OBJECT PE_BPF_SOURCE 63 %token PE_LEGACY_CACHE !! 68 %token PE_MODIFIER_EVENT PE_MODIFIER_BP 64 %token PE_PREFIX_MEM !! 69 %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT >> 70 %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP 65 %token PE_ERROR 71 %token PE_ERROR >> 72 %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT >> 73 %token PE_ARRAY_ALL PE_ARRAY_RANGE 66 %token PE_DRV_CFG_TERM 74 %token PE_DRV_CFG_TERM 67 %token PE_TERM_HW << 68 %type <num> PE_VALUE 75 %type <num> PE_VALUE 69 %type <num> PE_VALUE_SYM_HW 76 %type <num> PE_VALUE_SYM_HW 70 %type <num> PE_VALUE_SYM_SW 77 %type <num> PE_VALUE_SYM_SW 71 %type <num> PE_VALUE_SYM_TOOL 78 %type <num> PE_VALUE_SYM_TOOL 72 %type <mod> PE_MODIFIER_EVENT !! 79 %type <num> PE_RAW 73 %type <term_type> PE_TERM !! 80 %type <num> PE_TERM 74 %type <num> value_sym 81 %type <num> value_sym 75 %type <str> PE_RAW << 76 %type <str> PE_NAME 82 %type <str> PE_NAME 77 %type <str> PE_LEGACY_CACHE !! 83 %type <str> PE_BPF_OBJECT >> 84 %type <str> PE_BPF_SOURCE >> 85 %type <str> PE_NAME_CACHE_TYPE >> 86 %type <str> PE_NAME_CACHE_OP_RESULT >> 87 %type <str> PE_MODIFIER_EVENT 78 %type <str> PE_MODIFIER_BP 88 %type <str> PE_MODIFIER_BP 79 %type <str> PE_EVENT_NAME 89 %type <str> PE_EVENT_NAME >> 90 %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT 80 %type <str> PE_DRV_CFG_TERM 91 %type <str> PE_DRV_CFG_TERM 81 %type <str> name_or_raw << 82 %destructor { free ($$); } <str> 92 %destructor { free ($$); } <str> 83 %type <term> event_term 93 %type <term> event_term 84 %destructor { parse_events_term__delete ($$); 94 %destructor { parse_events_term__delete ($$); } <term> 85 %type <list_terms> event_config 95 %type <list_terms> event_config 86 %type <list_terms> opt_event_config 96 %type <list_terms> opt_event_config 87 %type <list_terms> opt_pmu_config 97 %type <list_terms> opt_pmu_config 88 %destructor { parse_events_terms__delete ($$); 98 %destructor { parse_events_terms__delete ($$); } <list_terms> 89 %type <list_evsel> event_pmu 99 %type <list_evsel> event_pmu 90 %type <list_evsel> event_legacy_symbol 100 %type <list_evsel> event_legacy_symbol 91 %type <list_evsel> event_legacy_cache 101 %type <list_evsel> event_legacy_cache 92 %type <list_evsel> event_legacy_mem 102 %type <list_evsel> event_legacy_mem 93 %type <list_evsel> event_legacy_tracepoint 103 %type <list_evsel> event_legacy_tracepoint 94 %type <list_evsel> event_legacy_numeric 104 %type <list_evsel> event_legacy_numeric 95 %type <list_evsel> event_legacy_raw 105 %type <list_evsel> event_legacy_raw >> 106 %type <list_evsel> event_bpf_file 96 %type <list_evsel> event_def 107 %type <list_evsel> event_def 97 %type <list_evsel> event_mod 108 %type <list_evsel> event_mod 98 %type <list_evsel> event_name 109 %type <list_evsel> event_name 99 %type <list_evsel> event 110 %type <list_evsel> event 100 %type <list_evsel> events 111 %type <list_evsel> events 101 %type <list_evsel> group_def 112 %type <list_evsel> group_def 102 %type <list_evsel> group 113 %type <list_evsel> group 103 %type <list_evsel> groups 114 %type <list_evsel> groups 104 %destructor { free_list_evsel ($$); } <list_ev 115 %destructor { free_list_evsel ($$); } <list_evsel> 105 %type <tracepoint_name> tracepoint_name 116 %type <tracepoint_name> tracepoint_name 106 %destructor { free ($$.sys); free ($$.event); 117 %destructor { free ($$.sys); free ($$.event); } <tracepoint_name> 107 %type <hardware_term> PE_TERM_HW !! 118 %type <array> array 108 %destructor { free ($$.str); } <hardware_term> !! 119 %type <array> array_term >> 120 %type <array> array_terms >> 121 %destructor { free ($$.ranges); } <array> 109 122 110 %union 123 %union 111 { 124 { 112 char *str; 125 char *str; 113 u64 num; 126 u64 num; 114 struct parse_events_modifier mod; << 115 enum parse_events__term_type term_type << 116 struct list_head *list_evsel; 127 struct list_head *list_evsel; 117 struct parse_events_terms *list_terms; !! 128 struct list_head *list_terms; 118 struct parse_events_term *term; 129 struct parse_events_term *term; 119 struct tracepoint_name { 130 struct tracepoint_name { 120 char *sys; 131 char *sys; 121 char *event; 132 char *event; 122 } tracepoint_name; 133 } tracepoint_name; 123 struct hardware_term { !! 134 struct parse_events_array array; 124 char *str; << 125 u64 num; << 126 } hardware_term; << 127 } 135 } 128 %% 136 %% 129 137 130 /* << 131 * Entry points. We are either parsing events << 132 * parsing is used for parsing events in sysf << 133 */ << 134 start: 138 start: 135 PE_START_EVENTS start_events 139 PE_START_EVENTS start_events 136 | 140 | 137 PE_START_TERMS start_terms 141 PE_START_TERMS start_terms 138 142 139 start_events: groups 143 start_events: groups 140 { 144 { 141 /* Take the parsed events, groups.. an << 142 struct list_head *groups = $1; << 143 struct parse_events_state *parse_state 145 struct parse_events_state *parse_state = _parse_state; 144 146 145 list_splice_tail(groups, &parse_state- !! 147 /* frees $1 */ 146 free(groups); !! 148 parse_events_update_lists($1, &parse_state->list); 147 } 149 } 148 150 149 groups: /* A list of groups or events. */ !! 151 groups: 150 groups ',' group 152 groups ',' group 151 { 153 { 152 /* Merge group into the list of events !! 154 struct list_head *list = $1; 153 struct list_head *groups = $1; !! 155 struct list_head *group = $3; 154 struct list_head *group = $3; !! 156 155 !! 157 /* frees $3 */ 156 list_splice_tail(group, groups); !! 158 parse_events_update_lists(group, list); 157 free(group); !! 159 $$ = list; 158 $$ = groups; << 159 } 160 } 160 | 161 | 161 groups ',' event 162 groups ',' event 162 { 163 { 163 /* Merge event into the list of events !! 164 struct list_head *list = $1; 164 struct list_head *groups = $1; << 165 struct list_head *event = $3; 165 struct list_head *event = $3; 166 166 167 !! 167 /* frees $3 */ 168 list_splice_tail(event, groups); !! 168 parse_events_update_lists(event, list); 169 free(event); !! 169 $$ = list; 170 $$ = groups; << 171 } 170 } 172 | 171 | 173 group 172 group 174 | 173 | 175 event 174 event 176 175 177 group: 176 group: 178 group_def ':' PE_MODIFIER_EVENT 177 group_def ':' PE_MODIFIER_EVENT 179 { 178 { 180 /* Apply the modifier to the events in << 181 struct list_head *list = $1; 179 struct list_head *list = $1; 182 int err; 180 int err; 183 181 184 err = parse_events__modifier_group(_pa !! 182 err = parse_events__modifier_group(list, $3); 185 if (err) !! 183 free($3); >> 184 if (err) { >> 185 free_list_evsel(list); 186 YYABORT; 186 YYABORT; >> 187 } 187 $$ = list; 188 $$ = list; 188 } 189 } 189 | 190 | 190 group_def 191 group_def 191 192 192 group_def: 193 group_def: 193 PE_NAME '{' events '}' 194 PE_NAME '{' events '}' 194 { 195 { 195 struct list_head *list = $3; 196 struct list_head *list = $3; 196 197 197 /* !! 198 inc_group_count(list, _parse_state); 198 * Set the first entry of list to be t !! 199 parse_events__set_leader($1, list, _parse_state); 199 * the leader to $1 taking ownership. !! 200 free($1); 200 */ << 201 parse_events__set_leader($1, list); << 202 $$ = list; 201 $$ = list; 203 } 202 } 204 | 203 | 205 '{' events '}' 204 '{' events '}' 206 { 205 { 207 struct list_head *list = $2; 206 struct list_head *list = $2; 208 207 209 /* Set the first entry of list to be t !! 208 inc_group_count(list, _parse_state); 210 parse_events__set_leader(NULL, list); !! 209 parse_events__set_leader(NULL, list, _parse_state); 211 $$ = list; 210 $$ = list; 212 } 211 } 213 212 214 events: 213 events: 215 events ',' event 214 events ',' event 216 { 215 { 217 struct list_head *events = $1; << 218 struct list_head *event = $3; 216 struct list_head *event = $3; >> 217 struct list_head *list = $1; 219 218 220 list_splice_tail(event, events); !! 219 /* frees $3 */ 221 free(event); !! 220 parse_events_update_lists(event, list); 222 $$ = events; !! 221 $$ = list; 223 } 222 } 224 | 223 | 225 event 224 event 226 225 227 event: event_mod 226 event: event_mod 228 227 229 event_mod: 228 event_mod: 230 event_name PE_MODIFIER_EVENT 229 event_name PE_MODIFIER_EVENT 231 { 230 { 232 struct list_head *list = $1; 231 struct list_head *list = $1; 233 int err; 232 int err; 234 233 235 /* 234 /* 236 * Apply modifier on all events added 235 * Apply modifier on all events added by single event definition 237 * (there could be more events added f 236 * (there could be more events added for multiple tracepoint 238 * definitions via '*?'. 237 * definitions via '*?'. 239 */ 238 */ 240 err = parse_events__modifier_event(_pa !! 239 err = parse_events__modifier_event(list, $2, false); 241 if (err) !! 240 free($2); >> 241 if (err) { >> 242 free_list_evsel(list); 242 YYABORT; 243 YYABORT; >> 244 } 243 $$ = list; 245 $$ = list; 244 } 246 } 245 | 247 | 246 event_name 248 event_name 247 249 248 event_name: 250 event_name: 249 PE_EVENT_NAME event_def 251 PE_EVENT_NAME event_def 250 { 252 { 251 /* !! 253 int err; 252 * When an event is parsed the text is << 253 * the event is set to the str of PE_E << 254 * no name was on an event via a term, << 255 * taking ownership of the allocation. << 256 */ << 257 int err = parse_events__set_default_na << 258 254 >> 255 err = parse_events_name($2, $1); >> 256 free($1); 259 if (err) { 257 if (err) { 260 free_list_evsel($2); 258 free_list_evsel($2); 261 YYNOMEM; !! 259 YYABORT; 262 } 260 } 263 $$ = $2; 261 $$ = $2; 264 } 262 } 265 | 263 | 266 event_def 264 event_def 267 265 268 event_def: event_pmu | 266 event_def: event_pmu | 269 event_legacy_symbol | 267 event_legacy_symbol | 270 event_legacy_cache sep_dc | 268 event_legacy_cache sep_dc | 271 event_legacy_mem sep_dc | !! 269 event_legacy_mem | 272 event_legacy_tracepoint sep_dc | 270 event_legacy_tracepoint sep_dc | 273 event_legacy_numeric sep_dc | 271 event_legacy_numeric sep_dc | 274 event_legacy_raw sep_dc !! 272 event_legacy_raw sep_dc | >> 273 event_bpf_file 275 274 276 event_pmu: 275 event_pmu: 277 PE_NAME opt_pmu_config 276 PE_NAME opt_pmu_config 278 { 277 { 279 /* List of created evsels. */ !! 278 struct parse_events_state *parse_state = _parse_state; 280 struct list_head *list = NULL; !! 279 struct parse_events_error *error = parse_state->error; 281 int err = parse_events_multi_pmu_add_o !! 280 struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL; >> 281 char *pattern = NULL; >> 282 >> 283 #define CLEANUP_YYABORT \ >> 284 do { \ >> 285 parse_events_terms__delete($2); \ >> 286 parse_events_terms__delete(orig_terms); \ >> 287 free(list); \ >> 288 free($1); \ >> 289 free(pattern); \ >> 290 YYABORT; \ >> 291 } while(0) >> 292 >> 293 if (parse_events_copy_term_list($2, &orig_terms)) >> 294 CLEANUP_YYABORT; >> 295 >> 296 if (error) >> 297 error->idx = @1.first_column; 282 298 >> 299 list = alloc_list(); >> 300 if (!list) >> 301 CLEANUP_YYABORT; >> 302 if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) { >> 303 struct perf_pmu *pmu = NULL; >> 304 int ok = 0; >> 305 >> 306 if (asprintf(&pattern, "%s*", $1) < 0) >> 307 CLEANUP_YYABORT; >> 308 >> 309 while ((pmu = perf_pmu__scan(pmu)) != NULL) { >> 310 char *name = pmu->name; >> 311 >> 312 if (!strncmp(name, "uncore_", 7) && >> 313 strncmp($1, "uncore_", 7)) >> 314 name += 7; >> 315 if (!fnmatch(pattern, name, 0)) { >> 316 if (parse_events_copy_term_list(orig_terms, &terms)) >> 317 CLEANUP_YYABORT; >> 318 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false)) >> 319 ok++; >> 320 parse_events_terms__delete(terms); >> 321 } >> 322 } >> 323 >> 324 if (!ok) >> 325 CLEANUP_YYABORT; >> 326 } 283 parse_events_terms__delete($2); 327 parse_events_terms__delete($2); >> 328 parse_events_terms__delete(orig_terms); >> 329 free(pattern); 284 free($1); 330 free($1); 285 if (err) << 286 PE_ABORT(err); << 287 $$ = list; 331 $$ = list; >> 332 #undef CLEANUP_YYABORT 288 } 333 } 289 | 334 | 290 PE_NAME sep_dc !! 335 PE_KERNEL_PMU_EVENT sep_dc 291 { 336 { 292 struct list_head *list; 337 struct list_head *list; 293 int err; 338 int err; 294 339 295 err = parse_events_multi_pmu_add(_pars !! 340 err = parse_events_multi_pmu_add(_parse_state, $1, &list); 296 if (err < 0) { !! 341 free($1); 297 struct parse_events_state *par !! 342 if (err < 0) 298 struct parse_events_error *err !! 343 YYABORT; 299 char *help; !! 344 $$ = list; >> 345 } >> 346 | >> 347 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc >> 348 { >> 349 struct list_head *list; >> 350 char pmu_name[128]; 300 351 301 if (asprintf(&help, "Unable to !! 352 snprintf(pmu_name, sizeof(pmu_name), "%s-%s", $1, $3); 302 help = NULL; << 303 parse_events_error__handle(err << 304 free($1); << 305 PE_ABORT(err); << 306 } << 307 free($1); 353 free($1); >> 354 free($3); >> 355 if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0) >> 356 YYABORT; 308 $$ = list; 357 $$ = list; 309 } 358 } 310 359 311 value_sym: 360 value_sym: 312 PE_VALUE_SYM_HW 361 PE_VALUE_SYM_HW 313 | 362 | 314 PE_VALUE_SYM_SW 363 PE_VALUE_SYM_SW 315 364 316 event_legacy_symbol: 365 event_legacy_symbol: 317 value_sym '/' event_config '/' 366 value_sym '/' event_config '/' 318 { 367 { 319 struct list_head *list; 368 struct list_head *list; 320 int type = $1 >> 16; 369 int type = $1 >> 16; 321 int config = $1 & 255; 370 int config = $1 & 255; 322 int err; 371 int err; 323 bool wildcard = (type == PERF_TYPE_HAR << 324 372 325 list = alloc_list(); 373 list = alloc_list(); 326 if (!list) !! 374 ABORT_ON(!list); 327 YYNOMEM; !! 375 err = parse_events_add_numeric(_parse_state, list, type, config, $3); 328 err = parse_events_add_numeric(_parse_ << 329 parse_events_terms__delete($3); 376 parse_events_terms__delete($3); 330 if (err) { 377 if (err) { 331 free_list_evsel(list); 378 free_list_evsel(list); 332 PE_ABORT(err); !! 379 YYABORT; 333 } 380 } 334 $$ = list; 381 $$ = list; 335 } 382 } 336 | 383 | 337 value_sym sep_slash_slash_dc 384 value_sym sep_slash_slash_dc 338 { 385 { 339 struct list_head *list; 386 struct list_head *list; 340 int type = $1 >> 16; 387 int type = $1 >> 16; 341 int config = $1 & 255; 388 int config = $1 & 255; 342 bool wildcard = (type == PERF_TYPE_HAR << 343 int err; << 344 389 345 list = alloc_list(); 390 list = alloc_list(); 346 if (!list) !! 391 ABORT_ON(!list); 347 YYNOMEM; !! 392 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL)); 348 err = parse_events_add_numeric(_parse_ << 349 if (err) << 350 PE_ABORT(err); << 351 $$ = list; 393 $$ = list; 352 } 394 } 353 | 395 | 354 PE_VALUE_SYM_TOOL sep_slash_slash_dc 396 PE_VALUE_SYM_TOOL sep_slash_slash_dc 355 { 397 { 356 struct list_head *list; 398 struct list_head *list; 357 int err; << 358 399 359 list = alloc_list(); 400 list = alloc_list(); 360 if (!list) !! 401 ABORT_ON(!list); 361 YYNOMEM; !! 402 ABORT_ON(parse_events_add_tool(_parse_state, list, $1)); 362 err = parse_events_add_tool(_parse_sta << 363 if (err) << 364 YYNOMEM; << 365 $$ = list; 403 $$ = list; 366 } 404 } 367 405 368 event_legacy_cache: 406 event_legacy_cache: 369 PE_LEGACY_CACHE opt_event_config !! 407 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config 370 { 408 { 371 struct parse_events_state *parse_state 409 struct parse_events_state *parse_state = _parse_state; >> 410 struct parse_events_error *error = parse_state->error; 372 struct list_head *list; 411 struct list_head *list; 373 int err; 412 int err; 374 413 375 list = alloc_list(); 414 list = alloc_list(); 376 if (!list) !! 415 ABORT_ON(!list); 377 YYNOMEM; !! 416 err = parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6); >> 417 parse_events_terms__delete($6); >> 418 free($1); >> 419 free($3); >> 420 free($5); >> 421 if (err) { >> 422 free_list_evsel(list); >> 423 YYABORT; >> 424 } >> 425 $$ = list; >> 426 } >> 427 | >> 428 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config >> 429 { >> 430 struct parse_events_state *parse_state = _parse_state; >> 431 struct parse_events_error *error = parse_state->error; >> 432 struct list_head *list; >> 433 int err; 378 434 379 err = parse_events_add_cache(list, &pa !! 435 list = alloc_list(); >> 436 ABORT_ON(!list); >> 437 err = parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4); >> 438 parse_events_terms__delete($4); >> 439 free($1); >> 440 free($3); >> 441 if (err) { >> 442 free_list_evsel(list); >> 443 YYABORT; >> 444 } >> 445 $$ = list; >> 446 } >> 447 | >> 448 PE_NAME_CACHE_TYPE opt_event_config >> 449 { >> 450 struct parse_events_state *parse_state = _parse_state; >> 451 struct parse_events_error *error = parse_state->error; >> 452 struct list_head *list; >> 453 int err; 380 454 >> 455 list = alloc_list(); >> 456 ABORT_ON(!list); >> 457 err = parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2); 381 parse_events_terms__delete($2); 458 parse_events_terms__delete($2); 382 free($1); 459 free($1); 383 if (err) { 460 if (err) { 384 free_list_evsel(list); 461 free_list_evsel(list); 385 PE_ABORT(err); !! 462 YYABORT; 386 } 463 } 387 $$ = list; 464 $$ = list; 388 } 465 } 389 466 390 event_legacy_mem: 467 event_legacy_mem: 391 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE !! 468 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc 392 { 469 { >> 470 struct parse_events_state *parse_state = _parse_state; 393 struct list_head *list; 471 struct list_head *list; 394 int err; 472 int err; 395 473 396 list = alloc_list(); 474 list = alloc_list(); 397 if (!list) !! 475 ABORT_ON(!list); 398 YYNOMEM; !! 476 err = parse_events_add_breakpoint(list, &parse_state->idx, 399 !! 477 (void *) $2, $6, $4); 400 err = parse_events_add_breakpoint(_par << 401 $2, << 402 parse_events_terms__delete($7); << 403 free($6); 478 free($6); 404 if (err) { 479 if (err) { 405 free(list); 480 free(list); 406 PE_ABORT(err); !! 481 YYABORT; 407 } 482 } 408 $$ = list; 483 $$ = list; 409 } 484 } 410 | 485 | 411 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE op !! 486 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc 412 { 487 { >> 488 struct parse_events_state *parse_state = _parse_state; 413 struct list_head *list; 489 struct list_head *list; 414 int err; << 415 490 416 list = alloc_list(); 491 list = alloc_list(); 417 if (!list) !! 492 ABORT_ON(!list); 418 YYNOMEM; !! 493 if (parse_events_add_breakpoint(list, &parse_state->idx, 419 !! 494 (void *) $2, NULL, $4)) { 420 err = parse_events_add_breakpoint(_par << 421 $2, << 422 parse_events_terms__delete($5); << 423 if (err) { << 424 free(list); 495 free(list); 425 PE_ABORT(err); !! 496 YYABORT; 426 } 497 } 427 $$ = list; 498 $$ = list; 428 } 499 } 429 | 500 | 430 PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER !! 501 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc 431 { 502 { >> 503 struct parse_events_state *parse_state = _parse_state; 432 struct list_head *list; 504 struct list_head *list; 433 int err; 505 int err; 434 506 435 list = alloc_list(); 507 list = alloc_list(); 436 if (!list) !! 508 ABORT_ON(!list); 437 YYNOMEM; !! 509 err = parse_events_add_breakpoint(list, &parse_state->idx, 438 !! 510 (void *) $2, $4, 0); 439 err = parse_events_add_breakpoint(_par << 440 $2, << 441 parse_events_terms__delete($5); << 442 free($4); 511 free($4); 443 if (err) { 512 if (err) { 444 free(list); 513 free(list); 445 PE_ABORT(err); !! 514 YYABORT; 446 } 515 } 447 $$ = list; 516 $$ = list; 448 } 517 } 449 | 518 | 450 PE_PREFIX_MEM PE_VALUE opt_event_config !! 519 PE_PREFIX_MEM PE_VALUE sep_dc 451 { 520 { >> 521 struct parse_events_state *parse_state = _parse_state; 452 struct list_head *list; 522 struct list_head *list; 453 int err; << 454 523 455 list = alloc_list(); 524 list = alloc_list(); 456 if (!list) !! 525 ABORT_ON(!list); 457 YYNOMEM; !! 526 if (parse_events_add_breakpoint(list, &parse_state->idx, 458 err = parse_events_add_breakpoint(_par !! 527 (void *) $2, NULL, 0)) { 459 $2, << 460 parse_events_terms__delete($3); << 461 if (err) { << 462 free(list); 528 free(list); 463 PE_ABORT(err); !! 529 YYABORT; 464 } 530 } 465 $$ = list; 531 $$ = list; 466 } 532 } 467 533 468 event_legacy_tracepoint: 534 event_legacy_tracepoint: 469 tracepoint_name opt_event_config 535 tracepoint_name opt_event_config 470 { 536 { 471 struct parse_events_state *parse_state 537 struct parse_events_state *parse_state = _parse_state; 472 struct parse_events_error *error = par 538 struct parse_events_error *error = parse_state->error; 473 struct list_head *list; 539 struct list_head *list; 474 int err; 540 int err; 475 541 476 list = alloc_list(); 542 list = alloc_list(); 477 if (!list) !! 543 ABORT_ON(!list); 478 YYNOMEM; !! 544 if (error) >> 545 error->idx = @1.first_column; 479 546 480 err = parse_events_add_tracepoint(pars !! 547 err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, 481 error, !! 548 error, $2); 482 549 483 parse_events_terms__delete($2); 550 parse_events_terms__delete($2); 484 free($1.sys); 551 free($1.sys); 485 free($1.event); 552 free($1.event); 486 if (err) { 553 if (err) { 487 free(list); 554 free(list); 488 PE_ABORT(err); !! 555 YYABORT; 489 } 556 } 490 $$ = list; 557 $$ = list; 491 } 558 } 492 559 493 tracepoint_name: 560 tracepoint_name: >> 561 PE_NAME '-' PE_NAME ':' PE_NAME >> 562 { >> 563 struct tracepoint_name tracepoint; >> 564 >> 565 ABORT_ON(asprintf(&tracepoint.sys, "%s-%s", $1, $3) < 0); >> 566 tracepoint.event = $5; >> 567 free($1); >> 568 free($3); >> 569 $$ = tracepoint; >> 570 } >> 571 | 494 PE_NAME ':' PE_NAME 572 PE_NAME ':' PE_NAME 495 { 573 { 496 struct tracepoint_name tracepoint = {$ 574 struct tracepoint_name tracepoint = {$1, $3}; 497 575 498 $$ = tracepoint; 576 $$ = tracepoint; 499 } 577 } 500 578 501 event_legacy_numeric: 579 event_legacy_numeric: 502 PE_VALUE ':' PE_VALUE opt_event_config 580 PE_VALUE ':' PE_VALUE opt_event_config 503 { 581 { 504 struct list_head *list; 582 struct list_head *list; 505 int err; 583 int err; 506 584 507 list = alloc_list(); 585 list = alloc_list(); 508 if (!list) !! 586 ABORT_ON(!list); 509 YYNOMEM; !! 587 err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4); 510 err = parse_events_add_numeric(_parse_ << 511 /*wildc << 512 parse_events_terms__delete($4); 588 parse_events_terms__delete($4); 513 if (err) { 589 if (err) { 514 free(list); 590 free(list); 515 PE_ABORT(err); !! 591 YYABORT; 516 } 592 } 517 $$ = list; 593 $$ = list; 518 } 594 } 519 595 520 event_legacy_raw: 596 event_legacy_raw: 521 PE_RAW opt_event_config 597 PE_RAW opt_event_config 522 { 598 { 523 struct list_head *list; 599 struct list_head *list; 524 int err; 600 int err; 525 u64 num; << 526 601 527 list = alloc_list(); 602 list = alloc_list(); 528 if (!list) !! 603 ABORT_ON(!list); 529 YYNOMEM; !! 604 err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2); 530 errno = 0; !! 605 parse_events_terms__delete($2); 531 num = strtoull($1 + 1, NULL, 16); !! 606 if (err) { 532 /* Given the lexer will only give [a-f !! 607 free(list); 533 if (errno) << 534 YYABORT; 608 YYABORT; >> 609 } >> 610 $$ = list; >> 611 } >> 612 >> 613 event_bpf_file: >> 614 PE_BPF_OBJECT opt_event_config >> 615 { >> 616 struct parse_events_state *parse_state = _parse_state; >> 617 struct list_head *list; >> 618 int err; >> 619 >> 620 list = alloc_list(); >> 621 ABORT_ON(!list); >> 622 err = parse_events_load_bpf(parse_state, list, $1, false, $2); >> 623 parse_events_terms__delete($2); 535 free($1); 624 free($1); 536 err = parse_events_add_numeric(_parse_ !! 625 if (err) { 537 /*wildc !! 626 free(list); >> 627 YYABORT; >> 628 } >> 629 $$ = list; >> 630 } >> 631 | >> 632 PE_BPF_SOURCE opt_event_config >> 633 { >> 634 struct list_head *list; >> 635 int err; >> 636 >> 637 list = alloc_list(); >> 638 ABORT_ON(!list); >> 639 err = parse_events_load_bpf(_parse_state, list, $1, true, $2); 538 parse_events_terms__delete($2); 640 parse_events_terms__delete($2); 539 if (err) { 641 if (err) { 540 free(list); 642 free(list); 541 PE_ABORT(err); !! 643 YYABORT; 542 } 644 } 543 $$ = list; 645 $$ = list; 544 } 646 } 545 647 546 opt_event_config: 648 opt_event_config: 547 '/' event_config '/' 649 '/' event_config '/' 548 { 650 { 549 $$ = $2; 651 $$ = $2; 550 } 652 } 551 | 653 | 552 '/' '/' 654 '/' '/' 553 { 655 { 554 $$ = NULL; 656 $$ = NULL; 555 } 657 } 556 | 658 | 557 { 659 { 558 $$ = NULL; 660 $$ = NULL; 559 } 661 } 560 662 561 opt_pmu_config: 663 opt_pmu_config: 562 '/' event_config '/' 664 '/' event_config '/' 563 { 665 { 564 $$ = $2; 666 $$ = $2; 565 } 667 } 566 | 668 | 567 '/' '/' 669 '/' '/' 568 { 670 { 569 $$ = NULL; 671 $$ = NULL; 570 } 672 } 571 673 572 start_terms: event_config 674 start_terms: event_config 573 { 675 { 574 struct parse_events_state *parse_state 676 struct parse_events_state *parse_state = _parse_state; 575 if (parse_state->terms) { 677 if (parse_state->terms) { 576 parse_events_terms__delete ($1 678 parse_events_terms__delete ($1); 577 YYABORT; 679 YYABORT; 578 } 680 } 579 parse_state->terms = $1; 681 parse_state->terms = $1; 580 } 682 } 581 683 582 event_config: 684 event_config: 583 event_config ',' event_term 685 event_config ',' event_term 584 { 686 { 585 struct parse_events_terms *head = $1; !! 687 struct list_head *head = $1; 586 struct parse_events_term *term = $3; 688 struct parse_events_term *term = $3; 587 689 588 if (!head) { 690 if (!head) { 589 parse_events_term__delete(term 691 parse_events_term__delete(term); 590 YYABORT; 692 YYABORT; 591 } 693 } 592 list_add_tail(&term->list, &head->term !! 694 list_add_tail(&term->list, head); 593 $$ = $1; 695 $$ = $1; 594 } 696 } 595 | 697 | 596 event_term 698 event_term 597 { 699 { 598 struct parse_events_terms *head = mall !! 700 struct list_head *head = malloc(sizeof(*head)); 599 struct parse_events_term *term = $1; 701 struct parse_events_term *term = $1; 600 702 601 if (!head) !! 703 ABORT_ON(!head); 602 YYNOMEM; !! 704 INIT_LIST_HEAD(head); 603 parse_events_terms__init(head); !! 705 list_add_tail(&term->list, head); 604 list_add_tail(&term->list, &head->term << 605 $$ = head; 706 $$ = head; 606 } 707 } 607 708 608 name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACH << 609 | << 610 PE_TERM_HW << 611 { << 612 $$ = $1.str; << 613 } << 614 << 615 event_term: 709 event_term: 616 PE_RAW 710 PE_RAW 617 { 711 { 618 struct parse_events_term *term; 712 struct parse_events_term *term; 619 int err = parse_events_term__str(&term << 620 strdu << 621 713 622 if (err) { !! 714 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_CONFIG, 623 free($1); !! 715 NULL, $1, false, &@1, NULL)); 624 PE_ABORT(err); << 625 } << 626 $$ = term; 716 $$ = term; 627 } 717 } 628 | 718 | 629 name_or_raw '=' name_or_raw !! 719 PE_NAME '=' PE_NAME 630 { 720 { 631 struct parse_events_term *term; 721 struct parse_events_term *term; 632 int err = parse_events_term__str(&term << 633 722 634 if (err) { !! 723 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 724 $1, $3, &@1, &@3)) { 635 free($1); 725 free($1); 636 free($3); 726 free($3); 637 PE_ABORT(err); !! 727 YYABORT; 638 } 728 } 639 $$ = term; 729 $$ = term; 640 } 730 } 641 | 731 | 642 name_or_raw '=' PE_VALUE !! 732 PE_NAME '=' PE_VALUE 643 { 733 { 644 struct parse_events_term *term; 734 struct parse_events_term *term; 645 int err = parse_events_term__num(&term << 646 $1, $ << 647 735 648 if (err) { !! 736 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 737 $1, $3, false, &@1, &@3)) { 649 free($1); 738 free($1); 650 PE_ABORT(err); !! 739 YYABORT; 651 } 740 } 652 $$ = term; 741 $$ = term; 653 } 742 } 654 | 743 | 655 PE_LEGACY_CACHE !! 744 PE_NAME '=' PE_VALUE_SYM_HW 656 { 745 { 657 struct parse_events_term *term; 746 struct parse_events_term *term; 658 int err = parse_events_term__num(&term !! 747 int config = $3 & 255; 659 $1, / << 660 748 661 if (err) { !! 749 if (parse_events_term__sym_hw(&term, $1, config)) { 662 free($1); 750 free($1); 663 PE_ABORT(err); !! 751 YYABORT; 664 } 752 } 665 $$ = term; 753 $$ = term; 666 } 754 } 667 | 755 | 668 PE_NAME 756 PE_NAME 669 { 757 { 670 struct parse_events_term *term; 758 struct parse_events_term *term; 671 int err = parse_events_term__num(&term << 672 $1, / << 673 759 674 if (err) { !! 760 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 761 $1, 1, true, &@1, NULL)) { 675 free($1); 762 free($1); 676 PE_ABORT(err); !! 763 YYABORT; 677 } 764 } 678 $$ = term; 765 $$ = term; 679 } 766 } 680 | 767 | 681 PE_TERM_HW !! 768 PE_VALUE_SYM_HW 682 { 769 { 683 struct parse_events_term *term; 770 struct parse_events_term *term; 684 int err = parse_events_term__num(&term !! 771 int config = $1 & 255; 685 $1.st << 686 &@1, << 687 772 688 if (err) { !! 773 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config)); 689 free($1.str); << 690 PE_ABORT(err); << 691 } << 692 $$ = term; 774 $$ = term; 693 } 775 } 694 | 776 | 695 PE_TERM '=' name_or_raw !! 777 PE_TERM '=' PE_NAME 696 { 778 { 697 struct parse_events_term *term; 779 struct parse_events_term *term; 698 int err = parse_events_term__str(&term << 699 780 700 if (err) { !! 781 if (parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)) { 701 free($3); 782 free($3); 702 PE_ABORT(err); !! 783 YYABORT; 703 } 784 } 704 $$ = term; 785 $$ = term; 705 } 786 } 706 | 787 | 707 PE_TERM '=' PE_TERM !! 788 PE_TERM '=' PE_VALUE 708 { 789 { 709 struct parse_events_term *term; 790 struct parse_events_term *term; 710 int err = parse_events_term__term(&ter << 711 << 712 if (err) << 713 PE_ABORT(err); << 714 791 >> 792 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3)); 715 $$ = term; 793 $$ = term; 716 } 794 } 717 | 795 | 718 PE_TERM '=' PE_VALUE !! 796 PE_TERM 719 { 797 { 720 struct parse_events_term *term; 798 struct parse_events_term *term; 721 int err = parse_events_term__num(&term << 722 /*con << 723 &@1, << 724 << 725 if (err) << 726 PE_ABORT(err); << 727 799 >> 800 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL)); 728 $$ = term; 801 $$ = term; 729 } 802 } 730 | 803 | 731 PE_TERM !! 804 PE_NAME array '=' PE_NAME 732 { 805 { 733 struct parse_events_term *term; 806 struct parse_events_term *term; 734 int err = parse_events_term__num(&term << 735 /*con << 736 &@1, << 737 807 738 if (err) !! 808 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 739 PE_ABORT(err); !! 809 $1, $4, &@1, &@4)) { >> 810 free($1); >> 811 free($4); >> 812 free($2.ranges); >> 813 YYABORT; >> 814 } >> 815 term->array = $2; >> 816 $$ = term; >> 817 } >> 818 | >> 819 PE_NAME array '=' PE_VALUE >> 820 { >> 821 struct parse_events_term *term; 740 822 >> 823 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 824 $1, $4, false, &@1, &@4)) { >> 825 free($1); >> 826 free($2.ranges); >> 827 YYABORT; >> 828 } >> 829 term->array = $2; 741 $$ = term; 830 $$ = term; 742 } 831 } 743 | 832 | 744 PE_DRV_CFG_TERM 833 PE_DRV_CFG_TERM 745 { 834 { 746 struct parse_events_term *term; 835 struct parse_events_term *term; 747 char *config = strdup($1); 836 char *config = strdup($1); 748 int err; << 749 837 750 if (!config) !! 838 ABORT_ON(!config); 751 YYNOMEM; !! 839 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, 752 err = parse_events_term__str(&term, PA !! 840 config, $1, &@1, NULL)) { 753 if (err) { << 754 free($1); 841 free($1); 755 free(config); 842 free(config); 756 PE_ABORT(err); !! 843 YYABORT; 757 } 844 } 758 $$ = term; 845 $$ = term; 759 } 846 } 760 847 >> 848 array: >> 849 '[' array_terms ']' >> 850 { >> 851 $$ = $2; >> 852 } >> 853 | >> 854 PE_ARRAY_ALL >> 855 { >> 856 $$.nr_ranges = 0; >> 857 $$.ranges = NULL; >> 858 } >> 859 >> 860 array_terms: >> 861 array_terms ',' array_term >> 862 { >> 863 struct parse_events_array new_array; >> 864 >> 865 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; >> 866 new_array.ranges = realloc($1.ranges, >> 867 sizeof(new_array.ranges[0]) * >> 868 new_array.nr_ranges); >> 869 ABORT_ON(!new_array.ranges); >> 870 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, >> 871 $3.nr_ranges * sizeof(new_array.ranges[0])); >> 872 free($3.ranges); >> 873 $$ = new_array; >> 874 } >> 875 | >> 876 array_term >> 877 >> 878 array_term: >> 879 PE_VALUE >> 880 { >> 881 struct parse_events_array array; >> 882 >> 883 array.nr_ranges = 1; >> 884 array.ranges = malloc(sizeof(array.ranges[0])); >> 885 ABORT_ON(!array.ranges); >> 886 array.ranges[0].start = $1; >> 887 array.ranges[0].length = 1; >> 888 $$ = array; >> 889 } >> 890 | >> 891 PE_VALUE PE_ARRAY_RANGE PE_VALUE >> 892 { >> 893 struct parse_events_array array; >> 894 >> 895 ABORT_ON($3 < $1); >> 896 array.nr_ranges = 1; >> 897 array.ranges = malloc(sizeof(array.ranges[0])); >> 898 ABORT_ON(!array.ranges); >> 899 array.ranges[0].start = $1; >> 900 array.ranges[0].length = $3 - $1 + 1; >> 901 $$ = array; >> 902 } >> 903 761 sep_dc: ':' | 904 sep_dc: ':' | 762 905 763 sep_slash_slash_dc: '/' '/' | ':' | 906 sep_slash_slash_dc: '/' '/' | ':' | 764 907 765 %% 908 %% 766 909 767 void parse_events_error(YYLTYPE *loc, void *_p !! 910 void parse_events_error(YYLTYPE *loc, void *parse_state, 768 void *scanner __maybe_ 911 void *scanner __maybe_unused, 769 char const *msg __mayb 912 char const *msg __maybe_unused) 770 { 913 { 771 struct parse_events_state *parse_state !! 914 parse_events_evlist_error(parse_state, loc->last_column, "parser error"); 772 << 773 if (!parse_state->error || !list_empty << 774 return; << 775 << 776 parse_events_error__handle(parse_state << 777 strdup("Unr << 778 } 915 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.