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