LCOV - code coverage report
Current view: top level - elfutils/libdw - libdw_form.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 31 41 75.6 %
Date: 2013-03-08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 32 56.2 %

           Branch data     Line data    Source code
       1                 :            : /* Helper functions for form handling.
       2                 :            :    Copyright (C) 2003-2009 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 <dwarf.h>
      35                 :            : #include <string.h>
      36                 :            : 
      37                 :            : #include "libdwP.h"
      38                 :            : 
      39                 :            : 
      40                 :            : size_t
      41                 :            : internal_function
      42                 :   61839265 : __libdw_form_val_len (Dwarf *dbg, struct Dwarf_CU *cu, unsigned int form,
      43                 :            :                       const unsigned char *valp)
      44                 :            : {
      45                 :            :   const unsigned char *saved;
      46                 :            :   Dwarf_Word u128;
      47                 :            :   size_t result;
      48                 :            : 
      49   [ +  +  +  +  :   61839265 :   switch (form)
          +  -  +  +  +  
          +  +  +  +  -  
                   -  + ]
      50                 :            :     {
      51                 :            :     case DW_FORM_addr:
      52                 :    2064636 :       result = cu->address_size;
      53                 :    2064636 :       break;
      54                 :            : 
      55                 :            :     case DW_FORM_ref_addr:
      56         [ -  + ]:       7190 :       result = cu->version == 2 ? cu->address_size : cu->offset_size;
      57                 :       7190 :       break;
      58                 :            : 
      59                 :            :     case DW_FORM_strp:
      60                 :            :     case DW_FORM_sec_offset:
      61                 :            :     case DW_FORM_GNU_ref_alt:
      62                 :            :     case DW_FORM_GNU_strp_alt:
      63                 :    3284705 :       result = cu->offset_size;
      64                 :    3284705 :       break;
      65                 :            : 
      66                 :            :     case DW_FORM_block1:
      67                 :    2622039 :       result = *valp + 1;
      68                 :    2622039 :       break;
      69                 :            : 
      70                 :            :     case DW_FORM_block2:
      71 [ -  + ][ #  # ]:          2 :       result = read_2ubyte_unaligned (dbg, valp) + 2;
      72                 :          2 :       break;
      73                 :            : 
      74                 :            :     case DW_FORM_block4:
      75         [ #  # ]:          0 :       result = read_4ubyte_unaligned (dbg, valp) + 4;
      76                 :          0 :       break;
      77                 :            : 
      78                 :            :     case DW_FORM_block:
      79                 :            :     case DW_FORM_exprloc:
      80                 :     294268 :       saved = valp;
      81         [ -  + ]:     294268 :       get_uleb128 (u128, valp);
      82                 :     294268 :       result = u128 + (valp - saved);
      83                 :     294268 :       break;
      84                 :            : 
      85                 :            :     case DW_FORM_flag_present:
      86                 :            :       result = 0;
      87                 :            :       break;
      88                 :            : 
      89                 :            :     case DW_FORM_ref1:
      90                 :            :     case DW_FORM_data1:
      91                 :            :     case DW_FORM_flag:
      92                 :   26698539 :       result = 1;
      93                 :   26698539 :       break;
      94                 :            : 
      95                 :            :     case DW_FORM_data2:
      96                 :            :     case DW_FORM_ref2:
      97                 :    1139469 :       result = 2;
      98                 :    1139469 :       break;
      99                 :            : 
     100                 :            :     case DW_FORM_data4:
     101                 :            :     case DW_FORM_ref4:
     102                 :   13935353 :       result = 4;
     103                 :   13935353 :       break;
     104                 :            : 
     105                 :            :     case DW_FORM_data8:
     106                 :            :     case DW_FORM_ref8:
     107                 :            :     case DW_FORM_ref_sig8:
     108                 :          4 :       result = 8;
     109                 :          4 :       break;
     110                 :            : 
     111                 :            :     case DW_FORM_string:
     112                 :   10017469 :       result = strlen ((char *) valp) + 1;
     113                 :   10017469 :       break;
     114                 :            : 
     115                 :            :     case DW_FORM_sdata:
     116                 :            :     case DW_FORM_udata:
     117                 :            :     case DW_FORM_ref_udata:
     118                 :     247251 :       saved = valp;
     119         [ +  + ]:     247251 :       get_uleb128 (u128, valp);
     120                 :     247251 :       result = valp - saved;
     121                 :     247251 :       break;
     122                 :            : 
     123                 :            :     case DW_FORM_indirect:
     124                 :          0 :       saved = valp;
     125         [ #  # ]:          0 :       get_uleb128 (u128, valp);
     126                 :            :       // XXX Is this really correct?
     127                 :          0 :       result = __libdw_form_val_len (dbg, cu, u128, valp);
     128         [ #  # ]:          0 :       if (result != (size_t) -1)
     129                 :          0 :         result += valp - saved;
     130                 :            :       break;
     131                 :            : 
     132                 :            :     default:
     133                 :          0 :       __libdw_seterrno (DWARF_E_INVALID_DWARF);
     134                 :          0 :       result = (size_t) -1l;
     135                 :          0 :       break;
     136                 :            :     }
     137                 :            : 
     138                 :   61839265 :   return result;
     139                 :            : }

Generated by: LCOV version 1.9