LCOV - code coverage report
Current view: top level - libdw - dwarf_end.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 66 66 100.0 %
Date: 2024-09-05 13:12:15 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 40 40 100.0 %

           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                 :      24056 : dwarf_package_index_free (Dwarf_Package_Index *index)
      45                 :            : {
      46         [ +  + ]:      24056 :   if (index != NULL)
      47                 :            :     {
      48                 :         52 :       free (index->debug_info_offsets);
      49                 :         52 :       free (index);
      50                 :            :     }
      51                 :      24056 : }
      52                 :            : 
      53                 :            : 
      54                 :            : static void
      55                 :    1229586 : noop_free (void *arg __attribute__ ((unused)))
      56                 :            : {
      57                 :    1229586 : }
      58                 :            : 
      59                 :            : 
      60                 :            : static void
      61                 :      82432 : cu_free (void *arg)
      62                 :            : {
      63                 :      82432 :   struct Dwarf_CU *p = (struct Dwarf_CU *) arg;
      64                 :      82432 :   eu_search_tree_fini (&p->locs_tree, noop_free);
      65                 :            : 
      66                 :            :   /* Only free the CU internals if its not a fake CU.  */
      67   [ +  +  +  + ]:      82432 :   if (p != p->dbg->fake_loc_cu && p != p->dbg->fake_loclists_cu
      68         [ +  + ]:      71702 :      && p != p->dbg->fake_addr_cu)
      69                 :            :     {
      70                 :      71570 :       Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
      71                 :      71570 :       rwlock_fini (p->abbrev_lock);
      72                 :      71570 :       rwlock_fini (p->split_lock);
      73                 :            : 
      74                 :            :       /* Free split dwarf one way (from skeleton to split).  */
      75         [ +  + ]:      71570 :       if (p->unit_type == DW_UT_skeleton
      76   [ +  +  +  + ]:        244 :           && p->split != NULL && p->split != (void *)-1)
      77                 :            :         {
      78                 :            :           /* The fake_addr_cu might be shared, only release one.  */
      79         [ +  + ]:        170 :           if (p->dbg->fake_addr_cu == p->split->dbg->fake_addr_cu)
      80                 :        126 :             p->split->dbg->fake_addr_cu = NULL;
      81                 :            :           /* There is only one DWP file. We free it later.  */
      82         [ +  + ]:        170 :           if (p->split->dbg != p->dbg->dwp_dwarf)
      83                 :        104 :             INTUSE(dwarf_end) (p->split->dbg);
      84                 :            :         }
      85                 :            :     }
      86                 :      82432 : }
      87                 :            : 
      88                 :            : 
      89                 :            : int
      90                 :      12048 : dwarf_end (Dwarf *dwarf)
      91                 :            : {
      92         [ +  + ]:      12048 :   if (dwarf != NULL)
      93                 :            :     {
      94                 :      12028 :       dwarf_package_index_free (dwarf->tu_index);
      95                 :      12028 :       dwarf_package_index_free (dwarf->cu_index);
      96                 :            : 
      97         [ +  + ]:      12028 :       if (dwarf->cfi != NULL)
      98                 :            :         /* Clean up the CFI cache.  */
      99                 :         36 :         __libdw_destroy_frame_cache (dwarf->cfi);
     100                 :            : 
     101                 :      12028 :       Dwarf_Sig8_Hash_free (&dwarf->sig8_hash);
     102                 :            : 
     103                 :            :       /* The search tree for the CUs.  NB: the CU data itself is
     104                 :            :          allocated separately, but the abbreviation hash tables need
     105                 :            :          to be handled.  */
     106                 :      12028 :       eu_search_tree_fini (&dwarf->cu_tree, cu_free);
     107                 :      12028 :       eu_search_tree_fini (&dwarf->tu_tree, cu_free);
     108                 :            : 
     109                 :            :       /* Search tree for macro opcode tables.  */
     110                 :      12028 :       eu_search_tree_fini (&dwarf->macro_ops_tree, noop_free);
     111                 :            : 
     112                 :            :       /* Search tree for decoded .debug_lines units.  */
     113                 :      12028 :       eu_search_tree_fini (&dwarf->files_lines_tree, noop_free);
     114                 :            : 
     115                 :            :       /* And the split Dwarf.  */
     116                 :      12028 :       eu_search_tree_fini (&dwarf->split_tree, noop_free);
     117                 :            : 
     118                 :            :       /* Free the internally allocated memory.  */
     119         [ +  + ]:      14049 :       for (size_t i = 0; i < dwarf->mem_stacks; i++)
     120                 :            :         {
     121                 :       2021 :           struct libdw_memblock *memp = dwarf->mem_tails[i];
     122         [ +  + ]:      53869 :           while (memp != NULL)
     123                 :            :             {
     124                 :      51848 :               struct libdw_memblock *prevp = memp->prev;
     125                 :      51848 :               free (memp);
     126                 :      51848 :               memp = prevp;
     127                 :            :             }
     128                 :            :         }
     129         [ +  + ]:      12028 :       if (dwarf->mem_tails != NULL)
     130                 :       1730 :         free (dwarf->mem_tails);
     131                 :      12028 :       pthread_rwlock_destroy (&dwarf->mem_rwl);
     132                 :      12028 :       rwlock_fini (dwarf->dwarf_lock);
     133                 :            : 
     134                 :            :       /* Free the pubnames helper structure.  */
     135                 :      12028 :       free (dwarf->pubnames_sets);
     136                 :            : 
     137                 :            :       /* Free the ELF descriptor if necessary.  */
     138         [ +  + ]:      12028 :       if (dwarf->free_elf)
     139                 :        682 :         elf_end (dwarf->elf);
     140                 :            : 
     141                 :            :       /* Free the fake location list CU.  */
     142         [ +  + ]:      12028 :       if (dwarf->fake_loc_cu != NULL)
     143                 :            :         {
     144                 :        324 :           cu_free (dwarf->fake_loc_cu);
     145                 :        324 :           free (dwarf->fake_loc_cu);
     146                 :            :         }
     147         [ +  + ]:      12028 :       if (dwarf->fake_loclists_cu != NULL)
     148                 :            :         {
     149                 :      10406 :           cu_free (dwarf->fake_loclists_cu);
     150                 :      10406 :           free (dwarf->fake_loclists_cu);
     151                 :            :         }
     152         [ +  + ]:      12028 :       if (dwarf->fake_addr_cu != NULL)
     153                 :            :         {
     154                 :        132 :           cu_free (dwarf->fake_addr_cu);
     155                 :        132 :           free (dwarf->fake_addr_cu);
     156                 :            :         }
     157                 :            : 
     158                 :            :       /* Did we find and allocate the alt Dwarf ourselves?  */
     159         [ +  + ]:      12028 :       if (dwarf->alt_fd != -1)
     160                 :            :         {
     161                 :          4 :           INTUSE(dwarf_end) (dwarf->alt_dwarf);
     162                 :          4 :           close (dwarf->alt_fd);
     163                 :            :         }
     164                 :            : 
     165         [ +  + ]:      12028 :       if (dwarf->dwp_fd != -1)
     166                 :            :         {
     167                 :         22 :           INTUSE(dwarf_end) (dwarf->dwp_dwarf);
     168                 :         22 :           close (dwarf->dwp_fd);
     169                 :            :         }
     170                 :            : 
     171                 :            :       /* The cached path and dir we found the Dwarf ELF file in.  */
     172                 :      12028 :       free (dwarf->elfpath);
     173                 :      12028 :       free (dwarf->debugdir);
     174                 :            : 
     175                 :            :       /* Free the context descriptor.  */
     176                 :      12028 :       free (dwarf);
     177                 :            :     }
     178                 :            : 
     179                 :      12048 :   return 0;
     180                 :            : }
     181                 :            : INTDEF(dwarf_end)

Generated by: LCOV version 1.16