[v4,25/39] dyndbg: don't process queries when trace cmd fails

Message ID 20240210235009.2405808-26-ukaszb@chromium.org
State New
Headers
Series dyndbg: add support for writing debug logs to trace |

Commit Message

Łukasz Bartosik Feb. 10, 2024, 11:49 p.m. UTC
  When trace open or close command fails then stop processing next
queries in multiquery string. The rationale behing this behavior
is to stop processing queries which might be dependent on success
of open/close trace commands.

Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
 lib/dynamic_debug.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
  

Patch

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 3d0c6b5faa31..d8cd40faeb4d 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -939,7 +939,8 @@  static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
 	return 0;
 }
 
-static int ddebug_exec_query(char *query_string, const char *modname)
+static int ddebug_exec_query(char *query_string, const char *modname,
+			     bool *is_trace_cmd)
 {
 	struct flag_settings modifiers = { .trace_dst = DST_NOT_SET };
 	struct ddebug_query query = {};
@@ -954,7 +955,8 @@  static int ddebug_exec_query(char *query_string, const char *modname)
 	}
 
 	/* check for open, close commands */
-	if (is_dd_trace_cmd(words[0]))
+	*is_trace_cmd = is_dd_trace_cmd(words[0]);
+	if (*is_trace_cmd)
 		return ddebug_parse_cmd(words, nwords-1);
 
 	if (ddebug_parse_query(words, nwords-1, &query, modname)) {
@@ -991,16 +993,19 @@  static int ddebug_exec_query(char *query_string, const char *modname)
 	return -EINVAL;
 }
 
-/* handle multiple queries in query string, continue on error, return
-   last error or number of matching callsites.  Module name is either
-   in param (for boot arg) or perhaps in query string.
-*/
+/* handle multiple queries in query string, continue on error with
+ * exception of open and close commands, return last error or number
+ * of matching callsites.  Module name is either in param (for boot arg)
+ * or perhaps in query string.
+ */
 static int ddebug_exec_queries(char *query, const char *modname)
 {
 	char *split;
 	int i, errs = 0, exitcode = 0, rc, nfound = 0;
 
 	for (i = 0; query; query = split) {
+		bool is_trace_cmd = false;
+
 		split = strpbrk(query, "%;\n");
 		if (split)
 			*split++ = '\0';
@@ -1011,10 +1016,16 @@  static int ddebug_exec_queries(char *query, const char *modname)
 
 		vpr_info("query %d: \"%s\" mod:%s\n", i, query, modname ?: "*");
 
-		rc = ddebug_exec_query(query, modname);
+		rc = ddebug_exec_query(query, modname, &is_trace_cmd);
 		if (rc < 0) {
 			errs++;
 			exitcode = rc;
+			/*
+			 * if open or close command failed then
+			 * do not continue with next queries
+			 */
+			if (is_trace_cmd)
+				break;
 		} else {
 			nfound += rc;
 		}