probe-event.c (4b3a2716dd785fabb9f6ac80c1d53cb29a88169d) | probe-event.c (c588d158124d5b60184fc612e551a19720720d68) |
---|---|
1/* 2 * probe-event.c : perf-probe definition to probe_events format converter 3 * 4 * Written by Masami Hiramatsu <mhiramat@redhat.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 1311 unchanged lines hidden (view full) --- 1320 free(name); 1321 return err; 1322} 1323 1324static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev) 1325{ 1326 char *ptr; 1327 | 1/* 2 * probe-event.c : perf-probe definition to probe_events format converter 3 * 4 * Written by Masami Hiramatsu <mhiramat@redhat.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 1311 unchanged lines hidden (view full) --- 1320 free(name); 1321 return err; 1322} 1323 1324static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev) 1325{ 1326 char *ptr; 1327 |
1328 ptr = strchr(*arg, ':'); | 1328 ptr = strpbrk_esc(*arg, ":"); |
1329 if (ptr) { 1330 *ptr = '\0'; 1331 if (!pev->sdt && !is_c_func_name(*arg)) 1332 goto ng_name; | 1329 if (ptr) { 1330 *ptr = '\0'; 1331 if (!pev->sdt && !is_c_func_name(*arg)) 1332 goto ng_name; |
1333 pev->group = strdup(*arg); | 1333 pev->group = strdup_esc(*arg); |
1334 if (!pev->group) 1335 return -ENOMEM; 1336 *arg = ptr + 1; 1337 } else 1338 pev->group = NULL; | 1334 if (!pev->group) 1335 return -ENOMEM; 1336 *arg = ptr + 1; 1337 } else 1338 pev->group = NULL; |
1339 if (!pev->sdt && !is_c_func_name(*arg)) { | 1339 1340 pev->event = strdup_esc(*arg); 1341 if (pev->event == NULL) 1342 return -ENOMEM; 1343 1344 if (!pev->sdt && !is_c_func_name(pev->event)) { 1345 zfree(&pev->event); |
1340ng_name: | 1346ng_name: |
1347 zfree(&pev->group); |
|
1341 semantic_error("%s is bad for event name -it must " 1342 "follow C symbol-naming rule.\n", *arg); 1343 return -EINVAL; 1344 } | 1348 semantic_error("%s is bad for event name -it must " 1349 "follow C symbol-naming rule.\n", *arg); 1350 return -EINVAL; 1351 } |
1345 pev->event = strdup(*arg); 1346 if (pev->event == NULL) 1347 return -ENOMEM; 1348 | |
1349 return 0; 1350} 1351 1352/* Parse probepoint definition. */ 1353static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) 1354{ 1355 struct perf_probe_point *pp = &pev->point; 1356 char *ptr, *tmp; --- 11 unchanged lines hidden (view full) --- 1368 return -EINVAL; 1369 1370 if (is_sdt_event(arg)) { 1371 pev->sdt = true; 1372 if (arg[0] == '%') 1373 arg++; 1374 } 1375 | 1352 return 0; 1353} 1354 1355/* Parse probepoint definition. */ 1356static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) 1357{ 1358 struct perf_probe_point *pp = &pev->point; 1359 char *ptr, *tmp; --- 11 unchanged lines hidden (view full) --- 1371 return -EINVAL; 1372 1373 if (is_sdt_event(arg)) { 1374 pev->sdt = true; 1375 if (arg[0] == '%') 1376 arg++; 1377 } 1378 |
1376 ptr = strpbrk(arg, ";=@+%"); | 1379 ptr = strpbrk_esc(arg, ";=@+%"); |
1377 if (pev->sdt) { 1378 if (ptr) { 1379 if (*ptr != '@') { 1380 semantic_error("%s must be an SDT name.\n", 1381 arg); 1382 return -EINVAL; 1383 } 1384 /* This must be a target file name or build id */ 1385 tmp = build_id_cache__complement(ptr + 1); 1386 if (tmp) { 1387 pev->target = build_id_cache__origname(tmp); 1388 free(tmp); 1389 } else | 1380 if (pev->sdt) { 1381 if (ptr) { 1382 if (*ptr != '@') { 1383 semantic_error("%s must be an SDT name.\n", 1384 arg); 1385 return -EINVAL; 1386 } 1387 /* This must be a target file name or build id */ 1388 tmp = build_id_cache__complement(ptr + 1); 1389 if (tmp) { 1390 pev->target = build_id_cache__origname(tmp); 1391 free(tmp); 1392 } else |
1390 pev->target = strdup(ptr + 1); | 1393 pev->target = strdup_esc(ptr + 1); |
1391 if (!pev->target) 1392 return -ENOMEM; 1393 *ptr = '\0'; 1394 } 1395 ret = parse_perf_probe_event_name(&arg, pev); 1396 if (ret == 0) { 1397 if (asprintf(&pev->point.function, "%%%s", pev->event) < 0) 1398 ret = -errno; --- 17 unchanged lines hidden (view full) --- 1416 * We consider arg to be a file spec if and only if it satisfies 1417 * all of the below criteria:: 1418 * - it does not include any of "+@%", 1419 * - it includes one of ":;", and 1420 * - it has a period '.' in the name. 1421 * 1422 * Otherwise, we consider arg to be a function specification. 1423 */ | 1394 if (!pev->target) 1395 return -ENOMEM; 1396 *ptr = '\0'; 1397 } 1398 ret = parse_perf_probe_event_name(&arg, pev); 1399 if (ret == 0) { 1400 if (asprintf(&pev->point.function, "%%%s", pev->event) < 0) 1401 ret = -errno; --- 17 unchanged lines hidden (view full) --- 1419 * We consider arg to be a file spec if and only if it satisfies 1420 * all of the below criteria:: 1421 * - it does not include any of "+@%", 1422 * - it includes one of ":;", and 1423 * - it has a period '.' in the name. 1424 * 1425 * Otherwise, we consider arg to be a function specification. 1426 */ |
1424 if (!strpbrk(arg, "+@%") && (ptr = strpbrk(arg, ";:")) != NULL) { | 1427 if (!strpbrk_esc(arg, "+@%")) { 1428 ptr = strpbrk_esc(arg, ";:"); |
1425 /* This is a file spec if it includes a '.' before ; or : */ | 1429 /* This is a file spec if it includes a '.' before ; or : */ |
1426 if (memchr(arg, '.', ptr - arg)) | 1430 if (ptr && memchr(arg, '.', ptr - arg)) |
1427 file_spec = true; 1428 } 1429 | 1431 file_spec = true; 1432 } 1433 |
1430 ptr = strpbrk(arg, ";:+@%"); | 1434 ptr = strpbrk_esc(arg, ";:+@%"); |
1431 if (ptr) { 1432 nc = *ptr; 1433 *ptr++ = '\0'; 1434 } 1435 1436 if (arg[0] == '\0') 1437 tmp = NULL; 1438 else { | 1435 if (ptr) { 1436 nc = *ptr; 1437 *ptr++ = '\0'; 1438 } 1439 1440 if (arg[0] == '\0') 1441 tmp = NULL; 1442 else { |
1439 tmp = strdup(arg); | 1443 tmp = strdup_esc(arg); |
1440 if (tmp == NULL) 1441 return -ENOMEM; 1442 } 1443 1444 if (file_spec) 1445 pp->file = tmp; 1446 else { 1447 pp->function = tmp; --- 16 unchanged lines hidden (view full) --- 1464 } 1465 } 1466 1467 /* Parse other options */ 1468 while (ptr) { 1469 arg = ptr; 1470 c = nc; 1471 if (c == ';') { /* Lazy pattern must be the last part */ | 1444 if (tmp == NULL) 1445 return -ENOMEM; 1446 } 1447 1448 if (file_spec) 1449 pp->file = tmp; 1450 else { 1451 pp->function = tmp; --- 16 unchanged lines hidden (view full) --- 1468 } 1469 } 1470 1471 /* Parse other options */ 1472 while (ptr) { 1473 arg = ptr; 1474 c = nc; 1475 if (c == ';') { /* Lazy pattern must be the last part */ |
1472 pp->lazy_line = strdup(arg); | 1476 pp->lazy_line = strdup(arg); /* let leave escapes */ |
1473 if (pp->lazy_line == NULL) 1474 return -ENOMEM; 1475 break; 1476 } | 1477 if (pp->lazy_line == NULL) 1478 return -ENOMEM; 1479 break; 1480 } |
1477 ptr = strpbrk(arg, ";:+@%"); | 1481 ptr = strpbrk_esc(arg, ";:+@%"); |
1478 if (ptr) { 1479 nc = *ptr; 1480 *ptr++ = '\0'; 1481 } 1482 switch (c) { 1483 case ':': /* Line number */ 1484 pp->line = strtoul(arg, &tmp, 0); 1485 if (*tmp != '\0') { --- 10 unchanged lines hidden (view full) --- 1496 return -EINVAL; 1497 } 1498 break; 1499 case '@': /* File name */ 1500 if (pp->file) { 1501 semantic_error("SRC@SRC is not allowed.\n"); 1502 return -EINVAL; 1503 } | 1482 if (ptr) { 1483 nc = *ptr; 1484 *ptr++ = '\0'; 1485 } 1486 switch (c) { 1487 case ':': /* Line number */ 1488 pp->line = strtoul(arg, &tmp, 0); 1489 if (*tmp != '\0') { --- 10 unchanged lines hidden (view full) --- 1500 return -EINVAL; 1501 } 1502 break; 1503 case '@': /* File name */ 1504 if (pp->file) { 1505 semantic_error("SRC@SRC is not allowed.\n"); 1506 return -EINVAL; 1507 } |
1504 pp->file = strdup(arg); | 1508 pp->file = strdup_esc(arg); |
1505 if (pp->file == NULL) 1506 return -ENOMEM; 1507 break; 1508 case '%': /* Probe places */ 1509 if (strcmp(arg, "return") == 0) { 1510 pp->retprobe = 1; 1511 } else { /* Others not supported yet */ 1512 semantic_error("%%%s is not supported.\n", arg); --- 1285 unchanged lines hidden (view full) --- 2798static int find_probe_functions(struct map *map, char *name, 2799 struct symbol **syms) 2800{ 2801 int found = 0; 2802 struct symbol *sym; 2803 struct rb_node *tmp; 2804 const char *norm, *ver; 2805 char *buf = NULL; | 1509 if (pp->file == NULL) 1510 return -ENOMEM; 1511 break; 1512 case '%': /* Probe places */ 1513 if (strcmp(arg, "return") == 0) { 1514 pp->retprobe = 1; 1515 } else { /* Others not supported yet */ 1516 semantic_error("%%%s is not supported.\n", arg); --- 1285 unchanged lines hidden (view full) --- 2802static int find_probe_functions(struct map *map, char *name, 2803 struct symbol **syms) 2804{ 2805 int found = 0; 2806 struct symbol *sym; 2807 struct rb_node *tmp; 2808 const char *norm, *ver; 2809 char *buf = NULL; |
2810 bool cut_version = true; |
|
2806 2807 if (map__load(map) < 0) 2808 return 0; 2809 | 2811 2812 if (map__load(map) < 0) 2813 return 0; 2814 |
2815 /* If user gives a version, don't cut off the version from symbols */ 2816 if (strchr(name, '@')) 2817 cut_version = false; 2818 |
|
2810 map__for_each_symbol(map, sym, tmp) { 2811 norm = arch__normalize_symbol_name(sym->name); 2812 if (!norm) 2813 continue; 2814 | 2819 map__for_each_symbol(map, sym, tmp) { 2820 norm = arch__normalize_symbol_name(sym->name); 2821 if (!norm) 2822 continue; 2823 |
2815 /* We don't care about default symbol or not */ 2816 ver = strchr(norm, '@'); 2817 if (ver) { 2818 buf = strndup(norm, ver - norm); 2819 if (!buf) 2820 return -ENOMEM; 2821 norm = buf; | 2824 if (cut_version) { 2825 /* We don't care about default symbol or not */ 2826 ver = strchr(norm, '@'); 2827 if (ver) { 2828 buf = strndup(norm, ver - norm); 2829 if (!buf) 2830 return -ENOMEM; 2831 norm = buf; 2832 } |
2822 } | 2833 } |
2834 |
|
2823 if (strglobmatch(norm, name)) { 2824 found++; 2825 if (syms && found < probe_conf.max_probes) 2826 syms[found - 1] = sym; 2827 } 2828 if (buf) 2829 zfree(&buf); 2830 } --- 703 unchanged lines hidden --- | 2835 if (strglobmatch(norm, name)) { 2836 found++; 2837 if (syms && found < probe_conf.max_probes) 2838 syms[found - 1] = sym; 2839 } 2840 if (buf) 2841 zfree(&buf); 2842 } --- 703 unchanged lines hidden --- |