[PATCH] Decode paths associated with file descriptors returned by syscalls

zubin.mithra at gmail.com zubin.mithra at gmail.com
Wed May 28 15:50:04 UTC 2014


From: Zubin Mithra <zubin.mithra at gmail.com>

* Type of `show_fd_path` changed from `bool` to `unsigned int` to
  support the `-yy` flag.
* util.c (returns_fd): New function that checks if the tcb refers
  to a function that returns a file descriptor.
* (trace_syscall_exiting): Use returns_fd to determine whether
  tcp->u_rval is a file descriptor.

Signed-off-by: Zubin Mithra <zubin.mithra at gmail.com>
---
 defs.h    |  3 ++-
 strace.c  |  4 ++--
 syscall.c |  7 ++++++-
 util.c    | 13 +++++++++++++
 4 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/defs.h b/defs.h
index 4e06a92..5381e60 100644
--- a/defs.h
+++ b/defs.h
@@ -550,7 +550,7 @@ extern bool Tflag;
 extern bool iflag;
 extern unsigned int qflag;
 extern bool not_failing_only;
-extern bool show_fd_path;
+extern unsigned int show_fd_path;
 extern bool hide_log_until_execve;
 /* are we filtering traces based on paths? */
 extern const char **paths_selected;
@@ -625,6 +625,7 @@ extern long getrval2(struct tcb *);
  */
 extern int setbpt(struct tcb *);
 extern int clearbpt(struct tcb *);
+extern bool returns_fd(struct tcb *);
 
 extern const char *signame(int);
 extern void pathtrace_select(const char *);
diff --git a/strace.c b/strace.c
index 8a49340..4e7868d 100644
--- a/strace.c
+++ b/strace.c
@@ -124,7 +124,7 @@ static int post_attach_sigstop = TCB_IGNORE_ONE_SIGSTOP;
 bool not_failing_only = 0;
 
 /* Show path associated with fd arguments */
-bool show_fd_path = 0;
+unsigned int show_fd_path = 0;
 
 static bool detach_on_execve = 0;
 /* Are we "strace PROG" and need to skip detach on first execve? */
@@ -1706,7 +1706,7 @@ init(int argc, char *argv[])
 			xflag++;
 			break;
 		case 'y':
-			show_fd_path = 1;
+			show_fd_path++;
 			break;
 		case 'v':
 			qualify("abbrev=none");
diff --git a/syscall.c b/syscall.c
index 28bdb66..4932bbe 100644
--- a/syscall.c
+++ b/syscall.c
@@ -2669,7 +2669,12 @@ trace_syscall_exiting(struct tcb *tcp)
 				tprintf("= %lu", tcp->u_rval);
 				break;
 			case RVAL_DECIMAL:
-				tprintf("= %ld", tcp->u_rval);
+				if ( show_fd_path && returns_fd(tcp) ) {
+					tprints("= ");
+					printfd(tcp, tcp->u_rval);
+				}
+				else
+					tprintf("= %ld", tcp->u_rval);
 				break;
 #if defined(LINUX_MIPSN32) || defined(X32)
 			/*
diff --git a/util.c b/util.c
index ff18b87..b1f1e90 100644
--- a/util.c
+++ b/util.c
@@ -1549,3 +1549,16 @@ clearbpt(struct tcb *tcp)
 	tcp->flags &= ~TCB_BPTSET;
 	return 0;
 }
+
+bool
+returns_fd(struct tcb *tcp)
+{
+	if ( tcp->s_ent->sys_func == sys_open   ||
+	     tcp->s_ent->sys_func == sys_openat ||
+	     tcp->s_ent->sys_func == sys_creat  ||
+	     tcp->s_ent->sys_func == sys_dup    ||
+	     tcp->s_ent->sys_func == sys_dup2   ||
+	     tcp->s_ent->sys_func == sys_dup3 )
+		return 1;
+	return 0;
+}
-- 
1.8.4





More information about the Strace-devel mailing list