diff mbox series

trace-cmd list: Show all functions that match string by default

Message ID 20250411093628.3f68fb02@gandalf.local.home (mailing list archive)
State Accepted
Commit 2fbeb31794b4e93e6d7325fea17be0a2778d499d
Headers show
Series trace-cmd list: Show all functions that match string by default | expand

Commit Message

Steven Rostedt April 11, 2025, 1:36 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Before tracefs_filter_functions() was used to find the list of functions,
the trace-cmd list -f would list all functions that match the given string
by default. After the switching over to tracefs_filter_functions(), by
default it does a exact match.

This is quite annoying, as in most cases the user wants to see what
available functions have the given string. If the user knows the function
they are looking for, they do not need to use trace-cmd list -f !

Fixes: 39acb4cc1 ("trace-cmd list: Use tracefs_filter_functions()")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-list.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 4e2cf041..073b37fb 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -466,6 +466,8 @@  static void show_clocks(void)
 
 static void show_functions(const char *funcre)
 {
+	bool found = false;
+	char *new_re = NULL;
 	char **list;
 	int i;
 
@@ -474,11 +476,33 @@  static void show_functions(const char *funcre)
 		return;
 	}
 
+	/* if the re doesn't have any regular expressions, then add them */
+	for (i = 0; !found && funcre[i]; i++) {
+		if (funcre[i] == '\\')
+			continue;
+		switch (funcre[i]) {
+		case '*':
+		case '[':
+		case '(':
+		case '.':
+		case '?':
+			found = true;
+		}
+	}
+
+	if (!found) {
+		/* Add glob around expression */
+		if (asprintf(&new_re, "*%s*", funcre) < 0)
+			die("Failed to allocate memory");
+		funcre = new_re;
+	}
+
 	if (tracefs_filter_functions(funcre, NULL, &list) < 0)
 		die("Failed to read filte functions");
 	for (i = 0; list && list[i]; i++)
 		printf("%s\n", list[i]);
 	tracefs_list_free(list);
+	free(new_re);
 }