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