Line data Source code
1 : /* Release debugging handling context.
2 : Copyright (C) 2002-2011, 2014 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 5134 : noop_free (void *arg __attribute__ ((unused)))
45 : {
46 5134 : }
47 :
48 :
49 : static void
50 10331 : cu_free (void *arg)
51 : {
52 15464 : struct Dwarf_CU *p = (struct Dwarf_CU *) arg;
53 :
54 15464 : Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
55 :
56 15464 : tdestroy (p->locs, noop_free);
57 10331 : }
58 :
59 :
60 : int
61 5294 : dwarf_end (Dwarf *dwarf)
62 : {
63 5294 : if (dwarf != NULL)
64 : {
65 5289 : if (dwarf->cfi != NULL)
66 : /* Clean up the CFI cache. */
67 9 : __libdw_destroy_frame_cache (dwarf->cfi);
68 :
69 5289 : Dwarf_Sig8_Hash_free (&dwarf->sig8_hash);
70 :
71 : /* The search tree for the CUs. NB: the CU data itself is
72 : allocated separately, but the abbreviation hash tables need
73 : to be handled. */
74 5289 : tdestroy (dwarf->cu_tree, cu_free);
75 5289 : tdestroy (dwarf->tu_tree, cu_free);
76 :
77 : /* Search tree for macro opcode tables. */
78 5289 : tdestroy (dwarf->macro_ops, noop_free);
79 :
80 : /* Search tree for decoded .debug_lines units. */
81 5289 : tdestroy (dwarf->files_lines, noop_free);
82 :
83 5289 : struct libdw_memblock *memp = dwarf->mem_tail;
84 : /* The first block is allocated together with the Dwarf object. */
85 15935 : while (memp->prev != NULL)
86 : {
87 5357 : struct libdw_memblock *prevp = memp->prev;
88 5357 : free (memp);
89 5357 : memp = prevp;
90 : }
91 :
92 : /* Free the pubnames helper structure. */
93 5289 : free (dwarf->pubnames_sets);
94 :
95 : /* Free the ELF descriptor if necessary. */
96 5289 : if (dwarf->free_elf)
97 46 : elf_end (dwarf->elf);
98 :
99 : /* Free the fake location list CU. */
100 5289 : if (dwarf->fake_loc_cu != NULL)
101 : {
102 10266 : cu_free (dwarf->fake_loc_cu);
103 5133 : free (dwarf->fake_loc_cu);
104 : }
105 :
106 : /* Free the context descriptor. */
107 5289 : free (dwarf);
108 : }
109 :
110 5294 : return 0;
111 : }
112 : INTDEF(dwarf_end)
|