LCOV - code coverage report
Current view: top level - elfutils/libdw - dwarf_end.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 30 37 81.1 %
Date: 2012-10-31 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 16 56.2 %

           Branch data     Line data    Source code
       1                 :            : /* Release debugging handling context.
       2                 :            :    Copyright (C) 2002-2011 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
       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 <search.h>
      35                 :            : #include <stdlib.h>
      36                 :            : #include <assert.h>
      37                 :            : #include <string.h>
      38                 :            : 
      39                 :            : #include "libdwP.h"
      40                 :            : #include "cfi.h"
      41                 :            : 
      42                 :            : 
      43                 :            : static void
      44                 :       7080 : noop_free (void *arg __attribute__ ((unused)))
      45                 :            : {
      46                 :       7080 : }
      47                 :            : 
      48                 :            : 
      49                 :            : static void
      50                 :      19130 : cu_free (void *arg)
      51                 :            : {
      52                 :      19130 :   struct Dwarf_CU *p = (struct Dwarf_CU *) arg;
      53                 :            : 
      54                 :      19130 :   Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
      55                 :            : 
      56                 :      19130 :   tdestroy (p->locs, noop_free);
      57                 :      19130 : }
      58                 :            : 
      59                 :            : 
      60                 :            : #if USE_ZLIB
      61                 :            : void
      62                 :            : internal_function
      63                 :       5441 : __libdw_free_zdata (Dwarf *dwarf)
      64                 :            : {
      65                 :       5441 :   unsigned int gzip_mask = dwarf->sectiondata_gzip_mask;
      66         [ -  + ]:       5441 :   while (gzip_mask != 0)
      67                 :            :     {
      68                 :          0 :       int i = ffs (gzip_mask);
      69         [ #  # ]:          0 :       assert (i > 0);
      70                 :          0 :       --i;
      71         [ #  # ]:          0 :       assert (i < IDX_last);
      72                 :          0 :       free (dwarf->sectiondata[i]);
      73                 :          0 :       gzip_mask &= ~(1U << i);
      74                 :            :     }
      75                 :       5441 : }
      76                 :            : #endif
      77                 :            : 
      78                 :            : int
      79                 :       5385 : dwarf_end (dwarf)
      80                 :            :      Dwarf *dwarf;
      81                 :            : {
      82         [ +  - ]:       5385 :   if (dwarf != NULL)
      83                 :            :     {
      84         [ -  + ]:       5385 :       if (dwarf->cfi != NULL)
      85                 :            :         /* Clean up the CFI cache.  */
      86                 :          0 :         __libdw_destroy_frame_cache (dwarf->cfi);
      87                 :            : 
      88                 :       5385 :       Dwarf_Sig8_Hash_free (&dwarf->sig8_hash);
      89                 :            : 
      90                 :            :       /* The search tree for the CUs.  NB: the CU data itself is
      91                 :            :          allocated separately, but the abbreviation hash tables need
      92                 :            :          to be handled.  */
      93                 :       5385 :       tdestroy (dwarf->cu_tree, cu_free);
      94                 :       5385 :       tdestroy (dwarf->tu_tree, cu_free);
      95                 :            : 
      96                 :       5385 :       struct libdw_memblock *memp = dwarf->mem_tail;
      97                 :            :       /* The first block is allocated together with the Dwarf object.  */
      98         [ +  + ]:      17632 :       while (memp->prev != NULL)
      99                 :            :         {
     100                 :      12247 :           struct libdw_memblock *prevp = memp->prev;
     101                 :      12247 :           free (memp);
     102                 :      12247 :           memp = prevp;
     103                 :            :         }
     104                 :            : 
     105                 :            :       /* Free the pubnames helper structure.  */
     106                 :       5385 :       free (dwarf->pubnames_sets);
     107                 :            : 
     108                 :       5385 :       __libdw_free_zdata (dwarf);
     109                 :            : 
     110                 :            :       /* Free the ELF descriptor if necessary.  */
     111         [ +  + ]:       5385 :       if (dwarf->free_elf)
     112                 :         18 :         elf_end (dwarf->elf);
     113                 :            : 
     114                 :            :       /* Free the alternative Dwarf descriptor if necessary.  */
     115         [ +  + ]:       5385 :       if (dwarf->free_alt)
     116                 :          2 :         INTUSE (dwarf_end) (dwarf->alt_dwarf);
     117                 :            : 
     118                 :            :       /* Free the context descriptor.  */
     119                 :       5385 :       free (dwarf);
     120                 :            :     }
     121                 :            : 
     122                 :       5385 :   return 0;
     123                 :            : }
     124                 :            : INTDEF(dwarf_end)

Generated by: LCOV version 1.9