LCOV - code coverage report
Current view: top level - elfutils/libdw - dwarf_siblingof.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 34 36 94.4 %
Date: 2012-10-31 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 20 28 71.4 %

           Branch data     Line data    Source code
       1                 :            : /* Return sibling of given DIE.
       2                 :            :    Copyright (C) 2003-2010 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2003.
       5                 :            : 
       6                 :            :    This file is free software; you can redistribute it and/or modify
       7                 :            :    it under the terms of either
       8                 :            : 
       9                 :            :      * the GNU Lesser General Public License as published by the Free
      10                 :            :        Software Foundation; either version 3 of the License, or (at
      11                 :            :        your option) any later version
      12                 :            : 
      13                 :            :    or
      14                 :            : 
      15                 :            :      * the GNU General Public License as published by the Free
      16                 :            :        Software Foundation; either version 2 of the License, or (at
      17                 :            :        your option) any later version
      18                 :            : 
      19                 :            :    or both in parallel, as here.
      20                 :            : 
      21                 :            :    elfutils is distributed in the hope that it will be useful, but
      22                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :    General Public License for more details.
      25                 :            : 
      26                 :            :    You should have received copies of the GNU General Public License and
      27                 :            :    the GNU Lesser General Public License along with this program.  If
      28                 :            :    not, see <http://www.gnu.org/licenses/>.  */
      29                 :            : 
      30                 :            : #ifdef HAVE_CONFIG_H
      31                 :            : # include <config.h>
      32                 :            : #endif
      33                 :            : 
      34                 :            : #include "libdwP.h"
      35                 :            : #include <dwarf.h>
      36                 :            : #include <string.h>
      37                 :            : 
      38                 :            : 
      39                 :            : int
      40                 :    3024408 : dwarf_siblingof (die, result)
      41                 :            :      Dwarf_Die *die;
      42                 :            :      Dwarf_Die *result;
      43                 :            : {
      44                 :            :   /* Ignore previous errors.  */
      45         [ +  - ]:    3024408 :   if (die == NULL)
      46                 :            :     return -1;
      47                 :            : 
      48         [ +  - ]:    3024408 :   if (result == NULL)
      49                 :            :     return -1;
      50                 :            : 
      51         [ -  + ]:    3024408 :   if (result != die)
      52                 :          0 :     result->addr = NULL;
      53                 :            : 
      54                 :    3024408 :   unsigned int level = 0;
      55                 :            : 
      56                 :            :   /* Copy of the current DIE.  */
      57                 :    3024408 :   Dwarf_Die this_die = *die;
      58                 :            :   /* Temporary attributes we create.  */
      59                 :            :   Dwarf_Attribute sibattr;
      60                 :            :   /* Copy of the CU in the request.  */
      61                 :    3024408 :   sibattr.cu = this_die.cu;
      62                 :            :   /* That's the address we start looking.  */
      63                 :    3024408 :   unsigned char *addr = this_die.addr;
      64                 :            :   /* End of the buffer.  */
      65                 :    3024408 :   unsigned char *endp
      66                 :    6048816 :     = ((unsigned char *) cu_data (sibattr.cu)->d_buf + sibattr.cu->end);
      67                 :            : 
      68                 :            :   /* Search for the beginning of the next die on this level.  We
      69                 :            :      must not return the dies for children of the given die.  */
      70                 :            :   do
      71                 :            :     {
      72                 :            :       /* Find the end of the DIE or the sibling attribute.  */
      73                 :    3287767 :       addr = __libdw_find_attr (&this_die, DW_AT_sibling, &sibattr.code,
      74                 :            :                                 &sibattr.form);
      75         [ +  + ]:    3287767 :       if (sibattr.code == DW_AT_sibling)
      76                 :            :         {
      77                 :            :           Dwarf_Off offset;
      78                 :     919615 :           sibattr.valp = addr;
      79         [ -  + ]:     919615 :           if (unlikely (__libdw_formref (&sibattr, &offset) != 0))
      80                 :            :             /* Something went wrong.  */
      81                 :            :             return -1;
      82                 :            : 
      83                 :            :           /* Compute the next address.  */
      84                 :     919615 :           addr = ((unsigned char *) cu_data (sibattr.cu)->d_buf
      85                 :     919615 :                   + sibattr.cu->start + offset);
      86                 :            :         }
      87         [ +  - ]:    2368152 :       else if (unlikely (addr == NULL)
      88         [ +  - ]:    2368152 :                || unlikely (this_die.abbrev == DWARF_END_ABBREV))
      89                 :            :         return -1;
      90         [ +  + ]:    2368152 :       else if (this_die.abbrev->has_children)
      91                 :            :         /* This abbreviation has children.  */
      92                 :    3287767 :         ++level;
      93                 :            : 
      94                 :            : 
      95                 :            :       while (1)
      96                 :            :         {
      97                 :            :           /* Make sure we are still in range.  Some producers might skip
      98                 :            :              the trailing NUL bytes.  */
      99         [ +  + ]:    3315430 :           if (addr >= endp)
     100                 :            :             return 1;
     101                 :            : 
     102         [ +  + ]:    3314079 :           if (*addr != '\0')
     103                 :            :             break;
     104                 :            : 
     105         [ +  + ]:     148811 :           if (level-- == 0)
     106                 :            :             {
     107         [ -  + ]:     121148 :               if (result != die)
     108                 :          0 :                 result->addr = addr;
     109                 :            :               /* No more sibling at all.  */
     110                 :            :               return 1;
     111                 :            :             }
     112                 :            : 
     113                 :      27663 :           ++addr;
     114                 :      27663 :         }
     115                 :            : 
     116                 :            :       /* Initialize the 'current DIE'.  */
     117                 :    3165268 :       this_die.addr = addr;
     118                 :    3165268 :       this_die.abbrev = NULL;
     119                 :            :     }
     120         [ +  + ]:    3165268 :   while (level > 0);
     121                 :            : 
     122                 :            :   /* Maybe we reached the end of the CU.  */
     123         [ +  - ]:    2901909 :   if (addr >= endp)
     124                 :            :     return 1;
     125                 :            : 
     126                 :            :   /* Clear the entire DIE structure.  This signals we have not yet
     127                 :            :      determined any of the information.  */
     128                 :    2901909 :   memset (result, '\0', sizeof (Dwarf_Die));
     129                 :            : 
     130                 :            :   /* We have the address.  */
     131                 :    2901909 :   result->addr = addr;
     132                 :            : 
     133                 :            :   /* Same CU as the parent.  */
     134                 :    3024408 :   result->cu = sibattr.cu;
     135                 :            : 
     136                 :            :   return 0;
     137                 :            : }
     138                 :    3944023 : INTDEF(dwarf_siblingof)

Generated by: LCOV version 1.9