1 %define api.pure full !! 1 %pure-parser 2 %parse-param {void *_parse_state} !! 2 %parse-param {void *_data} 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 !! 20 void parse_events_error(YYLTYPE *loc, void *data, void *scanner, char const *msg); 23 void parse_events_error(YYLTYPE *loc, void *pa << 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_evlist *data) 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 data->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 !! 118 struct parse_events_evlist *data = _data; 142 struct list_head *groups = $1; << 143 struct parse_events_state *parse_state << 144 119 145 list_splice_tail(groups, &parse_state- !! 120 parse_events_update_lists($1, &data->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, _data); 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, _data); 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 parse_events_evlist *data = _data; 280 struct list_head *list = NULL; !! 229 struct list_head *list, *orig_terms, *terms; 281 int err = parse_events_multi_pmu_add_o !! 230 >> 231 if (parse_events_copy_term_list($2, &orig_terms)) >> 232 YYABORT; 282 233 >> 234 ALLOC_LIST(list); >> 235 if (parse_events_add_pmu(data, list, $1, $2)) { >> 236 struct perf_pmu *pmu = NULL; >> 237 int ok = 0; >> 238 >> 239 while ((pmu = perf_pmu__scan(pmu)) != NULL) { >> 240 char *name = pmu->name; >> 241 >> 242 if (!strncmp(name, "uncore_", 7) && >> 243 strncmp($1, "uncore_", 7)) >> 244 name += 7; >> 245 if (!strncmp($1, name, strlen($1))) { >> 246 if (parse_events_copy_term_list(orig_terms, &terms)) >> 247 YYABORT; >> 248 if (!parse_events_add_pmu(data, list, pmu->name, terms)) >> 249 ok++; >> 250 parse_events_terms__delete(terms); >> 251 } >> 252 } >> 253 if (!ok) >> 254 YYABORT; >> 255 } 283 parse_events_terms__delete($2); 256 parse_events_terms__delete($2); 284 free($1); !! 257 parse_events_terms__delete(orig_terms); 285 if (err) << 286 PE_ABORT(err); << 287 $$ = list; 258 $$ = list; 288 } 259 } 289 | 260 | 290 PE_NAME sep_dc !! 261 PE_KERNEL_PMU_EVENT sep_dc 291 { 262 { 292 struct list_head *list; 263 struct list_head *list; 293 int err; << 294 264 295 err = parse_events_multi_pmu_add(_pars !! 265 if (parse_events_multi_pmu_add(_data, $1, &list) < 0) 296 if (err < 0) { !! 266 YYABORT; 297 struct parse_events_state *par !! 267 $$ = list; 298 struct parse_events_error *err !! 268 } 299 char *help; !! 269 | >> 270 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc >> 271 { >> 272 struct list_head *list; >> 273 char pmu_name[128]; 300 274 301 if (asprintf(&help, "Unable to !! 275 snprintf(&pmu_name, 128, "%s-%s", $1, $3); 302 help = NULL; !! 276 if (parse_events_multi_pmu_add(_data, pmu_name, &list) < 0) 303 parse_events_error__handle(err !! 277 YYABORT; 304 free($1); << 305 PE_ABORT(err); << 306 } << 307 free($1); << 308 $$ = list; 278 $$ = list; 309 } 279 } 310 280 311 value_sym: 281 value_sym: 312 PE_VALUE_SYM_HW 282 PE_VALUE_SYM_HW 313 | 283 | 314 PE_VALUE_SYM_SW 284 PE_VALUE_SYM_SW 315 285 316 event_legacy_symbol: 286 event_legacy_symbol: 317 value_sym '/' event_config '/' 287 value_sym '/' event_config '/' 318 { 288 { >> 289 struct parse_events_evlist *data = _data; 319 struct list_head *list; 290 struct list_head *list; 320 int type = $1 >> 16; 291 int type = $1 >> 16; 321 int config = $1 & 255; 292 int config = $1 & 255; 322 int err; << 323 bool wildcard = (type == PERF_TYPE_HAR << 324 293 325 list = alloc_list(); !! 294 ALLOC_LIST(list); 326 if (!list) !! 295 ABORT_ON(parse_events_add_numeric(data, list, type, config, $3)); 327 YYNOMEM; << 328 err = parse_events_add_numeric(_parse_ << 329 parse_events_terms__delete($3); 296 parse_events_terms__delete($3); 330 if (err) { << 331 free_list_evsel(list); << 332 PE_ABORT(err); << 333 } << 334 $$ = list; 297 $$ = list; 335 } 298 } 336 | 299 | 337 value_sym sep_slash_slash_dc !! 300 value_sym sep_slash_dc 338 { 301 { >> 302 struct parse_events_evlist *data = _data; 339 struct list_head *list; 303 struct list_head *list; 340 int type = $1 >> 16; 304 int type = $1 >> 16; 341 int config = $1 & 255; 305 int config = $1 & 255; 342 bool wildcard = (type == PERF_TYPE_HAR << 343 int err; << 344 306 345 list = alloc_list(); !! 307 ALLOC_LIST(list); 346 if (!list) !! 308 ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL)); 347 YYNOMEM; << 348 err = parse_events_add_numeric(_parse_ << 349 if (err) << 350 PE_ABORT(err); << 351 $$ = list; 309 $$ = list; 352 } 310 } 353 | !! 311 354 PE_VALUE_SYM_TOOL sep_slash_slash_dc !! 312 event_legacy_cache: >> 313 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config 355 { 314 { >> 315 struct parse_events_evlist *data = _data; >> 316 struct parse_events_error *error = data->error; 356 struct list_head *list; 317 struct list_head *list; 357 int err; << 358 318 359 list = alloc_list(); !! 319 ALLOC_LIST(list); 360 if (!list) !! 320 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5, error, $6)); 361 YYNOMEM; !! 321 parse_events_terms__delete($6); 362 err = parse_events_add_tool(_parse_sta << 363 if (err) << 364 YYNOMEM; << 365 $$ = list; 322 $$ = list; 366 } 323 } 367 !! 324 | 368 event_legacy_cache: !! 325 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config 369 PE_LEGACY_CACHE opt_event_config << 370 { 326 { 371 struct parse_events_state *parse_state !! 327 struct parse_events_evlist *data = _data; >> 328 struct parse_events_error *error = data->error; 372 struct list_head *list; 329 struct list_head *list; 373 int err; << 374 330 375 list = alloc_list(); !! 331 ALLOC_LIST(list); 376 if (!list) !! 332 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL, error, $4)); 377 YYNOMEM; !! 333 parse_events_terms__delete($4); 378 !! 334 $$ = list; 379 err = parse_events_add_cache(list, &pa !! 335 } >> 336 | >> 337 PE_NAME_CACHE_TYPE opt_event_config >> 338 { >> 339 struct parse_events_evlist *data = _data; >> 340 struct parse_events_error *error = data->error; >> 341 struct list_head *list; 380 342 >> 343 ALLOC_LIST(list); >> 344 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL, error, $2)); 381 parse_events_terms__delete($2); 345 parse_events_terms__delete($2); 382 free($1); << 383 if (err) { << 384 free_list_evsel(list); << 385 PE_ABORT(err); << 386 } << 387 $$ = list; 346 $$ = list; 388 } 347 } 389 348 390 event_legacy_mem: 349 event_legacy_mem: 391 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE !! 350 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc 392 { 351 { >> 352 struct parse_events_evlist *data = _data; 393 struct list_head *list; 353 struct list_head *list; 394 int err; << 395 354 396 list = alloc_list(); !! 355 ALLOC_LIST(list); 397 if (!list) !! 356 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 398 YYNOMEM; !! 357 (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; 358 $$ = list; 409 } 359 } 410 | 360 | 411 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE op !! 361 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc 412 { 362 { >> 363 struct parse_events_evlist *data = _data; 413 struct list_head *list; 364 struct list_head *list; 414 int err; << 415 << 416 list = alloc_list(); << 417 if (!list) << 418 YYNOMEM; << 419 365 420 err = parse_events_add_breakpoint(_par !! 366 ALLOC_LIST(list); 421 $2, !! 367 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 422 parse_events_terms__delete($5); !! 368 (void *) $2, NULL, $4)); 423 if (err) { << 424 free(list); << 425 PE_ABORT(err); << 426 } << 427 $$ = list; 369 $$ = list; 428 } 370 } 429 | 371 | 430 PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER !! 372 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc 431 { 373 { >> 374 struct parse_events_evlist *data = _data; 432 struct list_head *list; 375 struct list_head *list; 433 int err; << 434 376 435 list = alloc_list(); !! 377 ALLOC_LIST(list); 436 if (!list) !! 378 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 437 YYNOMEM; !! 379 (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; 380 $$ = list; 448 } 381 } 449 | 382 | 450 PE_PREFIX_MEM PE_VALUE opt_event_config !! 383 PE_PREFIX_MEM PE_VALUE sep_dc 451 { 384 { >> 385 struct parse_events_evlist *data = _data; 452 struct list_head *list; 386 struct list_head *list; 453 int err; << 454 387 455 list = alloc_list(); !! 388 ALLOC_LIST(list); 456 if (!list) !! 389 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 457 YYNOMEM; !! 390 (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; 391 $$ = list; 466 } 392 } 467 393 468 event_legacy_tracepoint: 394 event_legacy_tracepoint: 469 tracepoint_name opt_event_config 395 tracepoint_name opt_event_config 470 { 396 { 471 struct parse_events_state *parse_state !! 397 struct parse_events_evlist *data = _data; 472 struct parse_events_error *error = par !! 398 struct parse_events_error *error = data->error; 473 struct list_head *list; 399 struct list_head *list; 474 int err; << 475 400 476 list = alloc_list(); !! 401 ALLOC_LIST(list); 477 if (!list) !! 402 if (error) 478 YYNOMEM; !! 403 error->idx = @1.first_column; 479 404 480 err = parse_events_add_tracepoint(pars !! 405 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event, 481 error, !! 406 error, $2)) >> 407 return -1; 482 408 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; 409 $$ = list; 491 } 410 } 492 411 493 tracepoint_name: 412 tracepoint_name: >> 413 PE_NAME '-' PE_NAME ':' PE_NAME >> 414 { >> 415 char sys_name[128]; >> 416 struct tracepoint_name tracepoint; >> 417 >> 418 snprintf(&sys_name, 128, "%s-%s", $1, $3); >> 419 tracepoint.sys = &sys_name; >> 420 tracepoint.event = $5; >> 421 >> 422 $$ = tracepoint; >> 423 } >> 424 | 494 PE_NAME ':' PE_NAME 425 PE_NAME ':' PE_NAME 495 { 426 { 496 struct tracepoint_name tracepoint = {$ 427 struct tracepoint_name tracepoint = {$1, $3}; 497 428 498 $$ = tracepoint; 429 $$ = tracepoint; 499 } 430 } 500 431 501 event_legacy_numeric: 432 event_legacy_numeric: 502 PE_VALUE ':' PE_VALUE opt_event_config 433 PE_VALUE ':' PE_VALUE opt_event_config 503 { 434 { >> 435 struct parse_events_evlist *data = _data; 504 struct list_head *list; 436 struct list_head *list; 505 int err; << 506 437 507 list = alloc_list(); !! 438 ALLOC_LIST(list); 508 if (!list) !! 439 ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4)); 509 YYNOMEM; << 510 err = parse_events_add_numeric(_parse_ << 511 /*wildc << 512 parse_events_terms__delete($4); 440 parse_events_terms__delete($4); 513 if (err) { << 514 free(list); << 515 PE_ABORT(err); << 516 } << 517 $$ = list; 441 $$ = list; 518 } 442 } 519 443 520 event_legacy_raw: 444 event_legacy_raw: 521 PE_RAW opt_event_config 445 PE_RAW opt_event_config 522 { 446 { >> 447 struct parse_events_evlist *data = _data; 523 struct list_head *list; 448 struct list_head *list; 524 int err; << 525 u64 num; << 526 449 527 list = alloc_list(); !! 450 ALLOC_LIST(list); 528 if (!list) !! 451 ABORT_ON(parse_events_add_numeric(data, 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); 452 parse_events_terms__delete($2); 539 if (err) { << 540 free(list); << 541 PE_ABORT(err); << 542 } << 543 $$ = list; 453 $$ = list; 544 } 454 } 545 455 546 opt_event_config: !! 456 event_bpf_file: 547 '/' event_config '/' !! 457 PE_BPF_OBJECT opt_event_config 548 { 458 { 549 $$ = $2; !! 459 struct parse_events_evlist *data = _data; 550 } !! 460 struct parse_events_error *error = data->error; 551 | !! 461 struct list_head *list; 552 '/' '/' !! 462 553 { !! 463 ALLOC_LIST(list); 554 $$ = NULL; !! 464 ABORT_ON(parse_events_load_bpf(data, list, $1, false, $2)); >> 465 parse_events_terms__delete($2); >> 466 $$ = list; 555 } 467 } 556 | 468 | >> 469 PE_BPF_SOURCE opt_event_config 557 { 470 { 558 $$ = NULL; !! 471 struct parse_events_evlist *data = _data; >> 472 struct list_head *list; >> 473 >> 474 ALLOC_LIST(list); >> 475 ABORT_ON(parse_events_load_bpf(data, list, $1, true, $2)); >> 476 parse_events_terms__delete($2); >> 477 $$ = list; 559 } 478 } 560 479 561 opt_pmu_config: !! 480 opt_event_config: 562 '/' event_config '/' 481 '/' event_config '/' 563 { 482 { 564 $$ = $2; 483 $$ = $2; 565 } 484 } 566 | 485 | 567 '/' '/' 486 '/' '/' 568 { 487 { 569 $$ = NULL; 488 $$ = NULL; 570 } 489 } >> 490 | >> 491 { >> 492 $$ = NULL; >> 493 } 571 494 572 start_terms: event_config 495 start_terms: event_config 573 { 496 { 574 struct parse_events_state *parse_state !! 497 struct parse_events_terms *data = _data; 575 if (parse_state->terms) { !! 498 data->terms = $1; 576 parse_events_terms__delete ($1 << 577 YYABORT; << 578 } << 579 parse_state->terms = $1; << 580 } 499 } 581 500 582 event_config: 501 event_config: 583 event_config ',' event_term 502 event_config ',' event_term 584 { 503 { 585 struct parse_events_terms *head = $1; !! 504 struct list_head *head = $1; 586 struct parse_events_term *term = $3; 505 struct parse_events_term *term = $3; 587 506 588 if (!head) { !! 507 ABORT_ON(!head); 589 parse_events_term__delete(term !! 508 list_add_tail(&term->list, head); 590 YYABORT; << 591 } << 592 list_add_tail(&term->list, &head->term << 593 $$ = $1; 509 $$ = $1; 594 } 510 } 595 | 511 | 596 event_term 512 event_term 597 { 513 { 598 struct parse_events_terms *head = mall !! 514 struct list_head *head = malloc(sizeof(*head)); 599 struct parse_events_term *term = $1; 515 struct parse_events_term *term = $1; 600 516 601 if (!head) !! 517 ABORT_ON(!head); 602 YYNOMEM; !! 518 INIT_LIST_HEAD(head); 603 parse_events_terms__init(head); !! 519 list_add_tail(&term->list, head); 604 list_add_tail(&term->list, &head->term << 605 $$ = head; 520 $$ = head; 606 } 521 } 607 522 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: 523 event_term: 616 PE_RAW !! 524 PE_NAME '=' PE_NAME 617 { 525 { 618 struct parse_events_term *term; 526 struct parse_events_term *term; 619 int err = parse_events_term__str(&term << 620 strdu << 621 527 622 if (err) { !! 528 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 623 free($1); !! 529 $1, $3, &@1, &@3)); 624 PE_ABORT(err); << 625 } << 626 $$ = term; 530 $$ = term; 627 } 531 } 628 | 532 | 629 name_or_raw '=' name_or_raw !! 533 PE_NAME '=' PE_VALUE 630 { 534 { 631 struct parse_events_term *term; 535 struct parse_events_term *term; 632 int err = parse_events_term__str(&term << 633 536 634 if (err) { !! 537 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 635 free($1); !! 538 $1, $3, false, &@1, &@3)); 636 free($3); << 637 PE_ABORT(err); << 638 } << 639 $$ = term; 539 $$ = term; 640 } 540 } 641 | 541 | 642 name_or_raw '=' PE_VALUE !! 542 PE_NAME '=' PE_VALUE_SYM_HW 643 { 543 { 644 struct parse_events_term *term; 544 struct parse_events_term *term; 645 int err = parse_events_term__num(&term !! 545 int config = $3 & 255; 646 $1, $ << 647 546 648 if (err) { !! 547 ABORT_ON(parse_events_term__sym_hw(&term, $1, config)); 649 free($1); << 650 PE_ABORT(err); << 651 } << 652 $$ = term; 548 $$ = term; 653 } 549 } 654 | 550 | 655 PE_LEGACY_CACHE !! 551 PE_NAME 656 { 552 { 657 struct parse_events_term *term; 553 struct parse_events_term *term; 658 int err = parse_events_term__num(&term << 659 $1, / << 660 554 661 if (err) { !! 555 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 662 free($1); !! 556 $1, 1, true, &@1, NULL)); 663 PE_ABORT(err); << 664 } << 665 $$ = term; 557 $$ = term; 666 } 558 } 667 | 559 | 668 PE_NAME !! 560 PE_VALUE_SYM_HW 669 { 561 { 670 struct parse_events_term *term; 562 struct parse_events_term *term; 671 int err = parse_events_term__num(&term !! 563 int config = $1 & 255; 672 $1, / << 673 564 674 if (err) { !! 565 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config)); 675 free($1); << 676 PE_ABORT(err); << 677 } << 678 $$ = term; 566 $$ = term; 679 } 567 } 680 | 568 | 681 PE_TERM_HW !! 569 PE_TERM '=' PE_NAME 682 { 570 { 683 struct parse_events_term *term; 571 struct parse_events_term *term; 684 int err = parse_events_term__num(&term << 685 $1.st << 686 &@1, << 687 572 688 if (err) { !! 573 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)); 689 free($1.str); << 690 PE_ABORT(err); << 691 } << 692 $$ = term; 574 $$ = term; 693 } 575 } 694 | 576 | 695 PE_TERM '=' name_or_raw !! 577 PE_TERM '=' PE_VALUE 696 { 578 { 697 struct parse_events_term *term; 579 struct parse_events_term *term; 698 int err = parse_events_term__str(&term << 699 580 700 if (err) { !! 581 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3)); 701 free($3); << 702 PE_ABORT(err); << 703 } << 704 $$ = term; 582 $$ = term; 705 } 583 } 706 | 584 | 707 PE_TERM '=' PE_TERM !! 585 PE_TERM 708 { 586 { 709 struct parse_events_term *term; 587 struct parse_events_term *term; 710 int err = parse_events_term__term(&ter << 711 << 712 if (err) << 713 PE_ABORT(err); << 714 588 >> 589 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL)); 715 $$ = term; 590 $$ = term; 716 } 591 } 717 | 592 | 718 PE_TERM '=' PE_VALUE !! 593 PE_NAME array '=' PE_NAME 719 { 594 { 720 struct parse_events_term *term; 595 struct parse_events_term *term; 721 int err = parse_events_term__num(&term !! 596 int i; 722 /*con << 723 &@1, << 724 597 725 if (err) !! 598 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 726 PE_ABORT(err); !! 599 $1, $4, &@1, &@4)); 727 600 >> 601 term->array = $2; 728 $$ = term; 602 $$ = term; 729 } 603 } 730 | 604 | 731 PE_TERM !! 605 PE_NAME array '=' PE_VALUE 732 { 606 { 733 struct parse_events_term *term; 607 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 608 >> 609 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 610 $1, $4, false, &@1, &@4)); >> 611 term->array = $2; 741 $$ = term; 612 $$ = term; 742 } 613 } 743 | 614 | 744 PE_DRV_CFG_TERM 615 PE_DRV_CFG_TERM 745 { 616 { 746 struct parse_events_term *term; 617 struct parse_events_term *term; 747 char *config = strdup($1); << 748 int err; << 749 618 750 if (!config) !! 619 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, 751 YYNOMEM; !! 620 $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; 621 $$ = term; 759 } 622 } 760 623 >> 624 array: >> 625 '[' array_terms ']' >> 626 { >> 627 $$ = $2; >> 628 } >> 629 | >> 630 PE_ARRAY_ALL >> 631 { >> 632 $$.nr_ranges = 0; >> 633 $$.ranges = NULL; >> 634 } >> 635 >> 636 array_terms: >> 637 array_terms ',' array_term >> 638 { >> 639 struct parse_events_array new_array; >> 640 >> 641 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; >> 642 new_array.ranges = malloc(sizeof(new_array.ranges[0]) * >> 643 new_array.nr_ranges); >> 644 ABORT_ON(!new_array.ranges); >> 645 memcpy(&new_array.ranges[0], $1.ranges, >> 646 $1.nr_ranges * sizeof(new_array.ranges[0])); >> 647 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, >> 648 $3.nr_ranges * sizeof(new_array.ranges[0])); >> 649 free($1.ranges); >> 650 free($3.ranges); >> 651 $$ = new_array; >> 652 } >> 653 | >> 654 array_term >> 655 >> 656 array_term: >> 657 PE_VALUE >> 658 { >> 659 struct parse_events_array array; >> 660 >> 661 array.nr_ranges = 1; >> 662 array.ranges = malloc(sizeof(array.ranges[0])); >> 663 ABORT_ON(!array.ranges); >> 664 array.ranges[0].start = $1; >> 665 array.ranges[0].length = 1; >> 666 $$ = array; >> 667 } >> 668 | >> 669 PE_VALUE PE_ARRAY_RANGE PE_VALUE >> 670 { >> 671 struct parse_events_array array; >> 672 >> 673 ABORT_ON($3 < $1); >> 674 array.nr_ranges = 1; >> 675 array.ranges = malloc(sizeof(array.ranges[0])); >> 676 ABORT_ON(!array.ranges); >> 677 array.ranges[0].start = $1; >> 678 array.ranges[0].length = $3 - $1 + 1; >> 679 $$ = array; >> 680 } >> 681 761 sep_dc: ':' | 682 sep_dc: ':' | 762 683 763 sep_slash_slash_dc: '/' '/' | ':' | !! 684 sep_slash_dc: '/' | ':' | 764 685 765 %% 686 %% 766 687 767 void parse_events_error(YYLTYPE *loc, void *_p !! 688 void parse_events_error(YYLTYPE *loc, void *data, 768 void *scanner __maybe_ 689 void *scanner __maybe_unused, 769 char const *msg __mayb 690 char const *msg __maybe_unused) 770 { 691 { 771 struct parse_events_state *parse_state !! 692 parse_events_evlist_error(data, 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 } 693 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.