[PATCH] Path decoding of file descriptors returned from system calls

Zubin Mithra zubin.mithra at gmail.com
Sun May 25 17:49:43 UTC 2014


>From 6f7e5475f360ce8155f82cd5389f67c619ca7bed Mon Sep 17 00:00:00 2001
From: eQuiNoX__ <equinox.71717171 at gmail.com>
Date: Wed, 21 May 2014 18:19:01 +0530
Subject: [PATCH] Path decoding for system calls that return file descriptors
 implemented.

The following changes were made :- - Type of `show_fd_path`
 changed from `bool` to `unsigned int` to support the `-yy` flag - a
 `returns_fd` function added in util.c to check if the tcb refers   to a
 function that returns a file descriptor - `trace_syscall_exiting` now uses
 `returns_fd` to determine if   `tcp->u_rval` needs to be passed to `printfd`

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..d059130 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 == 2 && returns_fd(tcp) ) {
+ tprintf("= ");
+ 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