aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parse-events.c206
-rw-r--r--trace-read.c2
2 files changed, 157 insertions, 51 deletions
diff --git a/parse-events.c b/parse-events.c
index 01588c5..82477a7 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -557,6 +557,19 @@ static int event_item_type(enum event_type type)
557 } 557 }
558} 558}
559 559
560static void free_flag_sym(struct print_flag_sym *fsym)
561{
562 struct print_flag_sym *next;
563
564 while (fsym) {
565 next = fsym->next;
566 free(fsym->value);
567 free(fsym->str);
568 free(fsym);
569 fsym = next;
570 }
571}
572
560static void free_arg(struct print_arg *arg) 573static void free_arg(struct print_arg *arg)
561{ 574{
562 if (!arg) 575 if (!arg)
@@ -564,13 +577,37 @@ static void free_arg(struct print_arg *arg)
564 577
565 switch (arg->type) { 578 switch (arg->type) {
566 case PRINT_ATOM: 579 case PRINT_ATOM:
567 if (arg->atom.atom) 580 free(arg->atom.atom);
568 free(arg->atom.atom); 581 break;
582 case PRINT_FIELD:
583 free(arg->field.name);
584 break;
585 case PRINT_FLAGS:
586 free_arg(arg->flags.field);
587 free(arg->flags.delim);
588 free_flag_sym(arg->flags.flags);
589 break;
590 case PRINT_SYMBOL:
591 free_arg(arg->symbol.field);
592 free_flag_sym(arg->symbol.symbols);
593 break;
594 case PRINT_TYPE:
595 free(arg->typecast.type);
596 free_arg(arg->typecast.item);
569 break; 597 break;
598 case PRINT_STRING:
599 free(arg->string.string);
600 break;
601 case PRINT_DYNAMIC_ARRAY:
602 free(arg->dynarray.index);
603 break;
604 case PRINT_OP:
605 free(arg->op.op);
606 free_arg(arg->op.left);
607 free_arg(arg->op.right);
608
570 case PRINT_NULL: 609 case PRINT_NULL:
571 case PRINT_FIELD ... PRINT_OP:
572 default: 610 default:
573 /* todo */
574 break; 611 break;
575 } 612 }
576 613
@@ -825,6 +862,7 @@ static enum event_type read_token(char **tok)
825 } 862 }
826 863
827 /* not reached */ 864 /* not reached */
865 *tok = NULL;
828 return EVENT_NONE; 866 return EVENT_NONE;
829} 867}
830 868
@@ -837,11 +875,12 @@ static enum event_type read_token_item(char **tok)
837 type = __read_token(tok); 875 type = __read_token(tok);
838 if (type != EVENT_SPACE && type != EVENT_NEWLINE) 876 if (type != EVENT_SPACE && type != EVENT_NEWLINE)
839 return type; 877 return type;
840
841 free_token(*tok); 878 free_token(*tok);
879 *tok = NULL;
842 } 880 }
843 881
844 /* not reached */ 882 /* not reached */
883 *tok = NULL;
845 return EVENT_NONE; 884 return EVENT_NONE;
846} 885}
847 886
@@ -1011,8 +1050,9 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1011 } 1050 }
1012 1051
1013 if (test_type_token(type, token, EVENT_OP, ":") < 0) 1052 if (test_type_token(type, token, EVENT_OP, ":") < 0)
1014 return -1; 1053 goto fail;
1015 1054
1055 free_token(token);
1016 if (read_expect_type(EVENT_ITEM, &token) < 0) 1056 if (read_expect_type(EVENT_ITEM, &token) < 0)
1017 goto fail; 1057 goto fail;
1018 1058
@@ -1043,6 +1083,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1043 strlen(last_token) + 2); 1083 strlen(last_token) + 2);
1044 strcat(field->type, " "); 1084 strcat(field->type, " ");
1045 strcat(field->type, last_token); 1085 strcat(field->type, last_token);
1086 free(last_token);
1046 } else 1087 } else
1047 field->type = last_token; 1088 field->type = last_token;
1048 last_token = token; 1089 last_token = token;
@@ -1281,6 +1322,7 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok)
1281 1322
1282out_free: 1323out_free:
1283 free_token(*tok); 1324 free_token(*tok);
1325 *tok = NULL;
1284 free(right); 1326 free(right);
1285 free(left); 1327 free(left);
1286 free_arg(arg); 1328 free_arg(arg);
@@ -1311,6 +1353,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
1311 1353
1312out_free: 1354out_free:
1313 free_token(*tok); 1355 free_token(*tok);
1356 *tok = NULL;
1314 free_arg(arg); 1357 free_arg(arg);
1315 return EVENT_ERROR; 1358 return EVENT_ERROR;
1316} 1359}
@@ -1393,7 +1436,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1393 /* handle single op */ 1436 /* handle single op */
1394 if (token[1]) { 1437 if (token[1]) {
1395 die("bad op token %s", token); 1438 die("bad op token %s", token);
1396 return EVENT_ERROR; 1439 goto out_free;
1397 } 1440 }
1398 switch (token[0]) { 1441 switch (token[0]) {
1399 case '!': 1442 case '!':
@@ -1402,7 +1445,8 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1402 break; 1445 break;
1403 default: 1446 default:
1404 warning("bad op token %s", token); 1447 warning("bad op token %s", token);
1405 return EVENT_ERROR; 1448 goto out_free;
1449
1406 } 1450 }
1407 1451
1408 /* make an empty left */ 1452 /* make an empty left */
@@ -1413,6 +1457,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1413 right = alloc_arg(); 1457 right = alloc_arg();
1414 arg->op.right = right; 1458 arg->op.right = right;
1415 1459
1460 free_token(token);
1416 type = process_arg(event, right, tok); 1461 type = process_arg(event, right, tok);
1417 1462
1418 } else if (strcmp(token, "?") == 0) { 1463 } else if (strcmp(token, "?") == 0) {
@@ -1455,8 +1500,6 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1455 1500
1456 set_op_prio(arg); 1501 set_op_prio(arg);
1457 1502
1458 right = alloc_arg();
1459
1460 type = read_token_item(&token); 1503 type = read_token_item(&token);
1461 *tok = token; 1504 *tok = token;
1462 1505
@@ -1468,14 +1511,15 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1468 left->atom.atom = realloc(left->atom.atom, 1511 left->atom.atom = realloc(left->atom.atom,
1469 strlen(left->atom.atom) + 3); 1512 strlen(left->atom.atom) + 3);
1470 strcat(left->atom.atom, " *"); 1513 strcat(left->atom.atom, " *");
1514 free(arg->op.op);
1471 *arg = *left; 1515 *arg = *left;
1472 free(left); 1516 free(left);
1473 1517
1474 return type; 1518 return type;
1475 } 1519 }
1476 1520
1521 right = alloc_arg();
1477 type = process_arg_token(event, right, tok, type); 1522 type = process_arg_token(event, right, tok, type);
1478
1479 arg->op.right = right; 1523 arg->op.right = right;
1480 1524
1481 } else if (strcmp(token, "[") == 0) { 1525 } else if (strcmp(token, "[") == 0) {
@@ -1488,13 +1532,14 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1488 arg->op.left = left; 1532 arg->op.left = left;
1489 1533
1490 arg->op.prio = 0; 1534 arg->op.prio = 0;
1535
1491 type = process_array(event, arg, tok); 1536 type = process_array(event, arg, tok);
1492 1537
1493 } else { 1538 } else {
1494 warning("unknown op '%s'", token); 1539 warning("unknown op '%s'", token);
1495 event->flags |= EVENT_FL_FAILED; 1540 event->flags |= EVENT_FL_FAILED;
1496 /* the arg is now the left side */ 1541 /* the arg is now the left side */
1497 return EVENT_NONE; 1542 goto out_free;
1498 } 1543 }
1499 1544
1500 if (type == EVENT_OP) { 1545 if (type == EVENT_OP) {
@@ -1510,6 +1555,11 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1510 } 1555 }
1511 1556
1512 return type; 1557 return type;
1558
1559 out_free:
1560 free_token(token);
1561 *tok = NULL;
1562 return EVENT_ERROR;
1513} 1563}
1514 1564
1515static enum event_type 1565static enum event_type
@@ -1521,10 +1571,10 @@ process_entry(struct event_format *event __unused, struct print_arg *arg,
1521 char *token; 1571 char *token;
1522 1572
1523 if (read_expected(EVENT_OP, "->") < 0) 1573 if (read_expected(EVENT_OP, "->") < 0)
1524 return EVENT_ERROR; 1574 goto out_err;
1525 1575
1526 if (read_expect_type(EVENT_ITEM, &token) < 0) 1576 if (read_expect_type(EVENT_ITEM, &token) < 0)
1527 goto fail; 1577 goto out_free;
1528 field = token; 1578 field = token;
1529 1579
1530 arg->type = PRINT_FIELD; 1580 arg->type = PRINT_FIELD;
@@ -1535,8 +1585,10 @@ process_entry(struct event_format *event __unused, struct print_arg *arg,
1535 1585
1536 return type; 1586 return type;
1537 1587
1538fail: 1588 out_free:
1539 free_token(token); 1589 free_token(token);
1590 out_err:
1591 *tok = NULL;
1540 return EVENT_ERROR; 1592 return EVENT_ERROR;
1541} 1593}
1542 1594
@@ -1783,7 +1835,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
1783 enum event_type type; 1835 enum event_type type;
1784 struct print_arg *arg = NULL; 1836 struct print_arg *arg = NULL;
1785 struct print_flag_sym *field; 1837 struct print_flag_sym *field;
1786 char *token = NULL; 1838 char *token = *tok;
1787 char *value; 1839 char *value;
1788 1840
1789 do { 1841 do {
@@ -1805,6 +1857,9 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
1805 value = arg_eval(arg); 1857 value = arg_eval(arg);
1806 field->value = strdup(value); 1858 field->value = strdup(value);
1807 1859
1860 free_arg(arg);
1861 arg = alloc_arg();
1862
1808 free_token(token); 1863 free_token(token);
1809 type = process_arg(event, arg, &token); 1864 type = process_arg(event, arg, &token);
1810 if (test_type_token(type, token, EVENT_OP, "}")) 1865 if (test_type_token(type, token, EVENT_OP, "}"))
@@ -1828,6 +1883,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
1828out_free: 1883out_free:
1829 free_arg(arg); 1884 free_arg(arg);
1830 free_token(token); 1885 free_token(token);
1886 *tok = NULL;
1831 1887
1832 return EVENT_ERROR; 1888 return EVENT_ERROR;
1833} 1889}
@@ -1843,13 +1899,14 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
1843 arg->type = PRINT_FLAGS; 1899 arg->type = PRINT_FLAGS;
1844 1900
1845 if (read_expected_item(EVENT_DELIM, "(") < 0) 1901 if (read_expected_item(EVENT_DELIM, "(") < 0)
1846 return EVENT_ERROR; 1902 goto out_err;
1847 1903
1848 field = alloc_arg(); 1904 field = alloc_arg();
1849 1905
1850 type = process_arg(event, field, &token); 1906 type = process_arg(event, field, &token);
1851 if (test_type_token(type, token, EVENT_DELIM, ",")) 1907 if (test_type_token(type, token, EVENT_DELIM, ","))
1852 goto out_free; 1908 goto out_free;
1909 free_token(token);
1853 1910
1854 arg->flags.field = field; 1911 arg->flags.field = field;
1855 1912
@@ -1870,8 +1927,10 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
1870 type = read_token_item(tok); 1927 type = read_token_item(tok);
1871 return type; 1928 return type;
1872 1929
1873out_free: 1930 out_free:
1874 free_token(token); 1931 free_token(token);
1932 out_err:
1933 *tok = NULL;
1875 return EVENT_ERROR; 1934 return EVENT_ERROR;
1876} 1935}
1877 1936
@@ -1886,7 +1945,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
1886 arg->type = PRINT_SYMBOL; 1945 arg->type = PRINT_SYMBOL;
1887 1946
1888 if (read_expected_item(EVENT_DELIM, "(") < 0) 1947 if (read_expected_item(EVENT_DELIM, "(") < 0)
1889 return EVENT_ERROR; 1948 goto out_err;
1890 1949
1891 field = alloc_arg(); 1950 field = alloc_arg();
1892 1951
@@ -1904,8 +1963,10 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
1904 type = read_token_item(tok); 1963 type = read_token_item(tok);
1905 return type; 1964 return type;
1906 1965
1907out_free: 1966 out_free:
1908 free_token(token); 1967 free_token(token);
1968 out_err:
1969 *tok = NULL;
1909 return EVENT_ERROR; 1970 return EVENT_ERROR;
1910} 1971}
1911 1972
@@ -1920,7 +1981,7 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
1920 arg->type = PRINT_DYNAMIC_ARRAY; 1981 arg->type = PRINT_DYNAMIC_ARRAY;
1921 1982
1922 if (read_expected_item(EVENT_DELIM, "(") < 0) 1983 if (read_expected_item(EVENT_DELIM, "(") < 0)
1923 return EVENT_ERROR; 1984 goto out_err;
1924 1985
1925 /* 1986 /*
1926 * The item within the parenthesis is another field that holds 1987 * The item within the parenthesis is another field that holds
@@ -1929,19 +1990,19 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
1929 type = read_token(&token); 1990 type = read_token(&token);
1930 *tok = token; 1991 *tok = token;
1931 if (type != EVENT_ITEM) 1992 if (type != EVENT_ITEM)
1932 return EVENT_ERROR; 1993 goto out_free;
1933 1994
1934 /* Find the field */ 1995 /* Find the field */
1935 1996
1936 field = pevent_find_field(event, token); 1997 field = pevent_find_field(event, token);
1937 if (!field) 1998 if (!field)
1938 return EVENT_ERROR; 1999 goto out_free;
1939 2000
1940 arg->dynarray.field = field; 2001 arg->dynarray.field = field;
1941 arg->dynarray.index = 0; 2002 arg->dynarray.index = 0;
1942 2003
1943 if (read_expected(EVENT_DELIM, ")") < 0) 2004 if (read_expected(EVENT_DELIM, ")") < 0)
1944 return EVENT_ERROR; 2005 goto out_free;
1945 2006
1946 type = read_token_item(&token); 2007 type = read_token_item(&token);
1947 *tok = token; 2008 *tok = token;
@@ -1961,8 +2022,11 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
1961 type = read_token_item(tok); 2022 type = read_token_item(tok);
1962 return type; 2023 return type;
1963 2024
1964out_free: 2025 out_free:
1965 free(arg); 2026 free(arg);
2027 free_token(token);
2028 out_err:
2029 *tok = NULL;
1966 return EVENT_ERROR; 2030 return EVENT_ERROR;
1967} 2031}
1968 2032
@@ -1976,18 +2040,16 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
1976 type = process_arg(event, arg, &token); 2040 type = process_arg(event, arg, &token);
1977 2041
1978 if (type == EVENT_ERROR) 2042 if (type == EVENT_ERROR)
1979 return EVENT_ERROR; 2043 goto out_free;
1980 2044
1981 if (type == EVENT_OP) 2045 if (type == EVENT_OP)
1982 type = process_op(event, arg, &token); 2046 type = process_op(event, arg, &token);
1983 2047
1984 if (type == EVENT_ERROR) 2048 if (type == EVENT_ERROR)
1985 return EVENT_ERROR; 2049 goto out_free;
1986 2050
1987 if (test_type_token(type, token, EVENT_DELIM, ")")) { 2051 if (test_type_token(type, token, EVENT_DELIM, ")"))
1988 free_token(token); 2052 goto out_free;
1989 return EVENT_ERROR;
1990 }
1991 2053
1992 free_token(token); 2054 free_token(token);
1993 type = read_token_item(&token); 2055 type = read_token_item(&token);
@@ -2016,6 +2078,11 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
2016 2078
2017 *tok = token; 2079 *tok = token;
2018 return type; 2080 return type;
2081
2082 out_free:
2083 free_token(token);
2084 *tok = NULL;
2085 return EVENT_ERROR;
2019} 2086}
2020 2087
2021 2088
@@ -2026,24 +2093,27 @@ process_str(struct event_format *event __unused, struct print_arg *arg, char **t
2026 char *token; 2093 char *token;
2027 2094
2028 if (read_expected(EVENT_DELIM, "(") < 0) 2095 if (read_expected(EVENT_DELIM, "(") < 0)
2029 return EVENT_ERROR; 2096 goto out_err;
2030 2097
2031 if (read_expect_type(EVENT_ITEM, &token) < 0) 2098 if (read_expect_type(EVENT_ITEM, &token) < 0)
2032 goto fail; 2099 goto out_free;
2033 2100
2034 arg->type = PRINT_STRING; 2101 arg->type = PRINT_STRING;
2035 arg->string.string = token; 2102 arg->string.string = token;
2036 arg->string.offset = -1; 2103 arg->string.offset = -1;
2037 2104
2038 if (read_expected(EVENT_DELIM, ")") < 0) 2105 if (read_expected(EVENT_DELIM, ")") < 0)
2039 return EVENT_ERROR; 2106 goto out_err;
2040 2107
2041 type = read_token(&token); 2108 type = read_token(&token);
2042 *tok = token; 2109 *tok = token;
2043 2110
2044 return type; 2111 return type;
2045fail: 2112
2113 out_free:
2046 free_token(token); 2114 free_token(token);
2115 out_err:
2116 *tok = NULL;
2047 return EVENT_ERROR; 2117 return EVENT_ERROR;
2048} 2118}
2049 2119
@@ -2111,9 +2181,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
2111 arg->op.op = token; 2181 arg->op.op = token;
2112 arg->op.left = NULL; 2182 arg->op.left = NULL;
2113 type = process_op(event, arg, &token); 2183 type = process_op(event, arg, &token);
2114 if (type == EVENT_ERROR) 2184 /* return error type if errored */
2115 return type;
2116
2117 break; 2185 break;
2118 2186
2119 case EVENT_ERROR ... EVENT_NEWLINE: 2187 case EVENT_ERROR ... EVENT_NEWLINE:
@@ -2134,7 +2202,6 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
2134 2202
2135 do { 2203 do {
2136 if (type == EVENT_NEWLINE) { 2204 if (type == EVENT_NEWLINE) {
2137 free_token(token);
2138 type = read_token_item(&token); 2205 type = read_token_item(&token);
2139 continue; 2206 continue;
2140 } 2207 }
@@ -2144,6 +2211,7 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
2144 type = process_arg(event, arg, &token); 2211 type = process_arg(event, arg, &token);
2145 2212
2146 if (type == EVENT_ERROR) { 2213 if (type == EVENT_ERROR) {
2214 free_token(token);
2147 free_arg(arg); 2215 free_arg(arg);
2148 return -1; 2216 return -1;
2149 } 2217 }
@@ -2153,6 +2221,7 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
2153 2221
2154 if (type == EVENT_OP) { 2222 if (type == EVENT_OP) {
2155 type = process_op(event, arg, &token); 2223 type = process_op(event, arg, &token);
2224 free_token(token);
2156 list = &arg->next; 2225 list = &arg->next;
2157 continue; 2226 continue;
2158 } 2227 }
@@ -2166,7 +2235,7 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
2166 break; 2235 break;
2167 } while (type != EVENT_NONE); 2236 } while (type != EVENT_NONE);
2168 2237
2169 if (type != EVENT_NONE) 2238 if (type != EVENT_NONE && type != EVENT_ERROR)
2170 free_token(token); 2239 free_token(token);
2171 2240
2172 return args; 2241 return args;
@@ -2878,11 +2947,7 @@ static void free_args(struct print_arg *args)
2878 while (args) { 2947 while (args) {
2879 next = args->next; 2948 next = args->next;
2880 2949
2881 if (args->type == PRINT_ATOM) 2950 free_arg(args);
2882 free(args->atom.atom);
2883 else
2884 free(args->string.string);
2885 free(args);
2886 args = next; 2951 args = next;
2887 } 2952 }
2888} 2953}
@@ -3757,13 +3822,52 @@ static void free_event(struct event_format *event)
3757void pevent_free(struct pevent *pevent) 3822void pevent_free(struct pevent *pevent)
3758{ 3823{
3759 struct event_format *event, *next_event; 3824 struct event_format *event, *next_event;
3825 struct cmdline_list *cmdlist = pevent->cmdlist, *cmdnext;
3826 struct func_list *funclist = pevent->funclist, *funcnext;
3827 struct printk_list *printklist = pevent->printklist, *printknext;
3828 int i;
3829
3830 if (pevent->cmdlines) {
3831 for (i = 0; i < pevent->cmdline_count; i++)
3832 free(pevent->cmdlines[i].comm);
3833 free(pevent->cmdlines);
3834 }
3835
3836 while (cmdlist) {
3837 cmdnext = cmdlist->next;
3838 free(cmdlist->comm);
3839 free(cmdlist);
3840 cmdlist = cmdnext;
3841 }
3842
3843 if (pevent->func_map) {
3844 for (i = 0; i < pevent->func_count; i++) {
3845 free(pevent->func_map[i].func);
3846 free(pevent->func_map[i].mod);
3847 }
3848 free(pevent->func_map);
3849 }
3850
3851 while (funclist) {
3852 funcnext = funclist->next;
3853 free(funclist->func);
3854 free(funclist->mod);
3855 free(funclist);
3856 funclist = funcnext;
3857 }
3858
3859 if (pevent->printk_map) {
3860 for (i = 0; i < pevent->printk_count; i++)
3861 free(pevent->printk_map[i].printk);
3862 free(pevent->printk_map);
3863 }
3760 3864
3761 free(pevent->cmdlines); 3865 while (printklist) {
3762 free(pevent->cmdlist); 3866 printknext = printklist->next;
3763 free(pevent->func_map); 3867 free(printklist->printk);
3764 free(pevent->funclist); 3868 free(printklist);
3765 free(pevent->printk_map); 3869 printklist = printknext;
3766 free(pevent->printklist); 3870 }
3767 3871
3768 free(pevent->events); 3872 free(pevent->events);
3769 3873
diff --git a/trace-read.c b/trace-read.c
index b17c271..175d0d3 100644
--- a/trace-read.c
+++ b/trace-read.c
@@ -412,5 +412,7 @@ void trace_report (int argc, char **argv)
412 412
413 read_data_info(handle); 413 read_data_info(handle);
414 414
415 pevent_free(pevent);
416
415 return; 417 return;
416} 418}