blob: 647a1b8d1c749954292e6578540da98233de06fd [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Release debugging handling context.
Mark Wielaarddf85bf92014-05-01 14:48:27 +02002 Copyright (C) 2002-2011, 2014 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
5
Mark Wielaardde2ed972012-06-05 17:15:16 +02006 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Mark Wielaardde2ed972012-06-05 17:15:16 +02009 * 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
Ulrich Drepper361df7d2006-04-04 21:38:57 +000022 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
Mark Wielaardde2ed972012-06-05 17:15:16 +020026 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/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000029
30#ifdef HAVE_CONFIG_H
31# include <config.h>
32#endif
33
34#include <search.h>
35#include <stdlib.h>
Roland McGrath725aad52011-02-23 19:52:46 -080036#include <assert.h>
37#include <string.h>
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000038
39#include "libdwP.h"
Roland McGrath3c84db32009-06-24 17:41:40 -070040#include "cfi.h"
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000041
42
43static void
44noop_free (void *arg __attribute__ ((unused)))
45{
46}
47
48
49static void
50cu_free (void *arg)
51{
52 struct Dwarf_CU *p = (struct Dwarf_CU *) arg;
53
54 Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
55
56 tdestroy (p->locs, noop_free);
57}
58
59
Roland McGrath725aad52011-02-23 19:52:46 -080060#if USE_ZLIB
61void
62internal_function
63__libdw_free_zdata (Dwarf *dwarf)
64{
65 unsigned int gzip_mask = dwarf->sectiondata_gzip_mask;
66 while (gzip_mask != 0)
67 {
68 int i = ffs (gzip_mask);
69 assert (i > 0);
70 --i;
71 assert (i < IDX_last);
72 free (dwarf->sectiondata[i]);
73 gzip_mask &= ~(1U << i);
74 }
75}
76#endif
77
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000078int
79dwarf_end (dwarf)
80 Dwarf *dwarf;
81{
82 if (dwarf != NULL)
83 {
Roland McGrath3c84db32009-06-24 17:41:40 -070084 if (dwarf->cfi != NULL)
85 /* Clean up the CFI cache. */
86 __libdw_destroy_frame_cache (dwarf->cfi);
87
Roland McGrath3e0f7d12010-06-15 23:10:35 -070088 Dwarf_Sig8_Hash_free (&dwarf->sig8_hash);
89
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000090 /* 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 tdestroy (dwarf->cu_tree, cu_free);
Roland McGrath2b1f0952010-06-20 17:55:50 -070094 tdestroy (dwarf->tu_tree, cu_free);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000095
Petr Machatafb90bf32014-10-17 02:47:03 +020096 /* Search tree for macro opcode tables. */
97 tdestroy (dwarf->macro_ops, noop_free);
98
99 /* Search tree for decoded .debug_lines units. */
100 tdestroy (dwarf->files_lines, noop_free);
101
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000102 struct libdw_memblock *memp = dwarf->mem_tail;
103 /* The first block is allocated together with the Dwarf object. */
104 while (memp->prev != NULL)
105 {
106 struct libdw_memblock *prevp = memp->prev;
107 free (memp);
108 memp = prevp;
109 }
110
111 /* Free the pubnames helper structure. */
112 free (dwarf->pubnames_sets);
113
Roland McGrath725aad52011-02-23 19:52:46 -0800114 __libdw_free_zdata (dwarf);
115
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000116 /* Free the ELF descriptor if necessary. */
117 if (dwarf->free_elf)
118 elf_end (dwarf->elf);
119
120 /* Free the context descriptor. */
121 free (dwarf);
122 }
123
124 return 0;
125}
Roland McGrath4959bf82005-08-09 10:31:08 +0000126INTDEF(dwarf_end)