1179187Sjb/*-
2179187Sjb * Copyright (c) 2007 John Birrell (jb@freebsd.org)
3179187Sjb * All rights reserved.
4179187Sjb *
5179187Sjb * Redistribution and use in source and binary forms, with or without
6179187Sjb * modification, are permitted provided that the following conditions
7179187Sjb * are met:
8179187Sjb * 1. Redistributions of source code must retain the above copyright
9179187Sjb *    notice, this list of conditions and the following disclaimer.
10179187Sjb * 2. Redistributions in binary form must reproduce the above copyright
11179187Sjb *    notice, this list of conditions and the following disclaimer in the
12179187Sjb *    documentation and/or other materials provided with the distribution.
13179187Sjb *
14179187Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15179187Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16179187Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17179187Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18179187Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19179187Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20179187Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21179187Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22179187Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23179187Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24179187Sjb * SUCH DAMAGE.
25179187Sjb *
26179187Sjb * $FreeBSD$
27179187Sjb */
28179187Sjb
29179187Sjb#include <stdlib.h>
30179187Sjb#include "_libdwarf.h"
31179187Sjb
32179187Sjbint
33179187Sjbdwarf_abbrev_add(Dwarf_CU cu, uint64_t entry, uint64_t tag, uint8_t children, Dwarf_Abbrev *ap, Dwarf_Error *error)
34179187Sjb{
35179187Sjb	Dwarf_Abbrev a;
36179187Sjb	int ret = DWARF_E_NONE;
37179187Sjb
38179187Sjb	if ((a = malloc(sizeof(struct _Dwarf_Abbrev))) == NULL) {
39179187Sjb		DWARF_SET_ERROR(error, DWARF_E_MEMORY);
40179187Sjb		return DWARF_E_MEMORY;
41179187Sjb	}
42179187Sjb
43179187Sjb	/* Initialise the abbrev structure. */
44179187Sjb	a->a_entry	= entry;
45179187Sjb	a->a_tag	= tag;
46179187Sjb	a->a_children	= children;
47179187Sjb
48179187Sjb	/* Initialise the list of attributes. */
49179187Sjb	STAILQ_INIT(&a->a_attrib);
50179187Sjb
51179187Sjb	/* Add the abbrev to the list in the compilation unit. */
52179187Sjb	STAILQ_INSERT_TAIL(&cu->cu_abbrev, a, a_next);
53179187Sjb
54179187Sjb	if (ap != NULL)
55179187Sjb		*ap = a;
56179187Sjb
57179187Sjb	return ret;
58179187Sjb}
59179187Sjb
60179187SjbDwarf_Abbrev
61179187Sjbdwarf_abbrev_find(Dwarf_CU cu, uint64_t entry)
62179187Sjb{
63179187Sjb	Dwarf_Abbrev a = NULL;
64179187Sjb
65179187Sjb	STAILQ_FOREACH(a, &cu->cu_abbrev, a_next) {
66179187Sjb		if (a->a_entry == entry)
67179187Sjb			break;
68179187Sjb	}
69179187Sjb
70179187Sjb	return a;
71179187Sjb}
72