Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* Release debugging handling context. |
| 2 | Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc. |
| 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 4 | |
| 5 | This program is Open Source software; you can redistribute it and/or |
| 6 | modify it under the terms of the Open Software License version 1.0 as |
| 7 | published by the Open Source Initiative. |
| 8 | |
| 9 | You should have received a copy of the Open Software License along |
| 10 | with this program; if not, you may obtain a copy of the Open Software |
| 11 | License version 1.0 from http://www.opensource.org/licenses/osl.php or |
| 12 | by writing the Open Source Initiative c/o Lawrence Rosen, Esq., |
| 13 | 3001 King Ranch Road, Ukiah, CA 95482. */ |
| 14 | |
| 15 | #ifdef HAVE_CONFIG_H |
| 16 | # include <config.h> |
| 17 | #endif |
| 18 | |
| 19 | #include <search.h> |
| 20 | #include <stdlib.h> |
| 21 | |
| 22 | #include "libdwP.h" |
| 23 | |
| 24 | |
| 25 | |
| 26 | static void |
| 27 | noop_free (void *arg __attribute__ ((unused))) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | |
| 32 | static void |
| 33 | cu_free (void *arg) |
| 34 | { |
| 35 | struct Dwarf_CU *p = (struct Dwarf_CU *) arg; |
| 36 | |
| 37 | Dwarf_Abbrev_Hash_free (&p->abbrev_hash); |
| 38 | |
| 39 | tdestroy (p->locs, noop_free); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | int |
| 44 | dwarf_end (dwarf) |
| 45 | Dwarf *dwarf; |
| 46 | { |
| 47 | if (dwarf != NULL) |
| 48 | { |
| 49 | /* The search tree for the CUs. NB: the CU data itself is |
| 50 | allocated separately, but the abbreviation hash tables need |
| 51 | to be handled. */ |
| 52 | tdestroy (dwarf->cu_tree, cu_free); |
| 53 | |
| 54 | struct libdw_memblock *memp = dwarf->mem_tail; |
| 55 | /* The first block is allocated together with the Dwarf object. */ |
| 56 | while (memp->prev != NULL) |
| 57 | { |
| 58 | struct libdw_memblock *prevp = memp->prev; |
| 59 | free (memp); |
| 60 | memp = prevp; |
| 61 | } |
| 62 | |
| 63 | /* Free the pubnames helper structure. */ |
| 64 | free (dwarf->pubnames_sets); |
| 65 | |
| 66 | /* Free the ELF descriptor if necessary. */ |
| 67 | if (dwarf->free_elf) |
| 68 | elf_end (dwarf->elf); |
| 69 | |
| 70 | /* Free the context descriptor. */ |
| 71 | free (dwarf); |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |