LCOV - code coverage report
Current view: top level - elfutils/libdwfl - dwfl_getmodules.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 19 25 76.0 %
Date: 2012-10-31 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 28 64.3 %

           Branch data     Line data    Source code
       1                 :            : /* Iterate through modules.
       2                 :            :    Copyright (C) 2005, 2008 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            : 
       5                 :            :    This file is free software; you can redistribute it and/or modify
       6                 :            :    it under the terms of either
       7                 :            : 
       8                 :            :      * the GNU Lesser General Public License as published by the Free
       9                 :            :        Software Foundation; either version 3 of the License, or (at
      10                 :            :        your option) any later version
      11                 :            : 
      12                 :            :    or
      13                 :            : 
      14                 :            :      * the GNU General Public License as published by the Free
      15                 :            :        Software Foundation; either version 2 of the License, or (at
      16                 :            :        your option) any later version
      17                 :            : 
      18                 :            :    or both in parallel, as here.
      19                 :            : 
      20                 :            :    elfutils is distributed in the hope that it will be useful, but
      21                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      22                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      23                 :            :    General Public License for more details.
      24                 :            : 
      25                 :            :    You should have received copies of the GNU General Public License and
      26                 :            :    the GNU Lesser General Public License along with this program.  If
      27                 :            :    not, see <http://www.gnu.org/licenses/>.  */
      28                 :            : 
      29                 :            : #include "libdwflP.h"
      30                 :            : 
      31                 :            : ptrdiff_t
      32                 :        183 : dwfl_getmodules (Dwfl *dwfl,
      33                 :            :                  int (*callback) (Dwfl_Module *, void **,
      34                 :            :                                   const char *, Dwarf_Addr, void *),
      35                 :            :                  void *arg,
      36                 :            :                  ptrdiff_t offset)
      37                 :            : {
      38         [ +  - ]:        183 :   if (dwfl == NULL)
      39                 :            :     return -1;
      40                 :            : 
      41                 :            :   /* We iterate through the linked list when it's all we have.
      42                 :            :      But continuing from an offset is slow that way.  So when
      43                 :            :      DWFL->lookup_module is populated, we can instead keep our
      44                 :            :      place by jumping directly into the array.  Since the actions
      45                 :            :      of a callback could cause it to get populated, we must
      46                 :            :      choose the style of place-holder when we return an offset,
      47                 :            :      and we encode the choice in the low bits of that value.  */
      48                 :            : 
      49                 :        183 :   Dwfl_Module *m = dwfl->modulelist;
      50                 :            : 
      51         [ -  + ]:        183 :   if ((offset & 3) == 1)
      52                 :            :     {
      53                 :          0 :       offset >>= 2;
      54         [ #  # ]:          0 :       for (ptrdiff_t pos = 0; pos < offset; ++pos)
      55         [ #  # ]:          0 :         if (m == NULL)
      56                 :            :           return -1;
      57                 :            :         else
      58                 :          0 :           m = m->next;
      59                 :            :     }
      60 [ +  + ][ +  - ]:        183 :   else if (((offset & 3) == 2) && likely (dwfl->lookup_module != NULL))
      61                 :            :     {
      62                 :         12 :       offset >>= 2;
      63                 :            : 
      64         [ +  + ]:         12 :       if ((size_t) offset - 1 == dwfl->lookup_elts)
      65                 :            :         return 0;
      66                 :            : 
      67         [ +  - ]:         10 :       if (unlikely ((size_t) offset - 1 > dwfl->lookup_elts))
      68                 :            :         return -1;
      69                 :            : 
      70                 :         10 :       m = dwfl->lookup_module[offset - 1];
      71         [ +  - ]:         10 :       if (unlikely (m == NULL))
      72                 :            :         return -1;
      73                 :            :     }
      74         [ -  + ]:        171 :   else if (offset != 0)
      75                 :            :     {
      76                 :          0 :       __libdwfl_seterrno (DWFL_E_BADSTROFF);
      77                 :          0 :       return -1;
      78                 :            :     }
      79                 :            : 
      80         [ +  + ]:        364 :   while (m != NULL)
      81                 :            :     {
      82                 :        181 :       int ok = (*callback) (MODCB_ARGS (m), arg);
      83                 :        181 :       ++offset;
      84                 :        181 :       m = m->next;
      85         [ +  + ]:        181 :       if (ok != DWARF_CB_OK)
      86                 :        207 :         return ((dwfl->lookup_module == NULL) ? ((offset << 2) | 1)
      87 [ +  + ][ +  + ]:         26 :                 : (((m == NULL ? (ptrdiff_t) dwfl->lookup_elts + 1
      88                 :         12 :                      : m->segment + 1) << 2) | 2));
      89                 :            :     }
      90                 :            :   return 0;
      91                 :            : }
      92                 :            : INTDEF (dwfl_getmodules)

Generated by: LCOV version 1.9