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; 281 int err = parse_events_multi_pmu_add_o << 282 230 >> 231 ALLOC_LIST(list); >> 232 ABORT_ON(parse_events_add_pmu(data, list, $1, $2)); 283 parse_events_terms__delete($2); 233 parse_events_terms__delete($2); 284 free($1); << 285 if (err) << 286 PE_ABORT(err); << 287 $$ = list; 234 $$ = list; 288 } 235 } 289 | 236 | 290 PE_NAME sep_dc !! 237 PE_KERNEL_PMU_EVENT sep_dc 291 { 238 { >> 239 struct parse_events_evlist *data = _data; >> 240 struct list_head *head; >> 241 struct parse_events_term *term; 292 struct list_head *list; 242 struct list_head *list; 293 int err; !! 243 struct perf_pmu *pmu = NULL; 294 !! 244 int ok = 0; 295 err = parse_events_multi_pmu_add(_pars << 296 if (err < 0) { << 297 struct parse_events_state *par << 298 struct parse_events_error *err << 299 char *help; << 300 245 301 if (asprintf(&help, "Unable to !! 246 /* Add it for all PMUs that support the alias */ 302 help = NULL; !! 247 ALLOC_LIST(list); 303 parse_events_error__handle(err !! 248 while ((pmu = perf_pmu__scan(pmu)) != NULL) { 304 free($1); !! 249 struct perf_pmu_alias *alias; 305 PE_ABORT(err); !! 250 >> 251 list_for_each_entry(alias, &pmu->aliases, list) { >> 252 if (!strcasecmp(alias->name, $1)) { >> 253 ALLOC_LIST(head); >> 254 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 255 $1, 1, false, &@1, NULL)); >> 256 list_add_tail(&term->list, head); >> 257 >> 258 if (!parse_events_add_pmu(data, list, >> 259 pmu->name, head)) { >> 260 pr_debug("%s -> %s/%s/\n", $1, >> 261 pmu->name, alias->str); >> 262 ok++; >> 263 } >> 264 >> 265 parse_events_terms__delete(head); >> 266 } >> 267 } 306 } 268 } 307 free($1); !! 269 if (!ok) >> 270 YYABORT; >> 271 $$ = list; >> 272 } >> 273 | >> 274 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc >> 275 { >> 276 struct parse_events_evlist *data = _data; >> 277 struct list_head *head; >> 278 struct parse_events_term *term; >> 279 struct list_head *list; >> 280 char pmu_name[128]; >> 281 snprintf(&pmu_name, 128, "%s-%s", $1, $3); >> 282 >> 283 ALLOC_LIST(head); >> 284 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 285 &pmu_name, 1, false, &@1, NULL)); >> 286 list_add_tail(&term->list, head); >> 287 >> 288 ALLOC_LIST(list); >> 289 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); >> 290 parse_events_terms__delete(head); 308 $$ = list; 291 $$ = list; 309 } 292 } 310 293 311 value_sym: 294 value_sym: 312 PE_VALUE_SYM_HW 295 PE_VALUE_SYM_HW 313 | 296 | 314 PE_VALUE_SYM_SW 297 PE_VALUE_SYM_SW 315 298 316 event_legacy_symbol: 299 event_legacy_symbol: 317 value_sym '/' event_config '/' 300 value_sym '/' event_config '/' 318 { 301 { >> 302 struct parse_events_evlist *data = _data; 319 struct list_head *list; 303 struct list_head *list; 320 int type = $1 >> 16; 304 int type = $1 >> 16; 321 int config = $1 & 255; 305 int config = $1 & 255; 322 int err; << 323 bool wildcard = (type == PERF_TYPE_HAR << 324 306 325 list = alloc_list(); !! 307 ALLOC_LIST(list); 326 if (!list) !! 308 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); 309 parse_events_terms__delete($3); 330 if (err) { << 331 free_list_evsel(list); << 332 PE_ABORT(err); << 333 } << 334 $$ = list; 310 $$ = list; 335 } 311 } 336 | 312 | 337 value_sym sep_slash_slash_dc !! 313 value_sym sep_slash_dc 338 { 314 { >> 315 struct parse_events_evlist *data = _data; 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(data, 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_evlist *data = _data; >> 329 struct parse_events_error *error = data->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, &data->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_evlist *data = _data; >> 341 struct parse_events_error *error = data->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, &data->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_evlist *data = _data; >> 353 struct parse_events_error *error = data->error; >> 354 struct list_head *list; 380 355 >> 356 ALLOC_LIST(list); >> 357 ABORT_ON(parse_events_add_cache(list, &data->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_evlist *data = _data; 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, &data->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_evlist *data = _data; 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, &data->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_evlist *data = _data; 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, &data->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_evlist *data = _data; 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, &data->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_evlist *data = _data; 472 struct parse_events_error *error = par !! 411 struct parse_events_error *error = data->error; 473 struct list_head *list; 412 struct list_head *list; 474 int err; << 475 413 476 list = alloc_list(); !! 414 ALLOC_LIST(list); 477 if (!list) !! 415 if (error) 478 YYNOMEM; !! 416 error->idx = @1.first_column; 479 417 480 err = parse_events_add_tracepoint(pars !! 418 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event, 481 error, !! 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 { >> 448 struct parse_events_evlist *data = _data; 504 struct list_head *list; 449 struct list_head *list; 505 int err; << 506 450 507 list = alloc_list(); !! 451 ALLOC_LIST(list); 508 if (!list) !! 452 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); 453 parse_events_terms__delete($4); 513 if (err) { << 514 free(list); << 515 PE_ABORT(err); << 516 } << 517 $$ = list; 454 $$ = list; 518 } 455 } 519 456 520 event_legacy_raw: 457 event_legacy_raw: 521 PE_RAW opt_event_config 458 PE_RAW opt_event_config 522 { 459 { >> 460 struct parse_events_evlist *data = _data; 523 struct list_head *list; 461 struct list_head *list; 524 int err; << 525 u64 num; << 526 462 527 list = alloc_list(); !! 463 ALLOC_LIST(list); 528 if (!list) !! 464 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); 465 parse_events_terms__delete($2); 539 if (err) { << 540 free(list); << 541 PE_ABORT(err); << 542 } << 543 $$ = list; 466 $$ = list; 544 } 467 } 545 468 546 opt_event_config: !! 469 event_bpf_file: 547 '/' event_config '/' !! 470 PE_BPF_OBJECT opt_event_config 548 { << 549 $$ = $2; << 550 } << 551 | << 552 '/' '/' << 553 { 471 { 554 $$ = NULL; !! 472 struct parse_events_evlist *data = _data; >> 473 struct parse_events_error *error = data->error; >> 474 struct list_head *list; >> 475 >> 476 ALLOC_LIST(list); >> 477 ABORT_ON(parse_events_load_bpf(data, list, $1, false, $2)); >> 478 parse_events_terms__delete($2); >> 479 $$ = list; 555 } 480 } 556 | 481 | >> 482 PE_BPF_SOURCE opt_event_config 557 { 483 { 558 $$ = NULL; !! 484 struct parse_events_evlist *data = _data; >> 485 struct list_head *list; >> 486 >> 487 ALLOC_LIST(list); >> 488 ABORT_ON(parse_events_load_bpf(data, list, $1, true, $2)); >> 489 parse_events_terms__delete($2); >> 490 $$ = list; 559 } 491 } 560 492 561 opt_pmu_config: !! 493 opt_event_config: 562 '/' event_config '/' 494 '/' event_config '/' 563 { 495 { 564 $$ = $2; 496 $$ = $2; 565 } 497 } 566 | 498 | 567 '/' '/' 499 '/' '/' 568 { 500 { 569 $$ = NULL; 501 $$ = NULL; 570 } 502 } >> 503 | >> 504 { >> 505 $$ = NULL; >> 506 } 571 507 572 start_terms: event_config 508 start_terms: event_config 573 { 509 { 574 struct parse_events_state *parse_state !! 510 struct parse_events_terms *data = _data; 575 if (parse_state->terms) { !! 511 data->terms = $1; 576 parse_events_terms__delete ($1 << 577 YYABORT; << 578 } << 579 parse_state->terms = $1; << 580 } 512 } 581 513 582 event_config: 514 event_config: 583 event_config ',' event_term 515 event_config ',' event_term 584 { 516 { 585 struct parse_events_terms *head = $1; !! 517 struct list_head *head = $1; 586 struct parse_events_term *term = $3; 518 struct parse_events_term *term = $3; 587 519 588 if (!head) { !! 520 ABORT_ON(!head); 589 parse_events_term__delete(term !! 521 list_add_tail(&term->list, head); 590 YYABORT; << 591 } << 592 list_add_tail(&term->list, &head->term << 593 $$ = $1; 522 $$ = $1; 594 } 523 } 595 | 524 | 596 event_term 525 event_term 597 { 526 { 598 struct parse_events_terms *head = mall !! 527 struct list_head *head = malloc(sizeof(*head)); 599 struct parse_events_term *term = $1; 528 struct parse_events_term *term = $1; 600 529 601 if (!head) !! 530 ABORT_ON(!head); 602 YYNOMEM; !! 531 INIT_LIST_HEAD(head); 603 parse_events_terms__init(head); !! 532 list_add_tail(&term->list, head); 604 list_add_tail(&term->list, &head->term << 605 $$ = head; 533 $$ = head; 606 } 534 } 607 535 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: 536 event_term: 616 PE_RAW !! 537 PE_NAME '=' PE_NAME 617 { 538 { 618 struct parse_events_term *term; 539 struct parse_events_term *term; 619 int err = parse_events_term__str(&term << 620 strdu << 621 540 622 if (err) { !! 541 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 623 free($1); !! 542 $1, $3, &@1, &@3)); 624 PE_ABORT(err); << 625 } << 626 $$ = term; 543 $$ = term; 627 } 544 } 628 | 545 | 629 name_or_raw '=' name_or_raw !! 546 PE_NAME '=' PE_VALUE 630 { 547 { 631 struct parse_events_term *term; 548 struct parse_events_term *term; 632 int err = parse_events_term__str(&term << 633 549 634 if (err) { !! 550 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 635 free($1); !! 551 $1, $3, false, &@1, &@3)); 636 free($3); << 637 PE_ABORT(err); << 638 } << 639 $$ = term; 552 $$ = term; 640 } 553 } 641 | 554 | 642 name_or_raw '=' PE_VALUE !! 555 PE_NAME '=' PE_VALUE_SYM_HW 643 { 556 { 644 struct parse_events_term *term; 557 struct parse_events_term *term; 645 int err = parse_events_term__num(&term !! 558 int config = $3 & 255; 646 $1, $ << 647 559 648 if (err) { !! 560 ABORT_ON(parse_events_term__sym_hw(&term, $1, config)); 649 free($1); << 650 PE_ABORT(err); << 651 } << 652 $$ = term; 561 $$ = term; 653 } 562 } 654 | 563 | 655 PE_LEGACY_CACHE !! 564 PE_NAME 656 { 565 { 657 struct parse_events_term *term; 566 struct parse_events_term *term; 658 int err = parse_events_term__num(&term << 659 $1, / << 660 567 661 if (err) { !! 568 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 662 free($1); !! 569 $1, 1, true, &@1, NULL)); 663 PE_ABORT(err); << 664 } << 665 $$ = term; 570 $$ = term; 666 } 571 } 667 | 572 | 668 PE_NAME !! 573 PE_VALUE_SYM_HW 669 { 574 { 670 struct parse_events_term *term; 575 struct parse_events_term *term; 671 int err = parse_events_term__num(&term !! 576 int config = $1 & 255; 672 $1, / << 673 577 674 if (err) { !! 578 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config)); 675 free($1); << 676 PE_ABORT(err); << 677 } << 678 $$ = term; 579 $$ = term; 679 } 580 } 680 | 581 | 681 PE_TERM_HW !! 582 PE_TERM '=' PE_NAME 682 { 583 { 683 struct parse_events_term *term; 584 struct parse_events_term *term; 684 int err = parse_events_term__num(&term << 685 $1.st << 686 &@1, << 687 585 688 if (err) { !! 586 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)); 689 free($1.str); << 690 PE_ABORT(err); << 691 } << 692 $$ = term; 587 $$ = term; 693 } 588 } 694 | 589 | 695 PE_TERM '=' name_or_raw !! 590 PE_TERM '=' PE_VALUE 696 { 591 { 697 struct parse_events_term *term; 592 struct parse_events_term *term; 698 int err = parse_events_term__str(&term << 699 593 700 if (err) { !! 594 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3)); 701 free($3); << 702 PE_ABORT(err); << 703 } << 704 $$ = term; 595 $$ = term; 705 } 596 } 706 | 597 | 707 PE_TERM '=' PE_TERM !! 598 PE_TERM 708 { 599 { 709 struct parse_events_term *term; 600 struct parse_events_term *term; 710 int err = parse_events_term__term(&ter << 711 << 712 if (err) << 713 PE_ABORT(err); << 714 601 >> 602 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL)); 715 $$ = term; 603 $$ = term; 716 } 604 } 717 | 605 | 718 PE_TERM '=' PE_VALUE !! 606 PE_NAME array '=' PE_NAME 719 { 607 { 720 struct parse_events_term *term; 608 struct parse_events_term *term; 721 int err = parse_events_term__num(&term !! 609 int i; 722 /*con << 723 &@1, << 724 610 725 if (err) !! 611 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 726 PE_ABORT(err); !! 612 $1, $4, &@1, &@4)); 727 613 >> 614 term->array = $2; 728 $$ = term; 615 $$ = term; 729 } 616 } 730 | 617 | 731 PE_TERM !! 618 PE_NAME array '=' PE_VALUE 732 { 619 { 733 struct parse_events_term *term; 620 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 621 >> 622 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 623 $1, $4, false, &@1, &@4)); >> 624 term->array = $2; 741 $$ = term; 625 $$ = term; 742 } 626 } 743 | 627 | 744 PE_DRV_CFG_TERM 628 PE_DRV_CFG_TERM 745 { 629 { 746 struct parse_events_term *term; 630 struct parse_events_term *term; 747 char *config = strdup($1); << 748 int err; << 749 631 750 if (!config) !! 632 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, 751 YYNOMEM; !! 633 $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; 634 $$ = term; 759 } 635 } 760 636 >> 637 array: >> 638 '[' array_terms ']' >> 639 { >> 640 $$ = $2; >> 641 } >> 642 | >> 643 PE_ARRAY_ALL >> 644 { >> 645 $$.nr_ranges = 0; >> 646 $$.ranges = NULL; >> 647 } >> 648 >> 649 array_terms: >> 650 array_terms ',' array_term >> 651 { >> 652 struct parse_events_array new_array; >> 653 >> 654 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; >> 655 new_array.ranges = malloc(sizeof(new_array.ranges[0]) * >> 656 new_array.nr_ranges); >> 657 ABORT_ON(!new_array.ranges); >> 658 memcpy(&new_array.ranges[0], $1.ranges, >> 659 $1.nr_ranges * sizeof(new_array.ranges[0])); >> 660 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, >> 661 $3.nr_ranges * sizeof(new_array.ranges[0])); >> 662 free($1.ranges); >> 663 free($3.ranges); >> 664 $$ = new_array; >> 665 } >> 666 | >> 667 array_term >> 668 >> 669 array_term: >> 670 PE_VALUE >> 671 { >> 672 struct parse_events_array array; >> 673 >> 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 = 1; >> 679 $$ = array; >> 680 } >> 681 | >> 682 PE_VALUE PE_ARRAY_RANGE PE_VALUE >> 683 { >> 684 struct parse_events_array array; >> 685 >> 686 ABORT_ON($3 < $1); >> 687 array.nr_ranges = 1; >> 688 array.ranges = malloc(sizeof(array.ranges[0])); >> 689 ABORT_ON(!array.ranges); >> 690 array.ranges[0].start = $1; >> 691 array.ranges[0].length = $3 - $1 + 1; >> 692 $$ = array; >> 693 } >> 694 761 sep_dc: ':' | 695 sep_dc: ':' | 762 696 763 sep_slash_slash_dc: '/' '/' | ':' | !! 697 sep_slash_dc: '/' | ':' | 764 698 765 %% 699 %% 766 700 767 void parse_events_error(YYLTYPE *loc, void *_p !! 701 void parse_events_error(YYLTYPE *loc, void *data, 768 void *scanner __maybe_ 702 void *scanner __maybe_unused, 769 char const *msg __mayb 703 char const *msg __maybe_unused) 770 { 704 { 771 struct parse_events_state *parse_state !! 705 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 } 706 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.