LCOV - code coverage report
Current view: top level - elfutils/libdw - libdw_form.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 29 41 70.7 %
Date: 2012-10-31 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 34 47.1 %

           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                 :   61743143 : __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   [ +  -  +  +  :   61743143 :   switch (form)
          +  -  +  +  +  
          +  +  +  +  -  
                   -  + ]
      50                 :            :     {
      51                 :            :     case DW_FORM_addr:
      52                 :    2064130 :       result = cu->address_size;
      53                 :    2064130 :       break;
      54                 :            : 
      55                 :            :     case DW_FORM_ref_addr:
      56         [ #  # ]:          0 :       result = cu->version == 2 ? cu->address_size : cu->offset_size;
      57                 :          0 :       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                 :    3256036 :       result = cu->offset_size;
      64                 :    3256036 :       break;
      65                 :            : 
      66                 :            :     case DW_FORM_block1:
      67                 :    2621988 :       result = *valp + 1;
      68                 :    2621988 :       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                 :     292111 :       saved = valp;
      81         [ -  + ]:     292111 :       get_uleb128 (u128, valp);
      82                 :     292111 :       result = u128 + (valp - saved);
      83                 :     292111 :       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                 :   26644314 :       result = 1;
      93                 :   26644314 :       break;
      94                 :            : 
      95                 :            :     case DW_FORM_data2:
      96                 :            :     case DW_FORM_ref2:
      97                 :    1152541 :       result = 2;
      98                 :    1152541 :       break;
      99                 :            : 
     100                 :            :     case DW_FORM_data4:
     101                 :            :     case DW_FORM_ref4:
     102                 :   13918271 :       result = 4;
     103                 :   13918271 :       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                 :   10026252 :       result = strlen ((char *) valp) + 1;
     113                 :   10026252 :       break;
     114                 :            : 
     115                 :            :     case DW_FORM_sdata:
     116                 :            :     case DW_FORM_udata:
     117                 :            :     case DW_FORM_ref_udata:
     118                 :     245579 :       saved = valp;
     119         [ +  + ]:     245579 :       get_uleb128 (u128, valp);
     120                 :     245579 :       result = valp - saved;
     121                 :     245579 :       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                 :   61743143 :   return result;
     139                 :            : }

Generated by: LCOV version 1.9