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