Thread (23 messages) 23 messages, 1 author, 2021-08-03

[PATCH v3 16/22] libtracefs: Add error message when calculation has no label

flat view
STALE1895d

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2021-08-03 17:06:53
Also in: lkml
Subsystem: the rest · Maintainer: Linus Torvalds

Revision v3 of 3 in this series.

Revisions (3)
  1. v1 [diff vs current]
  2. v2 [diff vs current]
  3. v3 current
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

If a calculation between event fields is performed and there's no label
(name) for it, it errors out, causing the bison parser to give a strange
error:

  FAILED MEMORY: add_selection(sb, (yyvsp[0].expr), NULL)
  Failed creating synthetic event!: No such file or directory

Instead, just set the compare->name field to NULL, and report a better
error later on in the processing.

  ERROR: 'no name'
  Field calculations must be labeled 'AS name'

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/tracefs-sqlhist.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/tracefs-sqlhist.c b/src/tracefs-sqlhist.c
index d7829d4804b1..81a0cd1a908b 100644
--- a/src/tracefs-sqlhist.c
+++ b/src/tracefs-sqlhist.c
@@ -243,8 +243,6 @@ __hidden int add_selection(struct sqlhist_bison *sb, void *select,
 	case EXPR_FIELD:
 		break;
 	case EXPR_COMPARE:
-		if (!name)
-			return -1;
 		expr->compare.name = name;
 		break;
 	case EXPR_NUMBER:
@@ -779,6 +777,9 @@ static int build_compare(struct tracefs_synth *synth,
 	enum tracefs_synth_calc calc;
 	int ret;
 
+	if (!compare->name)
+		return -1;
+
 	lval = &compare->lval->field;
 	rval = &compare->rval->field;
 
@@ -1117,6 +1118,14 @@ static void compare_error(struct tep_handle *tep,
 {
 	struct compare *compare = &expr->compare;
 
+	if (!compare->name) {
+		sb->line_no = expr->line;
+		sb->line_idx = expr->idx + strlen("no name");
+
+		parse_error(sb, "no name",
+		    "Field calculations must be labeled 'AS name'\n");
+	}
+
 	switch (errno) {
 	case ENODEV:
 	case EBADE:
-- 
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help