39 static const char *input_buf;
40 static unsigned long long input_buf_ptr;
41 static unsigned long long input_buf_siz;
43 static int is_flag_field;
44 static int is_symbolic_field;
46 static int show_warning = 1;
48 #define do_warning(fmt, ...) \
51 warning(fmt, ##__VA_ARGS__); \
54 static void init_input_buf(
const char *
buf,
unsigned long long size)
94 static unsigned long long
110 init_input_buf(buf, size);
121 return calloc(1,
sizeof(
struct print_arg));
129 static int cmdline_cmp(
const void *
a,
const void *
b)
161 cmdlines[
i].
pid = cmdlist->
pid;
165 cmdlist = cmdlist->
next;
169 qsort(cmdlines, pevent->
cmdline_count,
sizeof(*cmdlines), cmdline_cmp);
186 return "<not enough memory for cmdlines!>";
191 sizeof(*pevent->
cmdlines), cmdline_cmp);
220 sizeof(*pevent->
cmdlines), cmdline_cmp);
232 static int add_new_comm(
struct pevent *pevent,
const char *comm,
int pid)
245 sizeof(*pevent->
cmdlines), cmdline_cmp);
251 cmdlines = realloc(cmdlines,
sizeof(*cmdlines) * (pevent->
cmdline_count + 1));
269 qsort(cmdlines, pevent->
cmdline_count,
sizeof(*cmdlines), cmdline_cmp);
289 return add_new_comm(pevent, comm, pid);
291 item =
malloc(
sizeof(*item));
295 item->
comm = strdup(comm);
322 static int func_cmp(
const void *
a,
const void *
b)
339 static int func_bcmp(
const void *
a,
const void *
b)
347 fa->
addr < (fb+1)->addr))
356 static int func_map_init(
struct pevent *pevent)
373 func_map[
i].
mod = funclist->
mod;
376 funclist = funclist->
next;
380 qsort(func_map, pevent->
func_count,
sizeof(*func_map), func_cmp);
395 static struct func_map *
396 find_func(
struct pevent *pevent,
unsigned long long addr)
398 struct func_map *
func;
402 func_map_init(pevent);
407 sizeof(*pevent->
func_map), func_bcmp);
423 struct func_map *
map;
425 map = find_func(pevent, addr);
444 struct func_map *
map;
446 map = find_func(pevent, addr);
464 unsigned long long addr,
char *
mod)
472 item->
func = strdup(func);
477 item->
mod = strdup(mod);
509 func_map_init(pevent);
533 static int printk_cmp(
const void *a,
const void *b)
546 static int printk_map_init(
struct pevent *pevent)
565 printklist = printklist->
next;
569 qsort(printk_map, pevent->
printk_count,
sizeof(*printk_map), printk_cmp);
577 static struct printk_map *
578 find_printk(
struct pevent *pevent,
unsigned long long addr)
580 struct printk_map *
printk;
581 struct printk_map
key;
583 if (!pevent->
printk_map && printk_map_init(pevent))
604 unsigned long long addr)
614 item->
printk = strdup(fmt);
640 printk_map_init(pevent);
664 for (i = 0; i < pevent->
nr_events; i++) {
665 if (pevent->
events[i]->id > event->
id)
668 if (i < pevent->nr_events)
671 sizeof(event) * (pevent->
nr_events - i));
720 free_arg(arg->
flags.field);
722 free_flag_sym(arg->
flags.flags);
725 free_arg(arg->
symbol.field);
726 free_flag_sym(arg->
symbol.symbols);
729 free_arg(arg->
hex.field);
730 free_arg(arg->
hex.size);
745 free_arg(arg->
op.left);
746 free_arg(arg->
op.right);
749 while (arg->
func.args) {
750 farg = arg->
func.args;
778 if (ch ==
'(' || ch ==
')' || ch ==
',')
784 static int __read_char(
void)
786 if (input_buf_ptr >= input_buf_siz)
789 return input_buf[input_buf_ptr++];
792 static int __peek_char(
void)
794 if (input_buf_ptr >= input_buf_siz)
797 return input_buf[input_buf_ptr];
807 return __peek_char();
810 static int extend_token(
char **tok,
char *
buf,
int size)
812 char *newtok = realloc(*tok, size);
829 static enum event_type force_token(
const char *
str,
char **tok);
831 static enum event_type __read_token(
char **tok)
834 int ch, last_ch, quote_ch, next_ch;
855 if (asprintf(tok,
"%c", ch) < 0)
863 next_ch = __peek_char();
864 if (next_ch ==
'>') {
865 buf[i++] = __read_char();
878 buf[i++] = __read_char();
900 buf[i++] = __read_char();
911 if (i == (BUFSIZ - 1)) {
915 if (extend_token(tok, buf, tok_size) < 0)
923 if (ch ==
'\\' && last_ch ==
'\\')
925 }
while (ch != quote_ch || last_ch ==
'\\');
934 unsigned long long save_input_buf_ptr = input_buf_ptr;
941 input_buf_ptr = save_input_buf_ptr;
952 while (get_type(__peek_char()) == type) {
953 if (i == (BUFSIZ - 1)) {
957 if (extend_token(tok, buf, tok_size) < 0)
967 if (extend_token(tok, buf, tok_size + i + 1) < 0)
979 if (
strcmp(*tok,
"LOCAL_PR_FMT") == 0) {
982 return force_token(
"\"\%s\" ", tok);
983 }
else if (
strcmp(*tok,
"STA_PR_FMT") == 0) {
986 return force_token(
"\" sta:%pM\" ", tok);
987 }
else if (
strcmp(*tok,
"VIF_PR_FMT") == 0) {
990 return force_token(
"\" vif:%p(%d)\" ", tok);
997 static enum event_type force_token(
const char *
str,
char **tok)
999 const char *save_input_buf;
1000 unsigned long long save_input_buf_ptr;
1001 unsigned long long save_input_buf_siz;
1005 save_input_buf = input_buf;
1006 save_input_buf_ptr = input_buf_ptr;
1007 save_input_buf_siz = input_buf_siz;
1009 init_input_buf(str,
strlen(str));
1011 type = __read_token(tok);
1014 input_buf = save_input_buf;
1015 input_buf_ptr = save_input_buf_ptr;
1016 input_buf_siz = save_input_buf_siz;
1021 static void free_token(
char *tok)
1027 static enum event_type read_token(
char **tok)
1032 type = __read_token(tok);
1055 return read_token(tok);
1068 static enum event_type read_token_item(
char **tok)
1073 type = __read_token(tok);
1087 if (type != expect) {
1088 do_warning(
"Error: expected type %d but read %d",
1096 enum event_type expect,
const char *expect_tok)
1098 if (type != expect) {
1099 do_warning(
"Error: expected type %d but read %d",
1104 if (
strcmp(token, expect_tok) != 0) {
1105 do_warning(
"Error: expected '%s' but read '%s'",
1112 static int __read_expect_type(
enum event_type expect,
char **tok,
int newline_ok)
1117 type = read_token(tok);
1119 type = read_token_item(tok);
1120 return test_type(type, expect);
1123 static int read_expect_type(
enum event_type expect,
char **tok)
1125 return __read_expect_type(expect, tok, 1);
1128 static int __read_expected(
enum event_type expect,
const char *str,
1136 type = read_token(&token);
1138 type = read_token_item(&token);
1140 ret = test_type_token(type, token, expect, str);
1147 static int read_expected(
enum event_type expect,
const char *str)
1149 return __read_expected(expect, str, 1);
1152 static int read_expected_item(
enum event_type expect,
const char *str)
1154 return __read_expected(expect, str, 0);
1157 static char *event_read_name(
void)
1164 if (read_expected(
EVENT_OP,
":") < 0)
1167 if (read_expect_type(
EVENT_ITEM, &token) < 0)
1177 static int event_read_id(
void)
1182 if (read_expected_item(
EVENT_ITEM,
"ID") < 0)
1185 if (read_expected(
EVENT_OP,
":") < 0)
1188 if (read_expect_type(
EVENT_ITEM, &token) < 0)
1191 id = strtoul(token,
NULL, 0);
1210 static int field_is_dynamic(
struct format_field *field)
1236 type = read_token(&token);
1244 if (test_type_token(type, token,
EVENT_ITEM,
"field"))
1248 type = read_token(&token);
1256 type = read_token(&token);
1259 if (test_type_token(type, token,
EVENT_OP,
":") < 0)
1263 if (read_expect_type(
EVENT_ITEM, &token) < 0)
1268 field = calloc(1,
sizeof(*field));
1276 type = read_token(&token);
1286 if (
strcmp(token,
"*") == 0)
1291 new_type = realloc(field->
type,
1298 field->
type = new_type;
1303 field->
type = last_token;
1315 field->
name = last_token;
1320 if (
strcmp(token,
"[") == 0) {
1322 char *brackets =
token;
1328 type = read_token(&token);
1335 while (
strcmp(token,
"]") != 0) {
1343 new_brackets = realloc(brackets,
1346 if (!new_brackets) {
1350 brackets = new_brackets;
1357 type = read_token(&token);
1366 new_brackets = realloc(brackets,
strlen(brackets) + 2);
1367 if (!new_brackets) {
1371 brackets = new_brackets;
1376 type = read_token(&token);
1383 new_type = realloc(field->
type,
1391 field->
type = new_type;
1394 free_token(field->
name);
1397 type = read_token(&token);
1400 new_type = realloc(field->
type,
1407 field->
type = new_type;
1413 if (field_is_string(field))
1415 if (field_is_dynamic(field))
1417 if (field_is_long(field))
1420 if (test_type_token(type, token,
EVENT_OP,
";"))
1427 if (read_expected(
EVENT_OP,
":") < 0)
1435 if (read_expected(
EVENT_OP,
";") < 0)
1441 if (read_expected(
EVENT_OP,
":") < 0)
1446 field->
size = strtoul(token,
NULL, 0);
1449 if (read_expected(
EVENT_OP,
";") < 0)
1452 type = read_token(&token);
1455 if (test_type_token(type, token,
EVENT_ITEM,
"signed"))
1460 if (read_expected(
EVENT_OP,
":") < 0)
1469 if (read_expected(
EVENT_OP,
";") < 0)
1489 fields = &field->
next;
1506 static int event_read_format(
struct event_format *event)
1511 if (read_expected_item(
EVENT_ITEM,
"format") < 0)
1514 if (read_expected(
EVENT_OP,
":") < 0)
1521 ret = event_read_fields(event, &event->
format.common_fields);
1524 event->format.nr_common =
ret;
1526 ret = event_read_fields(event, &event->
format.fields);
1529 event->format.nr_fields =
ret;
1548 type = read_token(&token);
1551 return process_arg_token(event, arg, tok, type);
1568 if (!arg || !left || !right) {
1569 do_warning(
"%s: not enough memory!", __func__);
1581 type = process_arg(event, left, &token);
1586 type = process_op(event, left, &token);
1590 if (test_type_token(type, token,
EVENT_OP,
":"))
1595 type = process_arg(event, right, &token);
1597 top->
op.right =
arg;
1619 do_warning(
"%s: not enough memory!", __func__);
1626 type = process_arg(event, arg, &token);
1627 if (test_type_token(type, token,
EVENT_OP,
"]"))
1630 top->
op.right =
arg;
1633 type = read_token_item(&token);
1644 static int get_op_prio(
char *
op)
1676 if (
strcmp(op,
"++") == 0 ||
1679 }
else if (
strcmp(op,
">>") == 0 ||
1682 }
else if (
strcmp(op,
">=") == 0 ||
1685 }
else if (
strcmp(op,
"==") == 0 ||
1688 }
else if (
strcmp(op,
"&&") == 0) {
1690 }
else if (
strcmp(op,
"||") == 0) {
1699 static int set_op_prio(
struct print_arg *arg)
1706 arg->
op.prio = get_op_prio(arg->
op.op);
1708 return arg->
op.prio;
1756 type = process_arg(event, right, tok);
1758 }
else if (
strcmp(token,
"?") == 0) {
1773 type = process_cond(event, arg, tok);
1775 }
else if (
strcmp(token,
">>") == 0 ||
1776 strcmp(token,
"<<") == 0 ||
1777 strcmp(token,
"&") == 0 ||
1778 strcmp(token,
"|") == 0 ||
1779 strcmp(token,
"&&") == 0 ||
1780 strcmp(token,
"||") == 0 ||
1781 strcmp(token,
"-") == 0 ||
1782 strcmp(token,
"+") == 0 ||
1783 strcmp(token,
"*") == 0 ||
1784 strcmp(token,
"^") == 0 ||
1785 strcmp(token,
"/") == 0 ||
1786 strcmp(token,
"<") == 0 ||
1787 strcmp(token,
">") == 0 ||
1788 strcmp(token,
"==") == 0 ||
1789 strcmp(token,
"!=") == 0) {
1803 if (set_op_prio(arg) == -1) {
1810 type = read_token_item(&token);
1814 if ((
strcmp(arg->
op.op,
"*") == 0) &&
1822 new_atom = realloc(left->
atom.atom,
1827 left->
atom.atom = new_atom;
1840 type = process_arg_token(event, right, tok, type);
1843 }
else if (
strcmp(token,
"[") == 0) {
1858 type = process_array(event, arg, tok);
1871 prio = get_op_prio(*tok);
1873 if (prio > arg->
op.prio)
1874 return process_op(event, arg, tok);
1876 return process_op(event, right, tok);
1882 do_warning(
"%s: not enough memory!", __func__);
1897 if (read_expected(
EVENT_OP,
"->") < 0)
1900 if (read_expect_type(
EVENT_ITEM, &token) < 0)
1907 if (is_flag_field) {
1911 }
else if (is_symbolic_field) {
1914 is_symbolic_field = 0;
1917 type = read_token(&token);
1929 static char *arg_eval (
struct print_arg *arg);
1931 static unsigned long long
1932 eval_type_str(
unsigned long long val,
const char *type,
int pointer)
1942 if (type[len-1] !=
'*') {
1943 do_warning(
"pointer expected with non pointer type");
1949 do_warning(
"%s: not enough memory!", __func__);
1957 val = eval_type_str(val, ref, 0);
1963 if (type[len - 1] ==
'*')
1967 if (
strncmp(type,
"struct", 6) == 0)
1971 if (
strcmp(type,
"u8") == 0)
1974 if (
strcmp(type,
"u16") == 0)
1975 return val & 0xffff;
1977 if (
strcmp(type,
"u32") == 0)
1978 return val & 0xffffffff;
1980 if (
strcmp(type,
"u64") == 0 ||
1984 if (
strcmp(type,
"s8") == 0)
1985 return (
unsigned long long)(
char)val & 0xff;
1987 if (
strcmp(type,
"s16") == 0)
1988 return (
unsigned long long)(
short)val & 0xffff;
1990 if (
strcmp(type,
"s32") == 0)
1991 return (
unsigned long long)(
int)val & 0xffffffff;
1993 if (
strncmp(type,
"unsigned ", 9) == 0) {
1998 if (
strcmp(type,
"char") == 0) {
2000 return (
unsigned long long)(
char)val & 0xff;
2005 if (
strcmp(type,
"short") == 0) {
2007 return (
unsigned long long)(
short)val & 0xffff;
2009 return val & 0xffff;
2012 if (
strcmp(type,
"int") == 0) {
2014 return (
unsigned long long)(
int)val & 0xffffffff;
2016 return val & 0xffffffff;
2025 static unsigned long long
2026 eval_type(
unsigned long long val,
struct print_arg *arg,
int pointer)
2033 return eval_type_str(val, arg->
typecast.type, pointer);
2036 static int arg_num_eval(
struct print_arg *arg,
long long *val)
2041 switch (arg->
type) {
2043 *val = strtoll(arg->
atom.atom,
NULL, 0);
2046 ret = arg_num_eval(arg->
typecast.item, val);
2049 *val = eval_type(*val, arg, 0);
2052 switch (arg->
op.op[0]) {
2054 ret = arg_num_eval(arg->
op.left, &left);
2057 ret = arg_num_eval(arg->
op.right, &right);
2061 *val = left ||
right;
2063 *val = left |
right;
2066 ret = arg_num_eval(arg->
op.left, &left);
2069 ret = arg_num_eval(arg->
op.right, &right);
2073 *val = left &&
right;
2075 *val = left &
right;
2078 ret = arg_num_eval(arg->
op.left, &left);
2081 ret = arg_num_eval(arg->
op.right, &right);
2084 switch (arg->
op.op[1]) {
2086 *val = left <
right;
2089 *val = left <<
right;
2092 *val = left <=
right;
2100 ret = arg_num_eval(arg->
op.left, &left);
2103 ret = arg_num_eval(arg->
op.right, &right);
2106 switch (arg->
op.op[1]) {
2108 *val = left >
right;
2111 *val = left >>
right;
2114 *val = left >=
right;
2122 ret = arg_num_eval(arg->
op.left, &left);
2125 ret = arg_num_eval(arg->
op.right, &right);
2129 if (arg->
op.op[1] !=
'=') {
2133 *val = left ==
right;
2136 ret = arg_num_eval(arg->
op.left, &left);
2139 ret = arg_num_eval(arg->
op.right, &right);
2143 switch (arg->
op.op[1]) {
2145 *val = left !=
right;
2157 ret = arg_num_eval(arg->
op.left, &left);
2160 ret = arg_num_eval(arg->
op.right, &right);
2163 *val = left -
right;
2169 ret = arg_num_eval(arg->
op.left, &left);
2172 ret = arg_num_eval(arg->
op.right, &right);
2175 *val = left +
right;
2195 static char *arg_eval (
struct print_arg *arg)
2198 static char buf[20];
2200 switch (arg->
type) {
2202 return arg->
atom.atom;
2204 return arg_eval(arg->
typecast.item);
2206 if (!arg_num_eval(arg, &val))
2234 type = read_token_item(&token);
2235 if (test_type_token(type, token,
EVENT_OP,
"{"))
2243 type = process_arg(event, arg, &token);
2246 type = process_op(event, arg, &token);
2251 if (test_type_token(type, token,
EVENT_DELIM,
","))
2254 field = calloc(1,
sizeof(*field));
2258 value = arg_eval(arg);
2260 goto out_free_field;
2261 field->
value = strdup(value);
2263 goto out_free_field;
2271 type = process_arg(event, arg, &token);
2272 if (test_type_token(type, token,
EVENT_OP,
"}"))
2273 goto out_free_field;
2275 value = arg_eval(arg);
2277 goto out_free_field;
2278 field->
str = strdup(value);
2280 goto out_free_field;
2285 list = &field->
next;
2288 type = read_token_item(&token);
2295 free_flag_sym(field);
2311 memset(arg, 0,
sizeof(*arg));
2316 do_warning(
"%s: not enough memory!", __func__);
2320 type = process_arg(event, field, &token);
2324 type = process_op(event, field, &token);
2326 if (test_type_token(type, token,
EVENT_DELIM,
","))
2327 goto out_free_field;
2332 type = read_token_item(&token);
2333 if (event_item_type(type)) {
2335 type = read_token_item(&token);
2338 if (test_type_token(type, token,
EVENT_DELIM,
","))
2341 type = process_fields(event, &arg->
flags.flags, &token);
2342 if (test_type_token(type, token,
EVENT_DELIM,
")"))
2346 type = read_token_item(tok);
2364 memset(arg, 0,
sizeof(*arg));
2369 do_warning(
"%s: not enough memory!", __func__);
2373 type = process_arg(event, field, &token);
2374 if (test_type_token(type, token,
EVENT_DELIM,
","))
2375 goto out_free_field;
2379 type = process_fields(event, &arg->
symbol.symbols, &token);
2380 if (test_type_token(type, token,
EVENT_DELIM,
")"))
2384 type = read_token_item(tok);
2402 memset(arg, 0,
sizeof(*arg));
2407 do_warning(
"%s: not enough memory!", __func__);
2411 type = process_arg(event, field, &token);
2413 if (test_type_token(type, token,
EVENT_DELIM,
","))
2422 do_warning(
"%s: not enough memory!", __func__);
2427 type = process_arg(event, field, &token);
2429 if (test_type_token(type, token,
EVENT_DELIM,
")"))
2435 type = read_token_item(tok);
2452 memset(arg, 0,
sizeof(*arg));
2459 type = read_token(&token);
2477 type = read_token_item(&token);
2485 do_warning(
"%s: not enough memory!", __func__);
2490 type = process_arg(event, arg, &token);
2494 if (!test_type_token(type, token,
EVENT_OP,
"]"))
2498 type = read_token_item(tok);
2516 type = process_arg(event, arg, &token);
2522 type = process_op(event, arg, &token);
2527 if (test_type_token(type, token,
EVENT_DELIM,
")"))
2531 type = read_token_item(&token);
2537 if (event_item_type(type) ||
2544 do_warning(
"previous needed to be PRINT_ATOM");
2550 do_warning(
"%s: not enough memory!", __func__);
2557 type = process_arg_token(event, item_arg, &token, type);
2578 if (read_expect_type(
EVENT_ITEM, &token) < 0)
2588 type = read_token(&token);
2601 find_func_handler(
struct pevent *pevent,
char *func_name)
2616 static void remove_func_handler(
struct pevent *pevent,
char *func_name)
2622 while ((func = *next)) {
2625 free_func_handle(func);
2648 next_arg = &(arg->
func.args);
2649 for (i = 0; i < func->
nr_args; i++) {
2652 do_warning(
"%s: not enough memory!", __func__);
2656 type = process_arg(event, farg, &token);
2662 if (test_type_token(type, token,
EVENT_DELIM, test)) {
2669 next_arg = &(farg->
next);
2673 type = read_token(&token);
2681 char *token,
char **tok)
2685 if (
strcmp(token,
"__print_flags") == 0) {
2688 return process_flags(event, arg, tok);
2690 if (
strcmp(token,
"__print_symbolic") == 0) {
2692 is_symbolic_field = 1;
2693 return process_symbols(event, arg, tok);
2695 if (
strcmp(token,
"__print_hex") == 0) {
2697 return process_hex(event, arg, tok);
2699 if (
strcmp(token,
"__get_str") == 0) {
2701 return process_str(event, arg, tok);
2703 if (
strcmp(token,
"__get_dynamic_array") == 0) {
2705 return process_dynamic_array(event, arg, tok);
2708 func = find_func_handler(event->
pevent, token);
2711 return process_func_handler(event, func, arg, tok);
2714 do_warning(
"function %s not defined", token);
2730 if (
strcmp(token,
"REC") == 0) {
2732 type = process_entry(event, arg, &token);
2737 type = read_token_item(&token);
2747 type = process_function(event, arg, atom, &token);
2753 new_atom = realloc(atom,
2765 type = read_token_item(&token);
2769 arg->
atom.atom = atom;
2776 type = read_token_item(&token);
2779 if (
strcmp(token,
"(") == 0) {
2781 type = process_paren(event, arg, &token);
2789 type = process_op(event, arg, &token);
2817 type = read_token_item(&token);
2823 do_warning(
"%s: not enough memory!", __func__);
2827 type = process_arg(event, arg, &token);
2839 type = process_op(event, arg, &token);
2865 static int event_read_print(
struct event_format *event)
2871 if (read_expected_item(
EVENT_ITEM,
"print") < 0)
2877 if (read_expected(
EVENT_OP,
":") < 0)
2884 event->print_fmt.format =
token;
2885 event->print_fmt.args =
NULL;
2888 type = read_token_item(&token);
2897 if (asprintf(&cat,
"%s%s", event->
print_fmt.format, token) < 0)
2901 event->print_fmt.format =
NULL;
2906 if (test_type_token(type, token,
EVENT_DELIM,
","))
2911 ret = event_read_print_args(event, &event->
print_fmt.args);
2935 for (format = event->
format.common_fields;
2936 format; format = format->
next) {
2957 for (format = event->
format.fields;
2958 format; format = format->
next) {
2996 const void *
ptr,
int size)
3000 return *(
unsigned char *)ptr;
3025 unsigned long long *value)
3029 switch (field->
size) {
3042 static int get_common_info(
struct pevent *pevent,
3043 const char *type,
int *
offset,
int *size)
3057 event = pevent->
events[0];
3063 *size = field->
size;
3068 static int __parse_common(
struct pevent *pevent,
void *
data,
3069 int *size,
int *offset,
const char *
name)
3074 ret = get_common_info(pevent, name, offset, size);
3081 static int trace_parse_common_type(
struct pevent *pevent,
void *data)
3083 return __parse_common(pevent, data,
3088 static int parse_common_pid(
struct pevent *pevent,
void *data)
3090 return __parse_common(pevent, data,
3095 static int parse_common_pc(
struct pevent *pevent,
void *data)
3097 return __parse_common(pevent, data,
3099 "common_preempt_count");
3102 static int parse_common_flags(
struct pevent *pevent,
void *data)
3104 return __parse_common(pevent, data,
3109 static int parse_common_lock_depth(
struct pevent *pevent,
void *data)
3111 return __parse_common(pevent, data,
3113 "common_lock_depth");
3116 static int parse_common_migrate_disable(
struct pevent *pevent,
void *data)
3118 return __parse_common(pevent, data,
3120 "common_migrate_disable");
3123 static int events_id_cmp(
const void *a,
const void *b);
3145 sizeof(*pevent->
events), events_id_cmp);
3166 const char *
sys,
const char *name)
3176 for (i = 0; i < pevent->
nr_events; i++) {
3192 static unsigned long long
3195 struct pevent *pevent =
event->pevent;
3196 unsigned long long val = 0;
3201 unsigned int field_size;
3203 switch (arg->
type) {
3210 if (!arg->
field.field) {
3212 if (!arg->
field.field)
3213 goto out_warning_field;
3218 arg->
field.field->size);
3225 val = eval_num_arg(data, size, event, arg->
typecast.item);
3226 return eval_type(val, arg, 0);
3233 val = process_defined_func(&
s, data, size, event, arg);
3238 if (
strcmp(arg->
op.op,
"[") == 0) {
3243 right = eval_num_arg(data, size, event, arg->
op.right);
3246 larg = arg->
op.left;
3256 switch (larg->
type) {
3259 data + larg->
dynarray.field->offset,
3261 if (larg->
dynarray.field->elementsize)
3262 field_size = larg->
dynarray.field->elementsize;
3272 if (!larg->
field.field) {
3275 if (!larg->
field.field) {
3277 goto out_warning_field;
3280 field_size = larg->
field.field->elementsize;
3281 offset = larg->
field.field->offset +
3282 right * larg->
field.field->elementsize;
3288 data + offset, field_size);
3290 val = eval_type(val, typearg, 1);
3292 }
else if (
strcmp(arg->
op.op,
"?") == 0) {
3293 left = eval_num_arg(data, size, event, arg->
op.left);
3294 arg = arg->
op.right;
3296 val = eval_num_arg(data, size, event, arg->
op.left);
3298 val = eval_num_arg(data, size, event, arg->
op.right);
3302 left = eval_num_arg(data, size, event, arg->
op.left);
3303 right = eval_num_arg(data, size, event, arg->
op.right);
3304 switch (arg->
op.op[0]) {
3306 switch (arg->
op.op[1]) {
3311 val = left !=
right;
3314 goto out_warning_op;
3322 val = left ||
right;
3328 val = left &&
right;
3333 switch (arg->
op.op[1]) {
3338 val = left <<
right;
3341 val = left <=
right;
3344 goto out_warning_op;
3348 switch (arg->
op.op[1]) {
3353 val = left >>
right;
3356 val = left >=
right;
3359 goto out_warning_op;
3363 if (arg->
op.op[1] !=
'=')
3364 goto out_warning_op;
3366 val = left ==
right;
3381 goto out_warning_op;
3390 do_warning(
"%s: unknown op '%s'", __func__, arg->
op.op);
3404 {
"HI_SOFTIRQ", 0 },
3405 {
"TIMER_SOFTIRQ", 1 },
3406 {
"NET_TX_SOFTIRQ", 2 },
3407 {
"NET_RX_SOFTIRQ", 3 },
3408 {
"BLOCK_SOFTIRQ", 4 },
3409 {
"BLOCK_IOPOLL_SOFTIRQ", 5 },
3410 {
"TASKLET_SOFTIRQ", 6 },
3411 {
"SCHED_SOFTIRQ", 7 },
3412 {
"HRTIMER_SOFTIRQ", 8 },
3413 {
"RCU_SOFTIRQ", 9 },
3415 {
"HRTIMER_NORESTART", 0 },
3416 {
"HRTIMER_RESTART", 1 },
3419 static unsigned long long eval_flag(
const char *
flag)
3431 for (i = 0; i < (
int)(
sizeof(flags)/
sizeof(flags[0])); i++)
3432 if (
strcmp(flags[i].name, flag) == 0)
3433 return flags[i].value;
3439 int len_arg,
const char *str)
3447 static void print_str_arg(
struct trace_seq *s,
void *data,
int size,
3451 struct pevent *pevent =
event->pevent;
3454 unsigned long long val, fval;
3461 switch (arg->
type) {
3466 print_str_to_seq(s, format, len_arg, arg->
atom.atom);
3469 field = arg->
field.field;
3473 str = arg->
field.name;
3474 goto out_warning_field;
3488 addr = *(
unsigned long *)(data + field->
offset);
3494 do_warning(
"%s: not enough memory!", __func__);
3499 print_str_to_seq(s, format, len_arg, str);
3503 val = eval_num_arg(data, size, event, arg->
flags.field);
3505 for (flag = arg->
flags.flags; flag; flag = flag->
next) {
3506 fval = eval_flag(flag->
value);
3507 if (!val && !fval) {
3508 print_str_to_seq(s, format, len_arg, flag->
str);
3511 if (fval && (val & fval) == fval) {
3512 if (print && arg->
flags.delim)
3514 print_str_to_seq(s, format, len_arg, flag->
str);
3521 val = eval_num_arg(data, size, event, arg->
symbol.field);
3522 for (flag = arg->
symbol.symbols; flag; flag = flag->
next) {
3523 fval = eval_flag(flag->
value);
3525 print_str_to_seq(s, format, len_arg, flag->
str);
3531 field = arg->
hex.field->field.field;
3533 str = arg->
hex.field->field.name;
3536 goto out_warning_field;
3537 arg->
hex.field->field.field =
field;
3539 hex = data + field->
offset;
3540 len = eval_num_arg(data, size, event, arg->
hex.size);
3541 for (i = 0; i < len; i++) {
3553 if (arg->
string.offset == -1) {
3560 str_offset &= 0xffff;
3561 print_str_to_seq(s, format, len_arg, ((
char *)data) + str_offset);
3565 print_str_to_seq(s, format, len_arg, arg->
string.string);
3571 if (arg->
op.op[0] !=
'?')
3573 val = eval_num_arg(data, size, event, arg->
op.left);
3575 print_str_arg(s, data, size, event,
3576 format, len_arg, arg->
op.right->op.left);
3578 print_str_arg(s, data, size, event,
3579 format, len_arg, arg->
op.right->op.right);
3582 process_defined_func(s, data, size, event, arg);
3595 static unsigned long long
3596 process_defined_func(
struct trace_seq *s,
void *data,
int size,
3601 unsigned long long *args;
3602 unsigned long long ret;
3606 struct save_str *
next;
3612 ret = (*func_handle->
func)(s,
NULL);
3616 farg = arg->
func.args;
3617 param = func_handle->
params;
3624 for (i = 0; i < func_handle->
nr_args; i++) {
3625 switch (param->
type) {
3629 args[
i] = eval_num_arg(data, size, event, farg);
3633 print_str_arg(&str, data, size, event,
"%s", -1, farg);
3635 string =
malloc(
sizeof(*
string));
3637 do_warning(
"%s(%d): malloc str", __func__, __LINE__);
3640 string->next = strings;
3641 string->str = strdup(str.buffer);
3644 do_warning(
"%s(%d): malloc str", __func__, __LINE__);
3660 param = param->
next;
3663 ret = (*func_handle->
func)(s, args);
3668 strings =
string->next;
3678 static void free_args(
struct print_arg *args)
3692 struct pevent *pevent =
event->pevent;
3695 unsigned long long ip,
val;
3706 do_warning(
"can't find buffer field for binary printk");
3711 do_warning(
"can't find ip field for binary printk");
3725 do_warning(
"%s(%d): not enough memory!", __func__, __LINE__);
3734 if (asprintf(&arg->
atom.atom,
"%lld", ip) < 0)
3738 for (ptr = fmt + 6, bptr = data + field->
offset;
3739 bptr < data + size && *ptr; ptr++) {
3785 bptr = (
void *)(((
unsigned long)bptr + 3) &
3792 __func__, __LINE__);
3797 if (asprintf(&arg->
atom.atom,
"%lld", val) < 0) {
3815 __func__, __LINE__);
3820 arg->
string.string = strdup(bptr);
3823 bptr +=
strlen(bptr) + 1;
3840 get_bprint_format(
void *data,
int size __maybe_unused,
3843 struct pevent *pevent =
event->pevent;
3844 unsigned long long addr;
3846 struct printk_map *
printk;
3855 do_warning(
"can't find format field for binary printk");
3863 printk = find_printk(pevent, addr);
3865 if (asprintf(&format,
"%%pf : (NO FORMAT FOUND at %llx)\n", addr) < 0)
3874 if (asprintf(&format,
"%s : %s",
"%pf", p) < 0)
3877 p = format +
strlen(format) - 1;
3882 if (
strcmp(p,
"\\n") == 0)
3888 static void print_mac_arg(
struct trace_seq *s,
int mac,
void *data,
int size,
3892 char *fmt =
"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
3895 process_defined_func(s, data, size, event, arg);
3906 fmt =
"%.2x%.2x%.2x%.2x%.2x%.2x";
3907 if (!arg->
field.field) {
3910 if (!arg->
field.field) {
3912 __func__, arg->
field.name);
3916 if (arg->
field.field->size != 6) {
3920 buf = data + arg->
field.field->offset;
3924 static int is_printable_array(
char *p,
unsigned int len)
3928 for (i = 0; i < len && p[
i]; i++)
3934 static void print_event_fields(
struct trace_seq *s,
void *data,
int size,
3938 unsigned long long val;
3941 field =
event->format.fields;
3954 is_printable_array(data + offset, len)) {
3958 for (i = 0; i < len; i++) {
3962 *((
unsigned char *)data + offset + i));
3973 switch (field->
size) {
4000 field = field->
next;
4006 struct pevent *pevent =
event->pevent;
4010 const char *ptr = print_fmt->
format;
4011 unsigned long long val;
4012 struct func_map *
func;
4013 const char *saveptr;
4014 char *bprint_fmt =
NULL;
4024 print_event_fields(s, data, size, event);
4029 bprint_fmt = get_bprint_format(data, size, event);
4030 args = make_bprint_args(bprint_fmt, data, size, event);
4035 for (; *
ptr; ptr++) {
4057 }
else if (*ptr ==
'%') {
4086 len_arg = eval_num_arg(data, size, event, arg);
4101 if (*(ptr+1) ==
'F' ||
4105 }
else if (*(ptr+1) ==
'M' || *(ptr+1) ==
'm') {
4106 print_mac_arg(s, *(ptr+1), data, size, event, arg);
4124 len = ((
unsigned long)ptr + 1) -
4125 (
unsigned long)saveptr;
4134 memcpy(format, saveptr, len);
4137 val = eval_num_arg(data, size, event, arg);
4141 func = find_func(pevent, val);
4144 if (show_func ==
'F')
4152 sizeof(
long) != 8) {
4160 else if (
strcmp(format,
"%p") == 0)
4161 strcpy(format,
"0x%llx");
4207 len = ((
unsigned long)ptr + 1) -
4208 (
unsigned long)saveptr;
4217 memcpy(format, saveptr, len);
4221 print_str_arg(s, data, size, event,
4222 format, len_arg, arg);
4257 static int check_lock_depth = 1;
4258 static int check_migrate_disable = 1;
4259 static int lock_depth_exists;
4260 static int migrate_disable_exists;
4261 unsigned int lat_flags;
4264 int migrate_disable;
4267 void *data = record->
data;
4269 lat_flags = parse_common_flags(pevent, data);
4270 pc = parse_common_pc(pevent, data);
4272 if (lock_depth_exists)
4273 lock_depth = parse_common_lock_depth(pevent, data);
4274 else if (check_lock_depth) {
4275 lock_depth = parse_common_lock_depth(pevent, data);
4277 check_lock_depth = 0;
4279 lock_depth_exists = 1;
4283 if (migrate_disable_exists)
4284 migrate_disable = parse_common_migrate_disable(pevent, data);
4285 else if (check_migrate_disable) {
4286 migrate_disable = parse_common_migrate_disable(pevent, data);
4287 if (migrate_disable < 0)
4288 check_migrate_disable = 0;
4290 migrate_disable_exists = 1;
4302 (hardirq && softirq) ?
'H' :
4303 hardirq ?
'h' : softirq ?
's' :
'.');
4310 if (migrate_disable_exists) {
4311 if (migrate_disable < 0)
4317 if (lock_depth_exists) {
4336 return trace_parse_common_type(pevent, rec->
data);
4360 return parse_common_pid(pevent, rec->
data);
4375 comm = find_cmdline(pevent, pid);
4391 int print_pretty = 1;
4393 if (event->
pevent->print_raw)
4394 print_event_fields(s, record->
data, record->
size, event);
4398 print_pretty =
event->handler(s, record, event,
4402 pretty_print(s, record->
data, record->
size, event);
4411 static char *spaces =
" ";
4414 unsigned long usecs;
4415 unsigned long nsecs;
4417 void *data = record->
data;
4426 if (record->
size < 0) {
4431 type = trace_parse_common_type(pevent, data);
4435 do_warning(
"ug! no event found for type %d", type);
4439 pid = parse_common_pid(pevent, data);
4440 comm = find_cmdline(pevent, pid);
4444 comm, pid, record->
cpu);
4467 static int events_id_cmp(
const void *a,
const void *b)
4472 if ((*ea)->id < (*eb)->id)
4475 if ((*ea)->id > (*eb)->id)
4481 static int events_name_cmp(
const void *a,
const void *b)
4487 res =
strcmp((*ea)->name, (*eb)->name);
4491 res =
strcmp((*ea)->system, (*eb)->system);
4495 return events_id_cmp(a, b);
4498 static int events_system_cmp(
const void *a,
const void *b)
4504 res =
strcmp((*ea)->system, (*eb)->system);
4508 res =
strcmp((*ea)->name, (*eb)->name);
4512 return events_id_cmp(a, b);
4518 int (*
sort)(
const void *
a,
const void *
b);
4522 if (events && pevent->
last_type == sort_type)
4542 switch (sort_type) {
4544 sort = events_id_cmp;
4547 sort = events_name_cmp;
4550 sort = events_system_cmp;
4563 get_event_fields(
const char *type,
const char *name,
4570 fields =
malloc(
sizeof(*fields) * (count + 1));
4574 for (field = list;
field; field = field->
next) {
4575 fields[i++] =
field;
4576 if (i == count + 1) {
4577 do_warning(
"event %s has more %s fields than specified",
4585 do_warning(
"event %s has less %s fields than specified",
4602 return get_event_fields(
"common", event->
name,
4604 event->
format.common_fields);
4616 return get_event_fields(
"event", event->
name,
4626 print_fields(s, field->
next);
4631 static void print_args(
struct print_arg *args)
4633 int print_paren = 1;
4636 switch (args->
type) {
4647 printf(
"__print_flags(");
4648 print_args(args->
flags.field);
4651 print_fields(&s, args->
flags.flags);
4657 printf(
"__print_symbolic(");
4658 print_args(args->
symbol.field);
4661 print_fields(&s, args->
symbol.symbols);
4668 print_args(args->
hex.field);
4670 print_args(args->
hex.size);
4686 print_args(args->
op.left);
4688 print_args(args->
op.right);
4698 print_args(args->
next);
4702 static void parse_header_field(
const char *field,
4703 int *offset,
int *size,
int mandatory)
4705 unsigned long long save_input_buf_ptr;
4706 unsigned long long save_input_buf_siz;
4710 save_input_buf_ptr = input_buf_ptr;
4711 save_input_buf_siz = input_buf_siz;
4715 if (read_expected(
EVENT_OP,
":") < 0)
4719 if (read_expect_type(
EVENT_ITEM, &token) < 0)
4730 if (read_expect_type(
EVENT_ITEM, &token) < 0)
4732 if (
strcmp(token, field) != 0)
4737 if (read_expected(
EVENT_OP,
";") < 0)
4741 if (read_expected(
EVENT_OP,
":") < 0)
4743 if (read_expect_type(
EVENT_ITEM, &token) < 0)
4745 *offset = atoi(token);
4747 if (read_expected(
EVENT_OP,
";") < 0)
4751 if (read_expected(
EVENT_OP,
":") < 0)
4753 if (read_expect_type(
EVENT_ITEM, &token) < 0)
4755 *size = atoi(token);
4757 if (read_expected(
EVENT_OP,
";") < 0)
4759 type = read_token(&token);
4765 if (
strcmp(token,
"signed") != 0)
4770 if (read_expected(
EVENT_OP,
":") < 0)
4777 if (read_expected(
EVENT_OP,
";") < 0)
4788 input_buf_ptr = save_input_buf_ptr;
4789 input_buf_siz = save_input_buf_siz;
4823 init_input_buf(buf, size);
4838 int id,
const char *sys_name,
4839 const char *event_name)
4841 if (
id >= 0 &&
id != event->
id)
4844 if (event_name && (
strcmp(event_name, event->
name) != 0))
4847 if (sys_name && (
strcmp(sys_name, event->
system) != 0))
4860 static int find_event_handle(
struct pevent *pevent,
struct event_format *event)
4864 for (next = &pevent->
handlers; *next;
4865 next = &(*next)->
next) {
4867 if (event_matches(event, handle->
id,
4876 pr_stat(
"overriding event (%d) %s:%s with new print handler",
4879 event->handler = handle->
func;
4880 event->context = handle->
context;
4882 *next = handle->
next;
4883 free_handler(handle);
4902 struct pevent *pevent,
const char *buf,
4903 unsigned long size,
const char *
sys)
4908 init_input_buf(buf, size);
4910 *eventp =
event = alloc_event();
4912 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
4914 event->name = event_read_name();
4917 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
4918 goto event_alloc_failed;
4921 if (
strcmp(sys,
"ftrace") == 0) {
4928 event->id = event_read_id();
4929 if (event->
id < 0) {
4930 ret = PEVENT_ERRNO__READ_ID_FAILED;
4935 goto event_alloc_failed;
4938 event->system = strdup(sys);
4940 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
4941 goto event_alloc_failed;
4947 ret = event_read_format(event);
4949 ret = PEVENT_ERRNO__READ_FORMAT_FAILED;
4950 goto event_parse_failed;
4957 if (pevent && find_event_handle(pevent, event))
4960 ret = event_read_print(event);
4964 ret = PEVENT_ERRNO__READ_PRINT_FAILED;
4965 goto event_parse_failed;
4973 list = &
event->print_fmt.args;
4974 for (field = event->
format.fields; field; field = field->
next) {
4978 return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED;
4982 if (!arg->
field.name) {
4985 return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED;
5022 unsigned long size,
const char *
sys)
5042 unsigned long size,
const char *
sys)
5050 if (add_event(pevent, event)) {
5051 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
5052 goto event_add_failed;
5055 #define PRINT_ARGS 0
5067 #define _PE(code, str) str
5068 static const char *
const pevent_error_str[] = {
5074 char *buf,
size_t buflen)
5080 msg = strerror_r(errnum, buf, buflen);
5082 size_t len =
strlen(msg);
5084 *(buf +
min(buflen - 1, len)) =
'\0';
5094 msg = pevent_error_str[
idx];
5097 case PEVENT_ERRNO__MEM_ALLOC_FAILED:
5098 case PEVENT_ERRNO__PARSE_EVENT_FAILED:
5099 case PEVENT_ERRNO__READ_ID_FAILED:
5100 case PEVENT_ERRNO__READ_FORMAT_FAILED:
5101 case PEVENT_ERRNO__READ_PRINT_FAILED:
5102 case PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED:
5116 unsigned long long *val,
int err)
5152 void *data = record->
data;
5174 data + offset, field->
size);
5175 *len = offset >> 16;
5196 unsigned long long *val,
int err)
5221 unsigned long long *val,
int err)
5246 unsigned long long *val,
int err)
5274 unsigned long long val;
5332 func_handle = find_func_handler(pevent, name);
5339 pr_stat(
"override of function helper '%s'", name);
5340 remove_func_handler(pevent, name);
5343 func_handle = calloc(1,
sizeof(*func_handle));
5345 do_warning(
"Failed to allocate function handler");
5346 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
5350 func_handle->
name = strdup(name);
5352 if (!func_handle->
name) {
5353 do_warning(
"Failed to allocate function name");
5355 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
5358 next_param = &(func_handle->
params);
5366 do_warning(
"Invalid argument type %d", type);
5367 ret = PEVENT_ERRNO__INVALID_ARG_TYPE;
5371 param =
malloc(
sizeof(*param));
5373 do_warning(
"Failed to allocate function param");
5374 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
5380 *next_param =
param;
5381 next_param = &(param->
next);
5393 free_func_handle(func_handle);
5415 int id,
char *sys_name,
char *event_name,
5427 if (event_name && (
strcmp(event_name, event->
name) != 0))
5429 if (sys_name && (
strcmp(sys_name, event->
system) != 0))
5437 pr_stat(
"overriding event (%d) %s:%s with new print handler",
5440 event->handler =
func;
5446 handle = calloc(1,
sizeof(*handle));
5448 do_warning(
"Failed to allocate event handler");
5449 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
5456 handle->
sys_name = strdup(sys_name);
5460 do_warning(
"Failed to allocate event/sys name");
5464 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
5480 struct pevent *pevent = calloc(1,
sizeof(*pevent));
5493 static void free_format_fields(
struct format_field *field)
5506 static void free_formats(
struct format *format)
5509 free_format_fields(format->
fields);
5517 free_formats(&event->
format);
5556 cmdnext = cmdlist->
next;
5571 funcnext = funclist->
next;
5575 funclist = funcnext;
5581 free_func_handle(func_handler);
5590 while (printklist) {
5591 printknext = printklist->
next;
5594 printklist = printknext;
5603 free_handler(handle);