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