1 /* $NetBSD: dwarf_dealloc.c,v 1.3 2016/02/20 02:43:41 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2007 John Birrell (jb@freebsd.org) 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include "_libdwarf.h" 30 31 __RCSID("$NetBSD: dwarf_dealloc.c,v 1.3 2016/02/20 02:43:41 christos Exp $"); 32 ELFTC_VCSID("Id: dwarf_dealloc.c 2073 2011-10-27 03:30:47Z jkoshy "); 33 34 void 35 dwarf_dealloc(Dwarf_Debug dbg, Dwarf_Ptr p, Dwarf_Unsigned alloc_type) 36 { 37 Dwarf_Abbrev ab; 38 Dwarf_AttrDef ad, tad; 39 Dwarf_Attribute at, tat; 40 Dwarf_Die die; 41 42 /* 43 * This libdwarf implementation does not use the SGI/libdwarf 44 * style of memory allocation. In most cases it does not copy 45 * things to return to the client, so the client does not need 46 * to remember to free them. The remaining cases are handled 47 * below. 48 */ 49 50 (void) dbg; 51 52 if (alloc_type == DW_DLA_LIST || alloc_type == DW_DLA_FRAME_BLOCK || 53 alloc_type == DW_DLA_LOC_BLOCK || alloc_type == DW_DLA_LOCDESC) 54 free(p); 55 else if (alloc_type == DW_DLA_ABBREV) { 56 ab = p; 57 STAILQ_FOREACH_SAFE(ad, &ab->ab_attrdef, ad_next, tad) { 58 STAILQ_REMOVE(&ab->ab_attrdef, ad, _Dwarf_AttrDef, 59 ad_next); 60 free(ad); 61 } 62 free(ab); 63 } else if (alloc_type == DW_DLA_DIE) { 64 die = p; 65 STAILQ_FOREACH_SAFE(at, &die->die_attr, at_next, tat) { 66 STAILQ_REMOVE(&die->die_attr, at, 67 _Dwarf_Attribute, at_next); 68 if (at->at_ld != NULL) 69 free(at->at_ld); 70 free(at); 71 } 72 if (die->die_attrarray) 73 free(die->die_attrarray); 74 free(die); 75 } 76 } 77 78 void 79 dwarf_srclines_dealloc(Dwarf_Debug dbg, Dwarf_Line *linebuf, 80 Dwarf_Signed count) 81 { 82 /* 83 * In this libdwarf implementation, line information remains 84 * associated with the DIE for a compilation unit for the 85 * lifetime of the DIE. The client does not need to free 86 * the memory returned by `dwarf_srclines()`. 87 */ 88 89 (void) dbg; (void) linebuf; (void) count; 90 } 91 92 void 93 dwarf_ranges_dealloc(Dwarf_Debug dbg, Dwarf_Ranges *ranges, 94 Dwarf_Signed range_count) 95 { 96 /* 97 * In this libdwarf implementation, ranges information is 98 * kept by a STAILQ inside Dwarf_Debug object. The client 99 * does not need to free the memory returned by 100 * `dwarf_get_ranges()` or `dwarf_get_ranges_a()`. 101 */ 102 103 (void) dbg; (void) ranges; (void) range_count; 104 } 105 106 void 107 dwarf_fde_cie_list_dealloc(Dwarf_Debug dbg, Dwarf_Cie *cie_list, 108 Dwarf_Signed cie_count, Dwarf_Fde *fde_list, Dwarf_Signed fde_count) 109 { 110 /* 111 * In this implementation, FDE and CIE information is managed 112 * as part of the Dwarf_Debug object. The client does not need 113 * to explicitly free these memory arenas. 114 */ 115 (void) dbg; 116 (void) cie_list; 117 (void) cie_count; 118 (void) fde_list; 119 (void) fde_count; 120 } 121