[PATCH v1] Extend -e flag to provide the user possibility of listing all system calls in a class.

aminkhorsandi at gmail.com aminkhorsandi at gmail.com
Thu Jul 7 14:17:16 UTC 2016


From: Amin Khorsandi <amin.khorsandi at infinera.com>

---
 strace.1  |  5 +++++
 syscall.c | 26 +++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/strace.1 b/strace.1
index b7dddc0..c2088fa 100644
--- a/strace.1
+++ b/strace.1
@@ -403,6 +403,11 @@ Furthermore, using the abbreviation will ensure that you don't
 accidentally forget to include a call like
 .B lstat
 in the list.  Betchya woulda forgot that one.
+To see a list of all system calls in a class you can use
+.BR "-e\ trace?" = classname .
+For example you can see what are the system calls in the network
+class running strace using the option
+.BR "-e\ trace?" = network .
 .TP
 .BR "\-e\ trace" = process
 Trace all system calls which involve process management.  This
diff --git a/syscall.c b/syscall.c
index c61f827..fb20f65 100644
--- a/syscall.c
+++ b/syscall.c
@@ -503,6 +503,25 @@ lookup_class(const char *s)
 	return -1;
 }
 
+static void
+print_trace_class(const char* trace_class)
+{
+	unsigned int i;
+	unsigned pers = 0; /* only print system calls in personality 0 */
+	int class = lookup_class(trace_class);
+
+	if (class != -1) {
+		printf("List of system calls in %s class\n", trace_class);
+		printf("%s\n", "-------------------------------------");
+		for (i = 0; i < nsyscall_vec[pers]; i++)
+			if (sysent_vec[pers][i].sys_flags & class) {
+			printf("\t%s \n", sysent_vec[pers][i].sys_name);
+		}
+	} else {
+		error_msg_and_die("invalid class name '%s'", trace_class);
+	}
+}
+
 void
 qualify(const char *s)
 {
@@ -518,7 +537,12 @@ qualify(const char *s)
 	opt = &qual_options[0];
 	for (i = 0; (p = qual_options[i].option_name); i++) {
 		unsigned int len = strlen(p);
-		if (strncmp(s, p, len) == 0 && s[len] == '=') {
+		if (strncmp(s, p, len) == 0 && s[len] == '?' && s[len + 1] == '=') {
+			s += len + 2;
+			print_trace_class(s);
+			exit(0);
+		}
+		else if (strncmp(s, p, len) == 0 && s[len] == '=') {
 			opt = &qual_options[i];
 			s += len + 1;
 			break;
-- 
2.4.10





More information about the Strace-devel mailing list