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