dwarf_abbrev.c revision 179187
1230130Smav/*- 2230130Smav * Copyright (c) 2007 John Birrell (jb@freebsd.org) 3230130Smav * All rights reserved. 4230130Smav * 5230130Smav * Redistribution and use in source and binary forms, with or without 6230130Smav * modification, are permitted provided that the following conditions 7230130Smav * are met: 8230130Smav * 1. Redistributions of source code must retain the above copyright 9230130Smav * notice, this list of conditions and the following disclaimer. 10230130Smav * 2. Redistributions in binary form must reproduce the above copyright 11230130Smav * notice, this list of conditions and the following disclaimer in the 12230130Smav * documentation and/or other materials provided with the distribution. 13230130Smav * 14230130Smav * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15230130Smav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16230130Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17230130Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18230130Smav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19230130Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20230130Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21230130Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22230130Smav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23230130Smav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24230130Smav * SUCH DAMAGE. 25230130Smav * 26230130Smav * $FreeBSD: head/lib/libdwarf/dwarf_abbrev.c 179187 2008-05-22 02:14:23Z jb $ 27230130Smav */ 28230130Smav 29230130Smav#include <stdlib.h> 30230130Smav#include "_libdwarf.h" 31230130Smav 32230130Smavint 33230130Smavdwarf_abbrev_add(Dwarf_CU cu, uint64_t entry, uint64_t tag, uint8_t children, Dwarf_Abbrev *ap, Dwarf_Error *error) 34230130Smav{ 35230130Smav Dwarf_Abbrev a; 36230130Smav int ret = DWARF_E_NONE; 37230130Smav 38230130Smav if ((a = malloc(sizeof(struct _Dwarf_Abbrev))) == NULL) { 39230130Smav DWARF_SET_ERROR(error, DWARF_E_MEMORY); 40230130Smav return DWARF_E_MEMORY; 41230130Smav } 42230130Smav 43230130Smav /* Initialise the abbrev structure. */ 44230130Smav a->a_entry = entry; 45230130Smav a->a_tag = tag; 46230130Smav a->a_children = children; 47230130Smav 48230130Smav /* Initialise the list of attributes. */ 49230130Smav STAILQ_INIT(&a->a_attrib); 50230130Smav 51230130Smav /* Add the abbrev to the list in the compilation unit. */ 52230130Smav STAILQ_INSERT_TAIL(&cu->cu_abbrev, a, a_next); 53230130Smav 54230130Smav if (ap != NULL) 55230130Smav *ap = a; 56230130Smav 57230130Smav return ret; 58230130Smav} 59230130Smav 60230130SmavDwarf_Abbrev 61230130Smavdwarf_abbrev_find(Dwarf_CU cu, uint64_t entry) 62230130Smav{ 63230130Smav Dwarf_Abbrev a = NULL; 64230130Smav 65230130Smav STAILQ_FOREACH(a, &cu->cu_abbrev, a_next) { 66230130Smav if (a->a_entry == entry) 67230130Smav break; 68230130Smav } 69230130Smav 70230130Smav return a; 71230130Smav} 72230130Smav