]> granicus.if.org Git - strace/commitdiff
Change printnum_* printers to honor syserror
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 13 Jul 2015 20:44:01 +0000 (20:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 14 Jul 2015 21:59:26 +0000 (21:59 +0000)
With this change, printnum_* printers will not attempt to fetch data
in case of exiting(tcp) && syserror(tcp).
All "at exiting" decoders that call these printers have been made
ready for this change in previous commits.

* util.c (DEF_PRINTNUM, DEF_PRINTPAIR): Use umove_or_printaddr.
* prctl.c (prctl_exit): Use printnum_int and printnum_long.
(sys_arch_prctl): Do not check for syserror.

prctl.c
util.c

diff --git a/prctl.c b/prctl.c
index 4a6bd253f91caf627a7849ff3330121d63c53503..364a43d64c62080dbc5dbb5a70071a4a0213b0b1 100644 (file)
--- a/prctl.c
+++ b/prctl.c
@@ -175,7 +175,6 @@ prctl_enter(struct tcb *tcp)
 static int
 prctl_exit(struct tcb *tcp)
 {
-       unsigned long addr;
        unsigned int i;
 
        switch (tcp->u_arg[0]) {
@@ -194,13 +193,7 @@ prctl_exit(struct tcb *tcp)
        case PR_GET_FPEMU:
        case PR_GET_FPEXC:
                tprints(", ");
-               /* cannot use printnum_int() because of syserror() */
-               if (!tcp->u_arg[1])
-                       tprints("NULL");
-               else if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
-                       tprintf("%#lx", tcp->u_arg[1]);
-               else
-                       tprintf("[%u]", i);
+               printnum_int(tcp, tcp->u_arg[1], "%u");
                break;
 
        case PR_GET_NAME:
@@ -234,13 +227,7 @@ prctl_exit(struct tcb *tcp)
 
        case PR_GET_TID_ADDRESS:
                tprints(", ");
-               /* cannot use printnum_long() because of syserror() */
-               if (!tcp->u_arg[1])
-                       tprints("NULL");
-               else if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &addr) < 0)
-                       tprintf("%#lx", tcp->u_arg[1]);
-               else
-                       tprintf("[%#lx]", addr);
+               printnum_long(tcp, tcp->u_arg[1], "%#lx");
                break;
 
        case PR_GET_TSC:
@@ -299,8 +286,6 @@ SYS_FUNC(arch_prctl)
        case ARCH_GET_GS:
        case ARCH_GET_FS:
                if (exiting(tcp)) {
-                       if (syserror(tcp))
-                               break;
                        tprints(", ");
                        printnum_long(tcp, tcp->u_arg[1], "%#lx");
                }
diff --git a/util.c b/util.c
index ed2da67d7336d6b16bcdc7cdb077660aab5eb737..a7d2bd8569f7e7ebc8e443881825fac9cad00e2c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -389,11 +389,7 @@ void                                                                       \
 printnum_ ## name(struct tcb *tcp, const long addr, const char *fmt)   \
 {                                                                      \
        type num;                                                       \
-       if (!addr)                                                      \
-               tprints("NULL");                                        \
-       else if (umove(tcp, addr, &num) < 0)                            \
-               tprintf("%#lx", addr);                                  \
-       else {                                                          \
+       if (!umove_or_printaddr(tcp, addr, &num)) {                     \
                tprints("[");                                           \
                tprintf(fmt, num);                                      \
                tprints("]");                                           \
@@ -405,12 +401,7 @@ void                                                                       \
 printpair_ ## name(struct tcb *tcp, const long addr, const char *fmt)  \
 {                                                                      \
        type pair[2];                                                   \
-       if (!addr)                                                      \
-               tprints("NULL");                                        \
-       else if ((exiting(tcp) && syserror(tcp)) ||                     \
-                umove(tcp, addr, &pair) < 0)                           \
-               tprintf("%#lx", addr);                                  \
-       else {                                                          \
+       if (!umove_or_printaddr(tcp, addr, &pair)) {                    \
                tprints("[");                                           \
                tprintf(fmt, pair[0]);                                  \
                tprints(", ");                                          \