From: Zubin Mithra <zubin.mit...@gmail.com>

* defs.h (returns_fd): New prototype.
* util.c (returns_fd): New function that checks if the tcb refers
  to a function that returns a file descriptor.
* syscall.c (trace_syscall_exiting): Use returns_fd to determine whether
  tcp->u_rval is a file descriptor.

Signed-off-by: Zubin Mithra <zubin.mit...@gmail.com>
---
 defs.h    |  1 +
 syscall.c |  7 ++++++-
 util.c    | 11 +++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/defs.h b/defs.h
index 4e06a92..25551a3 100644
--- a/defs.h
+++ b/defs.h
@@ -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/syscall.c b/syscall.c
index 28bdb66..e6ad7ad 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..e47297a 100644
--- a/util.c
+++ b/util.c
@@ -1549,3 +1549,14 @@ clearbpt(struct tcb *tcp)
        tcp->flags &= ~TCB_BPTSET;
        return 0;
 }
+
+bool
+returns_fd(struct tcb *tcp)
+{
+       return 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;
+}
-- 
1.8.4


------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to