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() 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 perf_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); 284 free($1); 329 free($1); 285 if (err) << 286 PE_ABORT(err); << 287 $$ = list; 330 $$ = list; >> 331 #undef CLEANUP_YYABORT 288 } 332 } 289 | 333 | 290 PE_NAME sep_dc !! 334 PE_KERNEL_PMU_EVENT sep_dc 291 { 335 { 292 struct list_head *list; 336 struct list_head *list; 293 int err; 337 int err; 294 338 295 err = parse_events_multi_pmu_add(_pars !! 339 err = parse_events_multi_pmu_add(_parse_state, $1, &list); 296 if (err < 0) { !! 340 free($1); 297 struct parse_events_state *par !! 341 if (err < 0) 298 struct parse_events_error *err !! 342 YYABORT; 299 char *help; !! 343 $$ = list; >> 344 } >> 345 | >> 346 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc >> 347 { >> 348 struct list_head *list; >> 349 char pmu_name[128]; 300 350 301 if (asprintf(&help, "Unable to !! 351 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); 352 free($1); >> 353 free($3); >> 354 if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0) >> 355 YYABORT; 308 $$ = list; 356 $$ = list; 309 } 357 } 310 358 311 value_sym: 359 value_sym: 312 PE_VALUE_SYM_HW 360 PE_VALUE_SYM_HW 313 | 361 | 314 PE_VALUE_SYM_SW 362 PE_VALUE_SYM_SW 315 363 316 event_legacy_symbol: 364 event_legacy_symbol: 317 value_sym '/' event_config '/' 365 value_sym '/' event_config '/' 318 { 366 { 319 struct list_head *list; 367 struct list_head *list; 320 int type = $1 >> 16; 368 int type = $1 >> 16; 321 int config = $1 & 255; 369 int config = $1 & 255; 322 int err; 370 int err; 323 bool wildcard = (type == PERF_TYPE_HAR << 324 371 325 list = alloc_list(); 372 list = alloc_list(); 326 if (!list) !! 373 ABORT_ON(!list); 327 YYNOMEM; !! 374 err = parse_events_add_numeric(_parse_state, list, type, config, $3); 328 err = parse_events_add_numeric(_parse_ << 329 parse_events_terms__delete($3); 375 parse_events_terms__delete($3); 330 if (err) { 376 if (err) { 331 free_list_evsel(list); 377 free_list_evsel(list); 332 PE_ABORT(err); !! 378 YYABORT; 333 } 379 } 334 $$ = list; 380 $$ = list; 335 } 381 } 336 | 382 | 337 value_sym sep_slash_slash_dc 383 value_sym sep_slash_slash_dc 338 { 384 { 339 struct list_head *list; 385 struct list_head *list; 340 int type = $1 >> 16; 386 int type = $1 >> 16; 341 int config = $1 & 255; 387 int config = $1 & 255; 342 bool wildcard = (type == PERF_TYPE_HAR << 343 int err; << 344 388 345 list = alloc_list(); 389 list = alloc_list(); 346 if (!list) !! 390 ABORT_ON(!list); 347 YYNOMEM; !! 391 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; 392 $$ = list; 352 } 393 } 353 | 394 | 354 PE_VALUE_SYM_TOOL sep_slash_slash_dc 395 PE_VALUE_SYM_TOOL sep_slash_slash_dc 355 { 396 { 356 struct list_head *list; 397 struct list_head *list; 357 int err; << 358 398 359 list = alloc_list(); 399 list = alloc_list(); 360 if (!list) !! 400 ABORT_ON(!list); 361 YYNOMEM; !! 401 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; 402 $$ = list; 366 } 403 } 367 404 368 event_legacy_cache: 405 event_legacy_cache: 369 PE_LEGACY_CACHE opt_event_config !! 406 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config 370 { 407 { 371 struct parse_events_state *parse_state 408 struct parse_events_state *parse_state = _parse_state; >> 409 struct parse_events_error *error = parse_state->error; 372 struct list_head *list; 410 struct list_head *list; 373 int err; 411 int err; 374 412 375 list = alloc_list(); 413 list = alloc_list(); 376 if (!list) !! 414 ABORT_ON(!list); 377 YYNOMEM; !! 415 err = parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6); >> 416 parse_events_terms__delete($6); >> 417 free($1); >> 418 free($3); >> 419 free($5); >> 420 if (err) { >> 421 free_list_evsel(list); >> 422 YYABORT; >> 423 } >> 424 $$ = list; >> 425 } >> 426 | >> 427 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config >> 428 { >> 429 struct parse_events_state *parse_state = _parse_state; >> 430 struct parse_events_error *error = parse_state->error; >> 431 struct list_head *list; >> 432 int err; 378 433 379 err = parse_events_add_cache(list, &pa !! 434 list = alloc_list(); >> 435 ABORT_ON(!list); >> 436 err = parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4); >> 437 parse_events_terms__delete($4); >> 438 free($1); >> 439 free($3); >> 440 if (err) { >> 441 free_list_evsel(list); >> 442 YYABORT; >> 443 } >> 444 $$ = list; >> 445 } >> 446 | >> 447 PE_NAME_CACHE_TYPE opt_event_config >> 448 { >> 449 struct parse_events_state *parse_state = _parse_state; >> 450 struct parse_events_error *error = parse_state->error; >> 451 struct list_head *list; >> 452 int err; 380 453 >> 454 list = alloc_list(); >> 455 ABORT_ON(!list); >> 456 err = parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2); 381 parse_events_terms__delete($2); 457 parse_events_terms__delete($2); 382 free($1); 458 free($1); 383 if (err) { 459 if (err) { 384 free_list_evsel(list); 460 free_list_evsel(list); 385 PE_ABORT(err); !! 461 YYABORT; 386 } 462 } 387 $$ = list; 463 $$ = list; 388 } 464 } 389 465 390 event_legacy_mem: 466 event_legacy_mem: 391 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE !! 467 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc 392 { 468 { >> 469 struct parse_events_state *parse_state = _parse_state; 393 struct list_head *list; 470 struct list_head *list; 394 int err; 471 int err; 395 472 396 list = alloc_list(); 473 list = alloc_list(); 397 if (!list) !! 474 ABORT_ON(!list); 398 YYNOMEM; !! 475 err = parse_events_add_breakpoint(list, &parse_state->idx, 399 !! 476 (void *) $2, $6, $4); 400 err = parse_events_add_breakpoint(_par << 401 $2, << 402 parse_events_terms__delete($7); << 403 free($6); 477 free($6); 404 if (err) { 478 if (err) { 405 free(list); 479 free(list); 406 PE_ABORT(err); !! 480 YYABORT; 407 } 481 } 408 $$ = list; 482 $$ = list; 409 } 483 } 410 | 484 | 411 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE op !! 485 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc 412 { 486 { >> 487 struct parse_events_state *parse_state = _parse_state; 413 struct list_head *list; 488 struct list_head *list; 414 int err; << 415 489 416 list = alloc_list(); 490 list = alloc_list(); 417 if (!list) !! 491 ABORT_ON(!list); 418 YYNOMEM; !! 492 if (parse_events_add_breakpoint(list, &parse_state->idx, 419 !! 493 (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); 494 free(list); 425 PE_ABORT(err); !! 495 YYABORT; 426 } 496 } 427 $$ = list; 497 $$ = list; 428 } 498 } 429 | 499 | 430 PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER !! 500 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc 431 { 501 { >> 502 struct parse_events_state *parse_state = _parse_state; 432 struct list_head *list; 503 struct list_head *list; 433 int err; 504 int err; 434 505 435 list = alloc_list(); 506 list = alloc_list(); 436 if (!list) !! 507 ABORT_ON(!list); 437 YYNOMEM; !! 508 err = parse_events_add_breakpoint(list, &parse_state->idx, 438 !! 509 (void *) $2, $4, 0); 439 err = parse_events_add_breakpoint(_par << 440 $2, << 441 parse_events_terms__delete($5); << 442 free($4); 510 free($4); 443 if (err) { 511 if (err) { 444 free(list); 512 free(list); 445 PE_ABORT(err); !! 513 YYABORT; 446 } 514 } 447 $$ = list; 515 $$ = list; 448 } 516 } 449 | 517 | 450 PE_PREFIX_MEM PE_VALUE opt_event_config !! 518 PE_PREFIX_MEM PE_VALUE sep_dc 451 { 519 { >> 520 struct parse_events_state *parse_state = _parse_state; 452 struct list_head *list; 521 struct list_head *list; 453 int err; << 454 522 455 list = alloc_list(); 523 list = alloc_list(); 456 if (!list) !! 524 ABORT_ON(!list); 457 YYNOMEM; !! 525 if (parse_events_add_breakpoint(list, &parse_state->idx, 458 err = parse_events_add_breakpoint(_par !! 526 (void *) $2, NULL, 0)) { 459 $2, << 460 parse_events_terms__delete($3); << 461 if (err) { << 462 free(list); 527 free(list); 463 PE_ABORT(err); !! 528 YYABORT; 464 } 529 } 465 $$ = list; 530 $$ = list; 466 } 531 } 467 532 468 event_legacy_tracepoint: 533 event_legacy_tracepoint: 469 tracepoint_name opt_event_config 534 tracepoint_name opt_event_config 470 { 535 { 471 struct parse_events_state *parse_state 536 struct parse_events_state *parse_state = _parse_state; 472 struct parse_events_error *error = par 537 struct parse_events_error *error = parse_state->error; 473 struct list_head *list; 538 struct list_head *list; 474 int err; 539 int err; 475 540 476 list = alloc_list(); 541 list = alloc_list(); 477 if (!list) !! 542 ABORT_ON(!list); 478 YYNOMEM; !! 543 if (error) >> 544 error->idx = @1.first_column; 479 545 480 err = parse_events_add_tracepoint(pars !! 546 err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, 481 error, !! 547 error, $2); 482 548 483 parse_events_terms__delete($2); 549 parse_events_terms__delete($2); 484 free($1.sys); 550 free($1.sys); 485 free($1.event); 551 free($1.event); 486 if (err) { 552 if (err) { 487 free(list); 553 free(list); 488 PE_ABORT(err); !! 554 YYABORT; 489 } 555 } 490 $$ = list; 556 $$ = list; 491 } 557 } 492 558 493 tracepoint_name: 559 tracepoint_name: >> 560 PE_NAME '-' PE_NAME ':' PE_NAME >> 561 { >> 562 struct tracepoint_name tracepoint; >> 563 >> 564 ABORT_ON(asprintf(&tracepoint.sys, "%s-%s", $1, $3) < 0); >> 565 tracepoint.event = $5; >> 566 free($1); >> 567 free($3); >> 568 $$ = tracepoint; >> 569 } >> 570 | 494 PE_NAME ':' PE_NAME 571 PE_NAME ':' PE_NAME 495 { 572 { 496 struct tracepoint_name tracepoint = {$ 573 struct tracepoint_name tracepoint = {$1, $3}; 497 574 498 $$ = tracepoint; 575 $$ = tracepoint; 499 } 576 } 500 577 501 event_legacy_numeric: 578 event_legacy_numeric: 502 PE_VALUE ':' PE_VALUE opt_event_config 579 PE_VALUE ':' PE_VALUE opt_event_config 503 { 580 { 504 struct list_head *list; 581 struct list_head *list; 505 int err; 582 int err; 506 583 507 list = alloc_list(); 584 list = alloc_list(); 508 if (!list) !! 585 ABORT_ON(!list); 509 YYNOMEM; !! 586 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); 587 parse_events_terms__delete($4); 513 if (err) { 588 if (err) { 514 free(list); 589 free(list); 515 PE_ABORT(err); !! 590 YYABORT; 516 } 591 } 517 $$ = list; 592 $$ = list; 518 } 593 } 519 594 520 event_legacy_raw: 595 event_legacy_raw: 521 PE_RAW opt_event_config 596 PE_RAW opt_event_config 522 { 597 { 523 struct list_head *list; 598 struct list_head *list; 524 int err; 599 int err; 525 u64 num; << 526 600 527 list = alloc_list(); 601 list = alloc_list(); 528 if (!list) !! 602 ABORT_ON(!list); 529 YYNOMEM; !! 603 err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2); 530 errno = 0; !! 604 parse_events_terms__delete($2); 531 num = strtoull($1 + 1, NULL, 16); !! 605 if (err) { 532 /* Given the lexer will only give [a-f !! 606 free(list); 533 if (errno) << 534 YYABORT; 607 YYABORT; >> 608 } >> 609 $$ = list; >> 610 } >> 611 >> 612 event_bpf_file: >> 613 PE_BPF_OBJECT opt_event_config >> 614 { >> 615 struct parse_events_state *parse_state = _parse_state; >> 616 struct list_head *list; >> 617 int err; >> 618 >> 619 list = alloc_list(); >> 620 ABORT_ON(!list); >> 621 err = parse_events_load_bpf(parse_state, list, $1, false, $2); >> 622 parse_events_terms__delete($2); 535 free($1); 623 free($1); 536 err = parse_events_add_numeric(_parse_ !! 624 if (err) { 537 /*wildc !! 625 free(list); >> 626 YYABORT; >> 627 } >> 628 $$ = list; >> 629 } >> 630 | >> 631 PE_BPF_SOURCE opt_event_config >> 632 { >> 633 struct list_head *list; >> 634 int err; >> 635 >> 636 list = alloc_list(); >> 637 ABORT_ON(!list); >> 638 err = parse_events_load_bpf(_parse_state, list, $1, true, $2); 538 parse_events_terms__delete($2); 639 parse_events_terms__delete($2); 539 if (err) { 640 if (err) { 540 free(list); 641 free(list); 541 PE_ABORT(err); !! 642 YYABORT; 542 } 643 } 543 $$ = list; 644 $$ = list; 544 } 645 } 545 646 546 opt_event_config: 647 opt_event_config: 547 '/' event_config '/' 648 '/' event_config '/' 548 { 649 { 549 $$ = $2; 650 $$ = $2; 550 } 651 } 551 | 652 | 552 '/' '/' 653 '/' '/' 553 { 654 { 554 $$ = NULL; 655 $$ = NULL; 555 } 656 } 556 | 657 | 557 { 658 { 558 $$ = NULL; 659 $$ = NULL; 559 } 660 } 560 661 561 opt_pmu_config: 662 opt_pmu_config: 562 '/' event_config '/' 663 '/' event_config '/' 563 { 664 { 564 $$ = $2; 665 $$ = $2; 565 } 666 } 566 | 667 | 567 '/' '/' 668 '/' '/' 568 { 669 { 569 $$ = NULL; 670 $$ = NULL; 570 } 671 } 571 672 572 start_terms: event_config 673 start_terms: event_config 573 { 674 { 574 struct parse_events_state *parse_state 675 struct parse_events_state *parse_state = _parse_state; 575 if (parse_state->terms) { 676 if (parse_state->terms) { 576 parse_events_terms__delete ($1 677 parse_events_terms__delete ($1); 577 YYABORT; 678 YYABORT; 578 } 679 } 579 parse_state->terms = $1; 680 parse_state->terms = $1; 580 } 681 } 581 682 582 event_config: 683 event_config: 583 event_config ',' event_term 684 event_config ',' event_term 584 { 685 { 585 struct parse_events_terms *head = $1; !! 686 struct list_head *head = $1; 586 struct parse_events_term *term = $3; 687 struct parse_events_term *term = $3; 587 688 588 if (!head) { 689 if (!head) { 589 parse_events_term__delete(term 690 parse_events_term__delete(term); 590 YYABORT; 691 YYABORT; 591 } 692 } 592 list_add_tail(&term->list, &head->term !! 693 list_add_tail(&term->list, head); 593 $$ = $1; 694 $$ = $1; 594 } 695 } 595 | 696 | 596 event_term 697 event_term 597 { 698 { 598 struct parse_events_terms *head = mall !! 699 struct list_head *head = malloc(sizeof(*head)); 599 struct parse_events_term *term = $1; 700 struct parse_events_term *term = $1; 600 701 601 if (!head) !! 702 ABORT_ON(!head); 602 YYNOMEM; !! 703 INIT_LIST_HEAD(head); 603 parse_events_terms__init(head); !! 704 list_add_tail(&term->list, head); 604 list_add_tail(&term->list, &head->term << 605 $$ = head; 705 $$ = head; 606 } 706 } 607 707 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: 708 event_term: 616 PE_RAW !! 709 PE_NAME '=' PE_NAME 617 { 710 { 618 struct parse_events_term *term; 711 struct parse_events_term *term; 619 int err = parse_events_term__str(&term << 620 strdu << 621 712 622 if (err) { !! 713 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 714 $1, $3, &@1, &@3)) { 623 free($1); 715 free($1); 624 PE_ABORT(err); !! 716 free($3); >> 717 YYABORT; 625 } 718 } 626 $$ = term; 719 $$ = term; 627 } 720 } 628 | 721 | 629 name_or_raw '=' name_or_raw !! 722 PE_NAME '=' PE_VALUE 630 { 723 { 631 struct parse_events_term *term; 724 struct parse_events_term *term; 632 int err = parse_events_term__str(&term << 633 725 634 if (err) { !! 726 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 727 $1, $3, false, &@1, &@3)) { 635 free($1); 728 free($1); 636 free($3); !! 729 YYABORT; 637 PE_ABORT(err); << 638 } 730 } 639 $$ = term; 731 $$ = term; 640 } 732 } 641 | 733 | 642 name_or_raw '=' PE_VALUE !! 734 PE_NAME '=' PE_VALUE_SYM_HW 643 { 735 { 644 struct parse_events_term *term; 736 struct parse_events_term *term; 645 int err = parse_events_term__num(&term !! 737 int config = $3 & 255; 646 $1, $ << 647 738 648 if (err) { !! 739 if (parse_events_term__sym_hw(&term, $1, config)) { 649 free($1); 740 free($1); 650 PE_ABORT(err); !! 741 YYABORT; 651 } 742 } 652 $$ = term; 743 $$ = term; 653 } 744 } 654 | 745 | 655 PE_LEGACY_CACHE !! 746 PE_NAME 656 { 747 { 657 struct parse_events_term *term; 748 struct parse_events_term *term; 658 int err = parse_events_term__num(&term << 659 $1, / << 660 749 661 if (err) { !! 750 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 751 $1, 1, true, &@1, NULL)) { 662 free($1); 752 free($1); 663 PE_ABORT(err); !! 753 YYABORT; 664 } 754 } 665 $$ = term; 755 $$ = term; 666 } 756 } 667 | 757 | 668 PE_NAME !! 758 PE_VALUE_SYM_HW 669 { 759 { 670 struct parse_events_term *term; 760 struct parse_events_term *term; 671 int err = parse_events_term__num(&term !! 761 int config = $1 & 255; 672 $1, / << 673 762 674 if (err) { !! 763 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config)); 675 free($1); << 676 PE_ABORT(err); << 677 } << 678 $$ = term; 764 $$ = term; 679 } 765 } 680 | 766 | 681 PE_TERM_HW !! 767 PE_TERM '=' PE_NAME 682 { 768 { 683 struct parse_events_term *term; 769 struct parse_events_term *term; 684 int err = parse_events_term__num(&term << 685 $1.st << 686 &@1, << 687 770 688 if (err) { !! 771 if (parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)) { 689 free($1.str); !! 772 free($3); 690 PE_ABORT(err); !! 773 YYABORT; 691 } 774 } 692 $$ = term; 775 $$ = term; 693 } 776 } 694 | 777 | 695 PE_TERM '=' name_or_raw !! 778 PE_TERM '=' PE_VALUE 696 { 779 { 697 struct parse_events_term *term; 780 struct parse_events_term *term; 698 int err = parse_events_term__str(&term << 699 781 700 if (err) { !! 782 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3)); 701 free($3); << 702 PE_ABORT(err); << 703 } << 704 $$ = term; 783 $$ = term; 705 } 784 } 706 | 785 | 707 PE_TERM '=' PE_TERM !! 786 PE_TERM 708 { 787 { 709 struct parse_events_term *term; 788 struct parse_events_term *term; 710 int err = parse_events_term__term(&ter << 711 << 712 if (err) << 713 PE_ABORT(err); << 714 789 >> 790 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL)); 715 $$ = term; 791 $$ = term; 716 } 792 } 717 | 793 | 718 PE_TERM '=' PE_VALUE !! 794 PE_NAME array '=' PE_NAME 719 { 795 { 720 struct parse_events_term *term; 796 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 797 >> 798 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 799 $1, $4, &@1, &@4)) { >> 800 free($1); >> 801 free($4); >> 802 free($2.ranges); >> 803 YYABORT; >> 804 } >> 805 term->array = $2; 728 $$ = term; 806 $$ = term; 729 } 807 } 730 | 808 | 731 PE_TERM !! 809 PE_NAME array '=' PE_VALUE 732 { 810 { 733 struct parse_events_term *term; 811 struct parse_events_term *term; 734 int err = parse_events_term__num(&term << 735 /*con << 736 &@1, << 737 << 738 if (err) << 739 PE_ABORT(err); << 740 812 >> 813 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 814 $1, $4, false, &@1, &@4)) { >> 815 free($1); >> 816 free($2.ranges); >> 817 YYABORT; >> 818 } >> 819 term->array = $2; 741 $$ = term; 820 $$ = term; 742 } 821 } 743 | 822 | 744 PE_DRV_CFG_TERM 823 PE_DRV_CFG_TERM 745 { 824 { 746 struct parse_events_term *term; 825 struct parse_events_term *term; 747 char *config = strdup($1); 826 char *config = strdup($1); 748 int err; << 749 827 750 if (!config) !! 828 ABORT_ON(!config); 751 YYNOMEM; !! 829 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, 752 err = parse_events_term__str(&term, PA !! 830 config, $1, &@1, NULL)) { 753 if (err) { << 754 free($1); 831 free($1); 755 free(config); 832 free(config); 756 PE_ABORT(err); !! 833 YYABORT; 757 } 834 } 758 $$ = term; 835 $$ = term; 759 } 836 } 760 837 >> 838 array: >> 839 '[' array_terms ']' >> 840 { >> 841 $$ = $2; >> 842 } >> 843 | >> 844 PE_ARRAY_ALL >> 845 { >> 846 $$.nr_ranges = 0; >> 847 $$.ranges = NULL; >> 848 } >> 849 >> 850 array_terms: >> 851 array_terms ',' array_term >> 852 { >> 853 struct parse_events_array new_array; >> 854 >> 855 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; >> 856 new_array.ranges = realloc($1.ranges, >> 857 sizeof(new_array.ranges[0]) * >> 858 new_array.nr_ranges); >> 859 ABORT_ON(!new_array.ranges); >> 860 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, >> 861 $3.nr_ranges * sizeof(new_array.ranges[0])); >> 862 free($3.ranges); >> 863 $$ = new_array; >> 864 } >> 865 | >> 866 array_term >> 867 >> 868 array_term: >> 869 PE_VALUE >> 870 { >> 871 struct parse_events_array array; >> 872 >> 873 array.nr_ranges = 1; >> 874 array.ranges = malloc(sizeof(array.ranges[0])); >> 875 ABORT_ON(!array.ranges); >> 876 array.ranges[0].start = $1; >> 877 array.ranges[0].length = 1; >> 878 $$ = array; >> 879 } >> 880 | >> 881 PE_VALUE PE_ARRAY_RANGE PE_VALUE >> 882 { >> 883 struct parse_events_array array; >> 884 >> 885 ABORT_ON($3 < $1); >> 886 array.nr_ranges = 1; >> 887 array.ranges = malloc(sizeof(array.ranges[0])); >> 888 ABORT_ON(!array.ranges); >> 889 array.ranges[0].start = $1; >> 890 array.ranges[0].length = $3 - $1 + 1; >> 891 $$ = array; >> 892 } >> 893 761 sep_dc: ':' | 894 sep_dc: ':' | 762 895 763 sep_slash_slash_dc: '/' '/' | ':' | 896 sep_slash_slash_dc: '/' '/' | ':' | 764 897 765 %% 898 %% 766 899 767 void parse_events_error(YYLTYPE *loc, void *_p !! 900 void parse_events_error(YYLTYPE *loc, void *parse_state, 768 void *scanner __maybe_ 901 void *scanner __maybe_unused, 769 char const *msg __mayb 902 char const *msg __maybe_unused) 770 { 903 { 771 struct parse_events_state *parse_state !! 904 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 } 905 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.