[v4,18/39] dyndbg: add label keyword handling

Message ID 20240210235009.2405808-19-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
  From: Jim Cromie <jim.cromie@gmail.com>

Add a new user_label field to struct ddebug_query, label keyword
handling and saving to the struct, and update ddebug_change to test if
a given user_label is found in the list of known trace-instances.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 lib/dynamic_debug.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index dbae1ed6ab5b..17df4bf6863a 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -61,6 +61,7 @@  struct ddebug_query {
 	const char *function;
 	const char *format;
 	const char *class_string;
+	const char *user_label;
 	unsigned int first_lineno, last_lineno;
 };
 
@@ -300,13 +301,14 @@  static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
 			fmtlen--;
 	}
 
-	v3pr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u class=%s\n",
+	v3pr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u class=%s label=%s\n",
 		  msg,
 		  query->function ?: "",
 		  query->filename ?: "",
 		  query->module ?: "",
 		  fmtlen, query->format ?: "",
-		  query->first_lineno, query->last_lineno, query->class_string);
+		  query->first_lineno, query->last_lineno,
+		  query->class_string, query->user_label);
 }
 
 static bool is_dd_trace_cmd(const char *str)
@@ -574,6 +576,16 @@  static int ddebug_change(const struct ddebug_query *query,
 			if (dp->class_id != valid_class)
 				continue;
 
+			/* match against a given label */
+			if (query->user_label) {
+				int idx	= find_tr_instance(query->user_label);
+
+				if (idx < 0)
+					continue;
+				if (idx != get_trace_dst(dp))
+					continue;
+			}
+
 			/* match against the source filename */
 			if (query->filename &&
 			    !match_wildcard(query->filename, dp->filename) &&
@@ -770,6 +782,8 @@  static int check_set(const char **dest, char *src, char *name)
  * file <full-pathname>
  * file <base-filename>
  * module <module-name>
+ * class <class_name>
+ * label <user_label>
  * format <escaped-string-to-find-in-format>
  * line <lineno>
  * line <first-lineno>-<last-lineno> // where either may be empty
@@ -825,6 +839,8 @@  static int ddebug_parse_query(char *words[], int nwords,
 				return -EINVAL;
 		} else if (!strcmp(keyword, "class")) {
 			rc = check_set(&query->class_string, arg, "class");
+		} else if (!strcmp(keyword, "label")) {
+			rc = check_set(&query->user_label, arg, "label");
 		} else {
 			pr_err("unknown keyword \"%s\"\n", keyword);
 			return -EINVAL;