[PATCH v2] Add -m flag to list system calls of a class.

Amin Khorsandiaghai aminkhorsandi at gmail.com
Tue Jul 12 13:30:37 UTC 2016


---
 strace.1  |  5 +++++
 strace.c  |  6 +++++-
 syscall.c | 21 +++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/strace.1 b/strace.1
index b7dddc0..5f5c1cc 100644
--- a/strace.1
+++ b/strace.1
@@ -488,6 +488,11 @@ When strace can be interrupted by signals (such as pressing ^C).
 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
 strace -o FILE PROG not stop on ^Z).
 .TP
+.BI "\-m " traceclass
+List all system calls in a trace class. For example
+.BR "\-m file"
+prints the list of all system calls in file class.
+.TP
 .BI "\-o " filename
 Write the trace output to the file
 .I filename
diff --git a/strace.c b/strace.c
index 564f1cc..1fbc80c 100644
--- a/strace.c
+++ b/strace.c
@@ -1524,7 +1524,7 @@ init(int argc, char *argv[])
 		"k"
 #endif
 		"D"
-		"a:e:o:O:p:s:S:u:E:P:I:")) != EOF) {
+		"a:e:m:o:O:p:s:S:u:E:P:I:")) != EOF) {
 		switch (c) {
 		case 'b':
 			if (strcmp(optarg, "execve") != 0)
@@ -1601,6 +1601,10 @@ init(int argc, char *argv[])
 		case 'e':
 			qualify(optarg);
 			break;
+		case 'm':
+			print_trace_class(optarg);
+			exit(0);
+			break;
 		case 'o':
 			outfname = xstrdup(optarg);
 			break;
diff --git a/syscall.c b/syscall.c
index c61f827..cc974d7 100644
--- a/syscall.c
+++ b/syscall.c
@@ -504,6 +504,27 @@ lookup_class(const char *s)
 }
 
 void
+print_trace_class(const char *trace_class)
+{
+	unsigned int i;
+	unsigned pers;
+ 	int rc;
+
+	if ((rc = lookup_class(trace_class)) != -1) {
+		fprintf(stdout, "List of system calls in %s class\n", trace_class);
+		fprintf(stdout, "-------------------------------------\n");
+		for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
+			for (i = 0; i < nsyscall_vec[pers]; i++)
+				if (sysent_vec[pers][i].sys_flags & rc) {
+					fprintf(stdout, "\t%s \n", sysent_vec[pers][i].sys_name);
+				}
+		}
+	} else {
+		error_msg_and_die("invalid class '%s'", trace_class);
+	}
+}
+
+void
 qualify(const char *s)
 {
 	const struct qual_options *opt;
-- 
1.9.1





More information about the Strace-devel mailing list