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