LCOV - code coverage report
Current view: top level - strace - wait.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 54 63 85.7 %
Date: 2017-07-31 03:46:08 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 30 76.7 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
       3                 :            :  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
       4                 :            :  * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
       5                 :            :  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
       6                 :            :  * Copyright (c) 2002-2004 Roland McGrath <roland@redhat.com>
       7                 :            :  * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
       8                 :            :  * Copyright (c) 2009-2013 Denys Vlasenko <dvlasenk@redhat.com>
       9                 :            :  * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
      10                 :            :  * Copyright (c) 2014-2017 The strace developers.
      11                 :            :  * All rights reserved.
      12                 :            :  *
      13                 :            :  * Redistribution and use in source and binary forms, with or without
      14                 :            :  * modification, are permitted provided that the following conditions
      15                 :            :  * are met:
      16                 :            :  * 1. Redistributions of source code must retain the above copyright
      17                 :            :  *    notice, this list of conditions and the following disclaimer.
      18                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      19                 :            :  *    notice, this list of conditions and the following disclaimer in the
      20                 :            :  *    documentation and/or other materials provided with the distribution.
      21                 :            :  * 3. The name of the author may not be used to endorse or promote products
      22                 :            :  *    derived from this software without specific prior written permission.
      23                 :            :  *
      24                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      25                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      26                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      27                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      28                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      29                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      30                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      31                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      32                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      33                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      34                 :            :  */
      35                 :            : 
      36                 :            : #include "defs.h"
      37                 :            : 
      38                 :            : #include <sys/wait.h>
      39                 :            : 
      40                 :            : #include "xlat/wait4_options.h"
      41                 :            : 
      42                 :            : #if !defined WCOREFLAG && defined WCOREFLG
      43                 :            : # define WCOREFLAG WCOREFLG
      44                 :            : #endif
      45                 :            : #ifndef WCOREFLAG
      46                 :            : # define WCOREFLAG 0x80
      47                 :            : #endif
      48                 :            : #ifndef WCOREDUMP
      49                 :            : # define WCOREDUMP(status)  ((status) & 0200)
      50                 :            : #endif
      51                 :            : #ifndef W_STOPCODE
      52                 :            : # define W_STOPCODE(sig)  ((sig) << 8 | 0x7f)
      53                 :            : #endif
      54                 :            : #ifndef W_EXITCODE
      55                 :            : # define W_EXITCODE(ret, sig)  ((ret) << 8 | (sig))
      56                 :            : #endif
      57                 :            : #ifndef W_CONTINUED
      58                 :            : # define W_CONTINUED 0xffff
      59                 :            : #endif
      60                 :            : 
      61                 :            : #include "ptrace.h"
      62                 :            : #include "xlat/ptrace_events.h"
      63                 :            : 
      64                 :            : static int
      65                 :         22 : printstatus(int status)
      66                 :            : {
      67                 :         22 :         int exited = 0;
      68                 :            : 
      69                 :            :         /*
      70                 :            :          * Here is a tricky presentation problem.  This solution
      71                 :            :          * is still not entirely satisfactory but since there
      72                 :            :          * are no wait status constructors it will have to do.
      73                 :            :          */
      74         [ +  + ]:         22 :         if (WIFSTOPPED(status)) {
      75                 :          4 :                 int sig = WSTOPSIG(status);
      76         [ +  - ]:          4 :                 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s%s}",
      77                 :            :                         signame(sig & 0x7f),
      78                 :          4 :                         sig & 0x80 ? " | 0x80" : "");
      79                 :          4 :                 status &= ~W_STOPCODE(sig);
      80         [ +  + ]:         18 :         } else if (WIFSIGNALED(status)) {
      81         [ +  + ]:          6 :                 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
      82                 :          6 :                         signame(WTERMSIG(status)),
      83                 :          6 :                         WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
      84                 :          6 :                 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
      85         [ +  + ]:         12 :         } else if (WIFEXITED(status)) {
      86                 :          8 :                 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
      87                 :          8 :                         WEXITSTATUS(status));
      88                 :          8 :                 exited = 1;
      89                 :          8 :                 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
      90                 :            :         }
      91                 :            : #ifdef WIFCONTINUED
      92         [ +  - ]:          4 :         else if (WIFCONTINUED(status)) {
      93                 :          4 :                 tprints("[{WIFCONTINUED(s)}");
      94                 :          4 :                 status &= ~W_CONTINUED;
      95                 :            :         }
      96                 :            : #endif
      97                 :            :         else {
      98                 :          0 :                 tprintf("[%#x]", status);
      99                 :          0 :                 return 0;
     100                 :            :         }
     101                 :            : 
     102         [ -  + ]:         22 :         if (status) {
     103                 :          0 :                 unsigned int event = (unsigned int) status >> 16;
     104         [ #  # ]:          0 :                 if (event) {
     105                 :          0 :                         tprints(" | ");
     106                 :            :                         printxval(ptrace_events, event, "PTRACE_EVENT_???");
     107                 :          0 :                         tprints(" << 16");
     108                 :          0 :                         status &= 0xffff;
     109                 :            :                 }
     110         [ #  # ]:          0 :                 if (status)
     111                 :          0 :                         tprintf(" | %#x", status);
     112                 :            :         }
     113                 :         22 :         tprints("]");
     114                 :            : 
     115                 :         22 :         return exited;
     116                 :            : }
     117                 :            : 
     118                 :            : static int
     119                 :         70 : printwaitn(struct tcb *const tcp,
     120                 :            :            void (*const print_rusage)(struct tcb *, kernel_ulong_t))
     121                 :            : {
     122         [ +  + ]:         70 :         if (entering(tcp)) {
     123                 :            :                 /* On Linux, kernel-side pid_t is typedef'ed to int
     124                 :            :                  * on all arches. Also, glibc-2.8 truncates wait3 and wait4
     125                 :            :                  * pid argument to int on 64bit arches, producing,
     126                 :            :                  * for example, wait4(4294967295, ...) instead of -1
     127                 :            :                  * in strace. We have to use int here, not long.
     128                 :            :                  */
     129                 :         35 :                 int pid = tcp->u_arg[0];
     130                 :         35 :                 tprintf("%d, ", pid);
     131                 :            :         } else {
     132                 :            :                 int status;
     133                 :            : 
     134                 :            :                 /* status */
     135         [ +  + ]:         35 :                 if (tcp->u_rval == 0)
     136                 :          8 :                         printaddr(tcp->u_arg[1]);
     137         [ +  + ]:         27 :                 else if (!umove_or_printaddr(tcp, tcp->u_arg[1], &status))
     138                 :         22 :                         printstatus(status);
     139                 :            :                 /* options */
     140                 :         35 :                 tprints(", ");
     141                 :         35 :                 printflags(wait4_options, tcp->u_arg[2], "W???");
     142         [ +  + ]:         35 :                 if (print_rusage) {
     143                 :            :                         /* usage */
     144                 :         34 :                         tprints(", ");
     145         [ +  + ]:         34 :                         if (tcp->u_rval > 0)
     146                 :         22 :                                 print_rusage(tcp, tcp->u_arg[3]);
     147                 :            :                         else
     148                 :         35 :                                 printaddr(tcp->u_arg[3]);
     149                 :            :                 }
     150                 :            :         }
     151                 :         70 :         return 0;
     152                 :            : }
     153                 :            : 
     154                 :          2 : SYS_FUNC(waitpid)
     155                 :            : {
     156                 :          2 :         return printwaitn(tcp, NULL);
     157                 :            : }
     158                 :            : 
     159                 :         68 : SYS_FUNC(wait4)
     160                 :            : {
     161                 :         68 :         return printwaitn(tcp, printrusage);
     162                 :            : }
     163                 :            : 
     164                 :            : #ifdef ALPHA
     165                 :            : SYS_FUNC(osf_wait4)
     166                 :            : {
     167                 :            :         return printwaitn(tcp, printrusage32);
     168                 :            : }
     169                 :            : #endif
     170                 :            : 
     171                 :            : #include "xlat/waitid_types.h"
     172                 :            : 
     173                 :         64 : SYS_FUNC(waitid)
     174                 :            : {
     175         [ +  + ]:         64 :         if (entering(tcp)) {
     176                 :         32 :                 printxval(waitid_types, tcp->u_arg[0], "P_???");
     177                 :         32 :                 int pid = tcp->u_arg[1];
     178                 :         32 :                 tprintf(", %d, ", pid);
     179                 :            :         } else {
     180                 :            :                 /* siginfo */
     181                 :         32 :                 printsiginfo_at(tcp, tcp->u_arg[2]);
     182                 :            :                 /* options */
     183                 :         32 :                 tprints(", ");
     184                 :         32 :                 printflags(wait4_options, tcp->u_arg[3], "W???");
     185                 :            :                 /* usage */
     186                 :         32 :                 tprints(", ");
     187                 :         32 :                 printrusage(tcp, tcp->u_arg[4]);
     188                 :            :         }
     189                 :         64 :         return 0;
     190                 :            : }

Generated by: LCOV version 1.11