LCOV - code coverage report
Current view: top level - libdw - dwarf_end.c (source / functions) Hit Total Coverage
Test: elfutils-0.190 Lines: 54 54 100.0 %
Date: 2024-02-15 18:25:58 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 33 34 97.1 %

           Branch data     Line data    Source code
       1                 :            : /* Release debugging handling context.
       2                 :            :    Copyright (C) 2002-2011, 2014, 2018 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                 :    1200096 : noop_free (void *arg __attribute__ ((unused)))
      45                 :            : {
      46                 :    1200096 : }
      47                 :            : 
      48                 :            : 
      49                 :            : static void
      50                 :      89836 : cu_free (void *arg)
      51                 :            : {
      52                 :      89836 :   struct Dwarf_CU *p = (struct Dwarf_CU *) arg;
      53                 :            : 
      54                 :      89836 :   tdestroy (p->locs, noop_free);
      55                 :            : 
      56                 :            :   /* Only free the CU internals if its not a fake CU.  */
      57   [ +  +  +  + ]:      89836 :   if(p != p->dbg->fake_loc_cu && p != p->dbg->fake_loclists_cu
      58         [ +  + ]:      79110 :      && p != p->dbg->fake_addr_cu)
      59                 :            :     {
      60                 :      79026 :       Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
      61                 :            : 
      62                 :            :       /* Free split dwarf one way (from skeleton to split).  */
      63         [ +  + ]:      79026 :       if (p->unit_type == DW_UT_skeleton
      64   [ +  +  +  + ]:        134 :           && p->split != NULL && p->split != (void *)-1)
      65                 :            :         {
      66                 :            :           /* The fake_addr_cu might be shared, only release one.  */
      67         [ +  - ]:         96 :           if (p->dbg->fake_addr_cu == p->split->dbg->fake_addr_cu)
      68                 :         96 :             p->split->dbg->fake_addr_cu = NULL;
      69                 :         96 :           INTUSE(dwarf_end) (p->split->dbg);
      70                 :            :         }
      71                 :            :     }
      72                 :      89836 : }
      73                 :            : 
      74                 :            : 
      75                 :            : int
      76                 :      11666 : dwarf_end (Dwarf *dwarf)
      77                 :            : {
      78         [ +  + ]:      11666 :   if (dwarf != NULL)
      79                 :            :     {
      80                 :      11646 :       free (dwarf->tu_index);
      81                 :      11646 :       free (dwarf->cu_index);
      82                 :            : 
      83         [ +  + ]:      11646 :       if (dwarf->cfi != NULL)
      84                 :            :         /* Clean up the CFI cache.  */
      85                 :         36 :         __libdw_destroy_frame_cache (dwarf->cfi);
      86                 :            : 
      87                 :      11646 :       Dwarf_Sig8_Hash_free (&dwarf->sig8_hash);
      88                 :            : 
      89                 :            :       /* The search tree for the CUs.  NB: the CU data itself is
      90                 :            :          allocated separately, but the abbreviation hash tables need
      91                 :            :          to be handled.  */
      92                 :      11646 :       tdestroy (dwarf->cu_tree, cu_free);
      93                 :      11646 :       tdestroy (dwarf->tu_tree, cu_free);
      94                 :            : 
      95                 :            :       /* Search tree for macro opcode tables.  */
      96                 :      11646 :       tdestroy (dwarf->macro_ops, noop_free);
      97                 :            : 
      98                 :            :       /* Search tree for decoded .debug_lines units.  */
      99                 :      11646 :       tdestroy (dwarf->files_lines, noop_free);
     100                 :            : 
     101                 :            :       /* And the split Dwarf.  */
     102                 :      11646 :       tdestroy (dwarf->split_tree, noop_free);
     103                 :            : 
     104                 :            :       /* Free the internally allocated memory.  */
     105         [ +  + ]:      13349 :       for (size_t i = 0; i < dwarf->mem_stacks; i++)
     106                 :            :         {
     107                 :       1703 :           struct libdw_memblock *memp = dwarf->mem_tails[i];
     108         [ +  + ]:      55129 :           while (memp != NULL)
     109                 :            :             {
     110                 :      53426 :               struct libdw_memblock *prevp = memp->prev;
     111                 :      53426 :               free (memp);
     112                 :      53426 :               memp = prevp;
     113                 :            :             }
     114                 :            :         }
     115         [ +  + ]:      11646 :       if (dwarf->mem_tails != NULL)
     116                 :       1506 :         free (dwarf->mem_tails);
     117                 :      11646 :       pthread_rwlock_destroy (&dwarf->mem_rwl);
     118                 :            : 
     119                 :            :       /* Free the pubnames helper structure.  */
     120                 :      11646 :       free (dwarf->pubnames_sets);
     121                 :            : 
     122                 :            :       /* Free the ELF descriptor if necessary.  */
     123         [ +  + ]:      11646 :       if (dwarf->free_elf)
     124                 :        454 :         elf_end (dwarf->elf);
     125                 :            : 
     126                 :            :       /* Free the fake location list CU.  */
     127         [ +  + ]:      11646 :       if (dwarf->fake_loc_cu != NULL)
     128                 :            :         {
     129                 :        300 :           cu_free (dwarf->fake_loc_cu);
     130                 :        300 :           free (dwarf->fake_loc_cu);
     131                 :            :         }
     132         [ +  + ]:      11646 :       if (dwarf->fake_loclists_cu != NULL)
     133                 :            :         {
     134                 :      10426 :           cu_free (dwarf->fake_loclists_cu);
     135                 :      10426 :           free (dwarf->fake_loclists_cu);
     136                 :            :         }
     137         [ +  + ]:      11646 :       if (dwarf->fake_addr_cu != NULL)
     138                 :            :         {
     139                 :         84 :           cu_free (dwarf->fake_addr_cu);
     140                 :         84 :           free (dwarf->fake_addr_cu);
     141                 :            :         }
     142                 :            : 
     143                 :            :       /* Did we find and allocate the alt Dwarf ourselves?  */
     144         [ +  + ]:      11646 :       if (dwarf->alt_fd != -1)
     145                 :            :         {
     146                 :          4 :           INTUSE(dwarf_end) (dwarf->alt_dwarf);
     147                 :          4 :           close (dwarf->alt_fd);
     148                 :            :         }
     149                 :            : 
     150                 :            :       /* The cached path and dir we found the Dwarf ELF file in.  */
     151                 :      11646 :       free (dwarf->elfpath);
     152                 :      11646 :       free (dwarf->debugdir);
     153                 :            : 
     154                 :            :       /* Free the context descriptor.  */
     155                 :      11646 :       free (dwarf);
     156                 :            :     }
     157                 :            : 
     158                 :      11666 :   return 0;
     159                 :            : }
     160                 :            : INTDEF(dwarf_end)

Generated by: LCOV version 1.16