LCOV - code coverage report
Current view: top level - strace - process.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 57 64 89.1 %
Date: 2017-07-31 03:46:08 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 39 79.5 %

           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, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
       5                 :            :  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
       6                 :            :  * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
       7                 :            :  *                     Linux for s390 port by D.J. Barrow
       8                 :            :  *                    <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
       9                 :            :  * Copyright (c) 2000 PocketPenguins Inc.  Linux for Hitachi SuperH
      10                 :            :  *                    port by Greg Banks <gbanks@pocketpenguins.com>
      11                 :            :  * Copyright (c) 1999-2017 The strace developers.
      12                 :            :  *
      13                 :            :  * All rights reserved.
      14                 :            :  *
      15                 :            :  * Redistribution and use in source and binary forms, with or without
      16                 :            :  * modification, are permitted provided that the following conditions
      17                 :            :  * are met:
      18                 :            :  * 1. Redistributions of source code must retain the above copyright
      19                 :            :  *    notice, this list of conditions and the following disclaimer.
      20                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      21                 :            :  *    notice, this list of conditions and the following disclaimer in the
      22                 :            :  *    documentation and/or other materials provided with the distribution.
      23                 :            :  * 3. The name of the author may not be used to endorse or promote products
      24                 :            :  *    derived from this software without specific prior written permission.
      25                 :            :  *
      26                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      27                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      28                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      29                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      30                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      31                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      32                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      33                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      34                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      35                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      36                 :            :  */
      37                 :            : 
      38                 :            : #include "defs.h"
      39                 :            : 
      40                 :            : #ifdef HAVE_ELF_H
      41                 :            : # include <elf.h>
      42                 :            : #endif
      43                 :            : 
      44                 :            : #include "xlat/nt_descriptor_types.h"
      45                 :            : 
      46                 :            : #include "regs.h"
      47                 :            : #include "ptrace.h"
      48                 :            : #include "xlat/ptrace_cmds.h"
      49                 :            : #include "xlat/ptrace_setoptions_flags.h"
      50                 :            : #include "xlat/ptrace_peeksiginfo_flags.h"
      51                 :            : 
      52                 :            : #define uoff(member)    offsetof(struct user, member)
      53                 :            : #define XLAT_UOFF(member)       { uoff(member), "offsetof(struct user, " #member ")" }
      54                 :            : 
      55                 :            : static const struct xlat struct_user_offsets[] = {
      56                 :            : #include "userent.h"
      57                 :            :         XLAT_END
      58                 :            : };
      59                 :            : 
      60                 :            : static void
      61                 :          4 : print_user_offset_addr(const kernel_ulong_t addr)
      62                 :            : {
      63                 :            :         const struct xlat *x;
      64                 :            : 
      65         [ +  + ]:        148 :         for (x = struct_user_offsets; x->str; ++x) {
      66         [ +  - ]:        144 :                 if (x->val >= addr)
      67                 :            :                         break;
      68                 :            :         }
      69                 :            : 
      70         [ +  - ]:          4 :         if (!x->str) {
      71                 :          4 :                 printaddr(addr);
      72         [ #  # ]:          0 :         } else if (x->val > addr) {
      73         [ #  # ]:          0 :                 if (x == struct_user_offsets) {
      74                 :          0 :                         printaddr(addr);
      75                 :            :                 } else {
      76                 :          0 :                         --x;
      77                 :          0 :                         tprintf("%s + %" PRI_klu,
      78                 :          0 :                                 x->str, addr - (kernel_ulong_t) x->val);
      79                 :            :                 }
      80                 :            :         } else {
      81                 :          0 :                 tprints(x->str);
      82                 :            :         }
      83                 :          4 : }
      84                 :            : 
      85                 :         98 : SYS_FUNC(ptrace)
      86                 :            : {
      87                 :         98 :         const kernel_ulong_t request = tcp->u_arg[0];
      88                 :         98 :         const int pid = tcp->u_arg[1];
      89                 :         98 :         const kernel_ulong_t addr = tcp->u_arg[2];
      90                 :         98 :         const kernel_ulong_t data = tcp->u_arg[3];
      91                 :            : 
      92         [ +  + ]:         98 :         if (entering(tcp)) {
      93                 :            :                 /* request */
      94                 :            :                 printxval64(ptrace_cmds, request, "PTRACE_???");
      95                 :            : 
      96         [ +  + ]:         78 :                 if (request == PTRACE_TRACEME) {
      97                 :            :                         /* pid, addr, and data are ignored. */
      98                 :            :                         return RVAL_DECODED;
      99                 :            :                 }
     100                 :            : 
     101                 :            :                 /* pid */
     102                 :         76 :                 tprintf(", %d", pid);
     103                 :            : 
     104                 :            :                 /* addr */
     105   [ +  +  +  +  :         76 :                 switch (request) {
                   +  + ]
     106                 :            :                 case PTRACE_ATTACH:
     107                 :            :                 case PTRACE_INTERRUPT:
     108                 :            :                 case PTRACE_KILL:
     109                 :            :                 case PTRACE_LISTEN:
     110                 :            :                         /* addr and data are ignored */
     111                 :            :                         return RVAL_DECODED;
     112                 :            :                 case PTRACE_PEEKUSER:
     113                 :            :                 case PTRACE_POKEUSER:
     114                 :          4 :                         tprints(", ");
     115                 :          4 :                         print_user_offset_addr(addr);
     116                 :          4 :                         break;
     117                 :            :                 case PTRACE_GETREGSET:
     118                 :            :                 case PTRACE_SETREGSET:
     119                 :          4 :                         tprints(", ");
     120                 :          4 :                         printxval(nt_descriptor_types, addr, "NT_???");
     121                 :            :                         break;
     122                 :            :                 case PTRACE_GETSIGMASK:
     123                 :            :                 case PTRACE_SETSIGMASK:
     124                 :            :                 case PTRACE_SECCOMP_GET_FILTER:
     125                 :          6 :                         tprintf(", %" PRI_klu, addr);
     126                 :          6 :                         break;
     127                 :            :                 case PTRACE_PEEKSIGINFO: {
     128                 :          6 :                         tprints(", ");
     129                 :            :                         struct {
     130                 :            :                                 uint64_t off;
     131                 :            :                                 uint32_t flags;
     132                 :            :                                 uint32_t nr;
     133                 :            :                         } psi;
     134         [ +  + ]:          6 :                         if (umove_or_printaddr(tcp, addr, &psi)) {
     135                 :          2 :                                 tprints(", ");
     136                 :          2 :                                 printaddr(data);
     137                 :          2 :                                 return RVAL_DECODED;
     138                 :            :                         }
     139                 :          4 :                         tprintf("{off=%" PRIu64 ", flags=", psi.off);
     140                 :          4 :                         printflags(ptrace_peeksiginfo_flags, psi.flags,
     141                 :            :                                    "PTRACE_PEEKSIGINFO_???");
     142                 :          4 :                         tprintf(", nr=%u}", psi.nr);
     143                 :          4 :                         break;
     144                 :            :                 }
     145                 :            :                 default:
     146                 :         48 :                         tprints(", ");
     147                 :         48 :                         printaddr(addr);
     148                 :            :                 }
     149                 :            : 
     150                 :            : # if defined IA64 || defined SPARC || defined SPARC64
     151                 :            :                 switch (request) {
     152                 :            : #  ifdef IA64
     153                 :            :                 case PTRACE_PEEKDATA:
     154                 :            :                 case PTRACE_PEEKTEXT:
     155                 :            :                 case PTRACE_PEEKUSER:
     156                 :            :                         /* data is ignored */
     157                 :            :                         return RVAL_DECODED | RVAL_HEX;
     158                 :            : #  endif /* IA64 */
     159                 :            : #  if defined SPARC || defined SPARC64
     160                 :            :                 case PTRACE_GETREGS:
     161                 :            :                 case PTRACE_SETREGS:
     162                 :            :                 case PTRACE_GETFPREGS:
     163                 :            :                 case PTRACE_SETFPREGS:
     164                 :            :                         /* data is ignored */
     165                 :            :                         return RVAL_DECODED;
     166                 :            : #  endif /* SPARC || SPARC64 */
     167                 :            :                 }
     168                 :            : # endif /* IA64 || SPARC || SPARC64 */
     169                 :            : 
     170                 :         66 :                 tprints(", ");
     171                 :            : 
     172                 :            :                 /* data */
     173   [ +  +  +  +  :         66 :                 switch (request) {
                +  +  + ]
     174                 :            :                 case PTRACE_CONT:
     175                 :            :                 case PTRACE_DETACH:
     176                 :            :                 case PTRACE_SYSCALL:
     177                 :            : #ifdef PTRACE_SINGLESTEP
     178                 :            :                 case PTRACE_SINGLESTEP:
     179                 :            : #endif
     180                 :            : #ifdef PTRACE_SINGLEBLOCK
     181                 :            :                 case PTRACE_SINGLEBLOCK:
     182                 :            : #endif
     183                 :            : #ifdef PTRACE_SYSEMU
     184                 :            :                 case PTRACE_SYSEMU:
     185                 :            : #endif
     186                 :            : #ifdef PTRACE_SYSEMU_SINGLESTEP
     187                 :            :                 case PTRACE_SYSEMU_SINGLESTEP:
     188                 :            : #endif
     189                 :         16 :                         printsignal(data);
     190                 :         16 :                         break;
     191                 :            :                 case PTRACE_SEIZE:
     192                 :            :                 case PTRACE_SETOPTIONS:
     193                 :            : #ifdef PTRACE_OLDSETOPTIONS
     194                 :            :                 case PTRACE_OLDSETOPTIONS:
     195                 :            : #endif
     196                 :            :                         printflags64(ptrace_setoptions_flags, data, "PTRACE_O_???");
     197                 :            :                         break;
     198                 :            :                 case PTRACE_SETSIGINFO:
     199                 :         18 :                         printsiginfo_at(tcp, data);
     200                 :         18 :                         break;
     201                 :            :                 case PTRACE_SETSIGMASK:
     202                 :          2 :                         print_sigset_addr_len(tcp, data, addr);
     203                 :          2 :                         break;
     204                 :            :                 case PTRACE_SETREGSET:
     205                 :            :                         tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
     206                 :            :                         break;
     207                 :            : #ifndef IA64
     208                 :            :                 case PTRACE_PEEKDATA:
     209                 :            :                 case PTRACE_PEEKTEXT:
     210                 :            :                 case PTRACE_PEEKUSER:
     211                 :            : #endif
     212                 :            :                 case PTRACE_GETEVENTMSG:
     213                 :            :                 case PTRACE_GETREGSET:
     214                 :            :                 case PTRACE_GETSIGINFO:
     215                 :            :                 case PTRACE_GETSIGMASK:
     216                 :            :                 case PTRACE_PEEKSIGINFO:
     217                 :            :                 case PTRACE_SECCOMP_GET_FILTER:
     218         [ -  + ]:         20 :                         if (verbose(tcp)) {
     219                 :            :                                 /* print data on exiting syscall */
     220                 :            :                                 return 0;
     221                 :            :                         }
     222                 :            :                         /* fall through */
     223                 :            :                 default:
     224                 :          4 :                         printaddr(data);
     225                 :          4 :                         break;
     226                 :            :                 }
     227                 :            : 
     228                 :            :                 return RVAL_DECODED;
     229                 :            :         } else {
     230   [ +  +  +  +  :         20 :                 switch (request) {
             +  +  +  - ]
     231                 :            : #ifndef IA64
     232                 :            :                 case PTRACE_PEEKDATA:
     233                 :            :                 case PTRACE_PEEKTEXT:
     234                 :            :                 case PTRACE_PEEKUSER:
     235                 :          6 :                         printnum_ptr(tcp, data);
     236                 :          6 :                         break;
     237                 :            : #endif
     238                 :            :                 case PTRACE_GETEVENTMSG:
     239                 :          2 :                         printnum_ulong(tcp, data);
     240                 :          2 :                         break;
     241                 :            :                 case PTRACE_GETREGSET:
     242                 :            :                         tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
     243                 :            :                         break;
     244                 :            :                 case PTRACE_GETSIGINFO:
     245                 :          2 :                         printsiginfo_at(tcp, data);
     246                 :          2 :                         break;
     247                 :            :                 case PTRACE_GETSIGMASK:
     248                 :          2 :                         print_sigset_addr_len(tcp, data, addr);
     249                 :          2 :                         break;
     250                 :            :                 case PTRACE_PEEKSIGINFO:
     251                 :          4 :                         print_siginfo_array(tcp, data, tcp->u_rval);
     252                 :          4 :                         break;
     253                 :            :                 case PTRACE_SECCOMP_GET_FILTER:
     254                 :          2 :                         print_seccomp_fprog(tcp, data, tcp->u_rval);
     255                 :          2 :                         break;
     256                 :            :                 }
     257                 :            :         }
     258                 :            :         return 0;
     259                 :            : }

Generated by: LCOV version 1.11