1*5ac3bc71Schristos /* $NetBSD: dwarf_dealloc.c,v 1.5 2024/03/03 17:37:30 christos Exp $ */
2e81373b4Schristos
39dd9d0cfSchristos /*-
49dd9d0cfSchristos * Copyright (c) 2007 John Birrell (jb@freebsd.org)
59dd9d0cfSchristos * All rights reserved.
69dd9d0cfSchristos *
79dd9d0cfSchristos * Redistribution and use in source and binary forms, with or without
89dd9d0cfSchristos * modification, are permitted provided that the following conditions
99dd9d0cfSchristos * are met:
109dd9d0cfSchristos * 1. Redistributions of source code must retain the above copyright
119dd9d0cfSchristos * notice, this list of conditions and the following disclaimer.
129dd9d0cfSchristos * 2. Redistributions in binary form must reproduce the above copyright
139dd9d0cfSchristos * notice, this list of conditions and the following disclaimer in the
149dd9d0cfSchristos * documentation and/or other materials provided with the distribution.
159dd9d0cfSchristos *
169dd9d0cfSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
179dd9d0cfSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189dd9d0cfSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199dd9d0cfSchristos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
209dd9d0cfSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219dd9d0cfSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229dd9d0cfSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239dd9d0cfSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249dd9d0cfSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259dd9d0cfSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269dd9d0cfSchristos * SUCH DAMAGE.
279dd9d0cfSchristos */
289dd9d0cfSchristos
299dd9d0cfSchristos #include "_libdwarf.h"
309dd9d0cfSchristos
31*5ac3bc71Schristos __RCSID("$NetBSD: dwarf_dealloc.c,v 1.5 2024/03/03 17:37:30 christos Exp $");
329dd9d0cfSchristos ELFTC_VCSID("Id: dwarf_dealloc.c 2073 2011-10-27 03:30:47Z jkoshy");
339dd9d0cfSchristos
349dd9d0cfSchristos void
dwarf_dealloc(Dwarf_Debug dbg,Dwarf_Ptr p,Dwarf_Unsigned alloc_type)359dd9d0cfSchristos dwarf_dealloc(Dwarf_Debug dbg, Dwarf_Ptr p, Dwarf_Unsigned alloc_type)
369dd9d0cfSchristos {
379dd9d0cfSchristos Dwarf_Abbrev ab;
389dd9d0cfSchristos Dwarf_AttrDef ad, tad;
399dd9d0cfSchristos Dwarf_Attribute at, tat;
409dd9d0cfSchristos Dwarf_Die die;
419dd9d0cfSchristos
429dd9d0cfSchristos /*
439dd9d0cfSchristos * This libdwarf implementation does not use the SGI/libdwarf
449dd9d0cfSchristos * style of memory allocation. In most cases it does not copy
459dd9d0cfSchristos * things to return to the client, so the client does not need
469dd9d0cfSchristos * to remember to free them. The remaining cases are handled
479dd9d0cfSchristos * below.
489dd9d0cfSchristos */
499dd9d0cfSchristos
509dd9d0cfSchristos (void) dbg;
519dd9d0cfSchristos
529dd9d0cfSchristos if (alloc_type == DW_DLA_LIST || alloc_type == DW_DLA_FRAME_BLOCK ||
539dd9d0cfSchristos alloc_type == DW_DLA_LOC_BLOCK || alloc_type == DW_DLA_LOCDESC)
549dd9d0cfSchristos free(p);
559dd9d0cfSchristos else if (alloc_type == DW_DLA_ABBREV) {
569dd9d0cfSchristos ab = p;
579dd9d0cfSchristos STAILQ_FOREACH_SAFE(ad, &ab->ab_attrdef, ad_next, tad) {
589dd9d0cfSchristos STAILQ_REMOVE(&ab->ab_attrdef, ad, _Dwarf_AttrDef,
599dd9d0cfSchristos ad_next);
609dd9d0cfSchristos free(ad);
619dd9d0cfSchristos }
629dd9d0cfSchristos free(ab);
639dd9d0cfSchristos } else if (alloc_type == DW_DLA_DIE) {
649dd9d0cfSchristos die = p;
659dd9d0cfSchristos STAILQ_FOREACH_SAFE(at, &die->die_attr, at_next, tat) {
669dd9d0cfSchristos STAILQ_REMOVE(&die->die_attr, at,
679dd9d0cfSchristos _Dwarf_Attribute, at_next);
689dd9d0cfSchristos if (at->at_ld != NULL)
699dd9d0cfSchristos free(at->at_ld);
709dd9d0cfSchristos free(at);
719dd9d0cfSchristos }
729dd9d0cfSchristos if (die->die_attrarray)
739dd9d0cfSchristos free(die->die_attrarray);
749dd9d0cfSchristos free(die);
759dd9d0cfSchristos }
769dd9d0cfSchristos }
779dd9d0cfSchristos
789dd9d0cfSchristos void
dwarf_srclines_dealloc(Dwarf_Debug dbg,Dwarf_Line * linebuf,Dwarf_Signed count)799dd9d0cfSchristos dwarf_srclines_dealloc(Dwarf_Debug dbg, Dwarf_Line *linebuf,
809dd9d0cfSchristos Dwarf_Signed count)
819dd9d0cfSchristos {
829dd9d0cfSchristos /*
839dd9d0cfSchristos * In this libdwarf implementation, line information remains
849dd9d0cfSchristos * associated with the DIE for a compilation unit for the
859dd9d0cfSchristos * lifetime of the DIE. The client does not need to free
869dd9d0cfSchristos * the memory returned by `dwarf_srclines()`.
879dd9d0cfSchristos */
889dd9d0cfSchristos
899dd9d0cfSchristos (void) dbg; (void) linebuf; (void) count;
909dd9d0cfSchristos }
919dd9d0cfSchristos
929dd9d0cfSchristos void
dwarf_ranges_dealloc(Dwarf_Debug dbg,Dwarf_Ranges * ranges,Dwarf_Signed range_count)939dd9d0cfSchristos dwarf_ranges_dealloc(Dwarf_Debug dbg, Dwarf_Ranges *ranges,
949dd9d0cfSchristos Dwarf_Signed range_count)
959dd9d0cfSchristos {
969dd9d0cfSchristos /*
979dd9d0cfSchristos * In this libdwarf implementation, ranges information is
989dd9d0cfSchristos * kept by a STAILQ inside Dwarf_Debug object. The client
999dd9d0cfSchristos * does not need to free the memory returned by
1009dd9d0cfSchristos * `dwarf_get_ranges()` or `dwarf_get_ranges_a()`.
1019dd9d0cfSchristos */
1029dd9d0cfSchristos
1039dd9d0cfSchristos (void) dbg; (void) ranges; (void) range_count;
1049dd9d0cfSchristos }
1059dd9d0cfSchristos
1069dd9d0cfSchristos void
dwarf_fde_cie_list_dealloc(Dwarf_Debug dbg,Dwarf_Cie * cie_list,Dwarf_Signed cie_count,Dwarf_Fde * fde_list,Dwarf_Signed fde_count)1079dd9d0cfSchristos dwarf_fde_cie_list_dealloc(Dwarf_Debug dbg, Dwarf_Cie *cie_list,
1089dd9d0cfSchristos Dwarf_Signed cie_count, Dwarf_Fde *fde_list, Dwarf_Signed fde_count)
1099dd9d0cfSchristos {
1109dd9d0cfSchristos /*
1119dd9d0cfSchristos * In this implementation, FDE and CIE information is managed
1129dd9d0cfSchristos * as part of the Dwarf_Debug object. The client does not need
1139dd9d0cfSchristos * to explicitly free these memory arenas.
1149dd9d0cfSchristos */
1159dd9d0cfSchristos (void) dbg;
1169dd9d0cfSchristos (void) cie_list;
1179dd9d0cfSchristos (void) cie_count;
1189dd9d0cfSchristos (void) fde_list;
1199dd9d0cfSchristos (void) fde_count;
1209dd9d0cfSchristos }
121