LCOV - code coverage report
Current view: top level - elfutils/libdw - dwarf_getattrs.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 24 27 88.9 %
Date: 2013-03-08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 26 65.4 %

           Branch data     Line data    Source code
       1                 :            : /* Get attributes of the DIE.
       2                 :            :    Copyright (C) 2004, 2005, 2008, 2009 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
       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                 :            : 
      36                 :            : 
      37                 :            : ptrdiff_t
      38                 :     721679 : dwarf_getattrs (Dwarf_Die *die, int (*callback) (Dwarf_Attribute *, void *),
      39                 :            :                 void *arg, ptrdiff_t offset)
      40                 :            : {
      41         [ +  - ]:     721679 :   if (die == NULL)
      42                 :            :     return -1l;
      43                 :            : 
      44         [ +  - ]:     721679 :   if (unlikely (offset == 1))
      45                 :            :     return 1;
      46                 :            : 
      47                 :     721679 :   const unsigned char *die_addr = die->addr;
      48                 :            : 
      49                 :            :   /* Get the abbreviation code.  */
      50                 :            :   unsigned int u128;
      51         [ +  + ]:     721679 :   get_uleb128 (u128, die_addr);
      52                 :            : 
      53         [ -  + ]:     721679 :   if (die->abbrev == NULL)
      54                 :            :     /* Find the abbreviation.  */
      55                 :          0 :     die->abbrev = __libdw_findabbrev (die->cu, u128);
      56                 :            : 
      57         [ -  + ]:     721679 :   if (unlikely (die->abbrev == DWARF_END_ABBREV))
      58                 :            :     {
      59                 :            :     invalid_dwarf:
      60                 :          0 :       __libdw_seterrno (DWARF_E_INVALID_DWARF);
      61                 :            :       return -1l;
      62                 :            :     }
      63                 :            : 
      64                 :            :   /* This is where the attributes start.  */
      65                 :     721679 :   const unsigned char *attrp = die->abbrev->attrp;
      66                 :     721679 :   const unsigned char *const offset_attrp = die->abbrev->attrp + offset;
      67                 :            : 
      68                 :            :   /* Go over the list of attributes.  */
      69                 :     721679 :   Dwarf *dbg = die->cu->dbg;
      70                 :            :   while (1)
      71                 :            :     {
      72                 :            :       /* Are we still in bounds?  */
      73         [ +  - ]:    3269564 :       if (unlikely (attrp
      74                 :            :                     >= ((unsigned char *) dbg->sectiondata[IDX_debug_abbrev]->d_buf
      75                 :            :                         + dbg->sectiondata[IDX_debug_abbrev]->d_size)))
      76                 :            :         goto invalid_dwarf;
      77                 :            : 
      78                 :            :       /* Get attribute name and form.  */
      79                 :            :       Dwarf_Attribute attr;
      80                 :    3269564 :       const unsigned char *remembered_attrp = attrp;
      81                 :            : 
      82                 :            :       // XXX Fix bound checks
      83         [ +  + ]:    3269564 :       get_uleb128 (attr.code, attrp);
      84         [ +  + ]:    3269564 :       get_uleb128 (attr.form, attrp);
      85                 :            : 
      86                 :            :       /* We can stop if we found the attribute with value zero.  */
      87         [ +  + ]:    3269564 :       if (attr.code == 0 && attr.form == 0)
      88                 :            :         /* Do not return 0 here - there would be no way to
      89                 :            :            distinguish this value from the attribute at offset 0.
      90                 :            :            Instead we return +1 which would never be a valid
      91                 :            :            offset of an attribute.  */
      92                 :            :         return 1l;
      93                 :            : 
      94                 :            :       /* If we are not to OFFSET_ATTRP yet, we just have to skip
      95                 :            :          the values of the intervening attributes.  */
      96         [ +  - ]:    2547885 :       if (remembered_attrp >= offset_attrp)
      97                 :            :         {
      98                 :            :           /* Fill in the rest.  */
      99                 :    2547885 :           attr.valp = (unsigned char *) die_addr;
     100                 :    2547885 :           attr.cu = die->cu;
     101                 :            : 
     102                 :            :           /* Now call the callback function.  */
     103         [ -  + ]:    2547885 :           if (callback (&attr, arg) != DWARF_CB_OK)
     104                 :            :             /* Return the offset of the start of the attribute, so that
     105                 :            :                dwarf_getattrs() can be restarted from this point if the
     106                 :            :                caller so desires.  */
     107                 :          0 :             return remembered_attrp - die->abbrev->attrp;
     108                 :            :         }
     109                 :            : 
     110                 :            :       /* Skip over the rest of this attribute (if there is any).  */
     111         [ +  - ]:    2547885 :       if (attr.form != 0)
     112                 :            :         {
     113                 :    2547885 :           size_t len = __libdw_form_val_len (dbg, die->cu, attr.form,
     114                 :            :                                              die_addr);
     115                 :            : 
     116         [ +  - ]:    2547885 :           if (unlikely (len == (size_t) -1l))
     117                 :            :             /* Something wrong with the file.  */
     118                 :            :             return -1l;
     119                 :            : 
     120                 :            :           // XXX We need better boundary checks.
     121                 :    2547885 :           die_addr += len;
     122                 :            :         }
     123                 :    3269564 :     }
     124                 :            :   /* NOTREACHED */
     125                 :            : }

Generated by: LCOV version 1.9