LCOV - code coverage report
Current view: top level - strace - print_timespec.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 55 56 98.2 %
Date: 2017-07-31 03:46:08 Functions: 13 19 68.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 27 88.9 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
       3                 :            :  * Copyright (c) 2016-2017 The strace developers.
       4                 :            :  * All rights reserved.
       5                 :            :  *
       6                 :            :  * Redistribution and use in source and binary forms, with or without
       7                 :            :  * modification, are permitted provided that the following conditions
       8                 :            :  * are met:
       9                 :            :  * 1. Redistributions of source code must retain the above copyright
      10                 :            :  *    notice, this list of conditions and the following disclaimer.
      11                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      12                 :            :  *    notice, this list of conditions and the following disclaimer in the
      13                 :            :  *    documentation and/or other materials provided with the distribution.
      14                 :            :  * 3. The name of the author may not be used to endorse or promote products
      15                 :            :  *    derived from this software without specific prior written permission.
      16                 :            :  *
      17                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      18                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      19                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      20                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      21                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      22                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      23                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      24                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      26                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include "defs.h"
      30                 :            : 
      31                 :            : #include DEF_MPERS_TYPE(timespec_t)
      32                 :            : 
      33                 :            : typedef struct timespec timespec_t;
      34                 :            : 
      35                 :            : #include MPERS_DEFS
      36                 :            : 
      37                 :            : #ifndef UTIME_NOW
      38                 :            : # define UTIME_NOW ((1l << 30) - 1l)
      39                 :            : #endif
      40                 :            : #ifndef UTIME_OMIT
      41                 :            : # define UTIME_OMIT ((1l << 30) - 2l)
      42                 :            : #endif
      43                 :            : 
      44                 :            : static const char timespec_fmt[] = "{tv_sec=%lld, tv_nsec=%llu}";
      45                 :            : 
      46                 :            : static void
      47                 :            : print_timespec_t(const timespec_t *t)
      48                 :            : {
      49                 :        348 :         tprintf(timespec_fmt, (long long) t->tv_sec,
      50                 :        340 :                 zero_extend_signed_to_ull(t->tv_nsec));
      51                 :            : }
      52                 :            : 
      53                 :            : static void
      54                 :         32 : print_timespec_t_utime(const timespec_t *t)
      55                 :            : {
      56      [ +  +  + ]:         32 :         switch (t->tv_nsec) {
      57                 :            :         case UTIME_NOW:
      58                 :          8 :                 tprints("UTIME_NOW");
      59                 :          8 :                 break;
      60                 :            :         case UTIME_OMIT:
      61                 :          8 :                 tprints("UTIME_OMIT");
      62                 :          8 :                 break;
      63                 :            :         default:
      64                 :            :                 print_timespec_t(t);
      65                 :         16 :                 tprints_comment(sprinttime_nsec(t->tv_sec,
      66                 :         16 :                         zero_extend_signed_to_ull(t->tv_nsec)));
      67                 :         16 :                 break;
      68                 :            :         }
      69                 :         32 : }
      70                 :            : 
      71                 :          8 : MPERS_PRINTER_DECL(bool, print_struct_timespec_data_size,
      72                 :            :                    const void *arg, const size_t size)
      73                 :            : {
      74         [ +  + ]:          8 :         if (size < sizeof(timespec_t)) {
      75                 :          4 :                 tprints("?");
      76                 :          4 :                 return false;
      77                 :            :         }
      78                 :            : 
      79                 :            :         print_timespec_t(arg);
      80                 :          4 :         return true;
      81                 :            : }
      82                 :            : 
      83                 :          8 : MPERS_PRINTER_DECL(bool, print_struct_timespec_array_data_size,
      84                 :            :                    const void *arg, const unsigned int nmemb,
      85                 :            :                    const size_t size)
      86                 :            : {
      87                 :          8 :         const timespec_t *ts = arg;
      88                 :            :         unsigned int i;
      89                 :            : 
      90         [ +  + ]:          8 :         if (nmemb > size / sizeof(timespec_t)) {
      91                 :          4 :                 tprints("?");
      92                 :          4 :                 return false;
      93                 :            :         }
      94                 :            : 
      95                 :          4 :         tprints("[");
      96                 :            : 
      97         [ +  + ]:         16 :         for (i = 0; i < nmemb; i++) {
      98         [ +  + ]:         12 :                 if (i)
      99                 :          8 :                         tprints(", ");
     100                 :         12 :                 print_timespec_t(&ts[i]);
     101                 :            :         }
     102                 :            : 
     103                 :          4 :         tprints("]");
     104                 :          4 :         return true;
     105                 :            : }
     106                 :            : 
     107                 :        352 : MPERS_PRINTER_DECL(void, print_timespec,
     108                 :            :                    struct tcb *const tcp, const kernel_ulong_t addr)
     109                 :            : {
     110                 :            :         timespec_t t;
     111                 :            : 
     112         [ +  + ]:        352 :         if (umove_or_printaddr(tcp, addr, &t))
     113                 :         68 :                 return;
     114                 :            : 
     115                 :            :         print_timespec_t(&t);
     116                 :            : }
     117                 :            : 
     118                 :         34 : MPERS_PRINTER_DECL(const char *, sprint_timespec,
     119                 :            :                    struct tcb *const tcp, const kernel_ulong_t addr)
     120                 :            : {
     121                 :            :         timespec_t t;
     122                 :            :         static char buf[sizeof(timespec_fmt) + 3 * sizeof(t)];
     123                 :            : 
     124         [ +  + ]:         34 :         if (!addr) {
     125                 :          8 :                 strcpy(buf, "NULL");
     126 [ +  - ][ +  + ]:         52 :         } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
           [ +  -  -  + ]
     127                 :         26 :                    umove(tcp, addr, &t)) {
     128                 :          0 :                 snprintf(buf, sizeof(buf), "%#" PRI_klx, addr);
     129                 :            :         } else {
     130                 :         26 :                 snprintf(buf, sizeof(buf), timespec_fmt,
     131                 :         26 :                          (long long) t.tv_sec,
     132                 :         26 :                          zero_extend_signed_to_ull(t.tv_nsec));
     133                 :            :         }
     134                 :            : 
     135                 :         34 :         return buf;
     136                 :            : }
     137                 :            : 
     138                 :         34 : MPERS_PRINTER_DECL(void, print_timespec_utime_pair,
     139                 :            :                    struct tcb *const tcp, const kernel_ulong_t addr)
     140                 :            : {
     141                 :            :         timespec_t t[2];
     142                 :            : 
     143         [ +  + ]:         34 :         if (umove_or_printaddr(tcp, addr, &t))
     144                 :         18 :                 return;
     145                 :            : 
     146                 :         16 :         tprints("[");
     147                 :         16 :         print_timespec_t_utime(&t[0]);
     148                 :         16 :         tprints(", ");
     149                 :         16 :         print_timespec_t_utime(&t[1]);
     150                 :         16 :         tprints("]");
     151                 :            : }
     152                 :            : 
     153                 :         24 : MPERS_PRINTER_DECL(void, print_itimerspec,
     154                 :            :                    struct tcb *const tcp, const kernel_ulong_t addr)
     155                 :            : {
     156                 :            :         timespec_t t[2];
     157                 :            : 
     158         [ +  + ]:         24 :         if (umove_or_printaddr(tcp, addr, &t))
     159                 :          8 :                 return;
     160                 :            : 
     161                 :         16 :         tprints("{it_interval=");
     162                 :            :         print_timespec_t(&t[0]);
     163                 :         16 :         tprints(", it_value=");
     164                 :            :         print_timespec_t(&t[1]);
     165                 :         16 :         tprints("}");
     166                 :            : }

Generated by: LCOV version 1.11