Remove building with NOCRYPTO option
[minix3.git] / external / bsd / elftoolchain / dist / libdwarf / dwarf_abbrev.c
blob7d2c25771afd1492bb249f59aafbd19e87be28ed
1 /* $NetBSD: dwarf_abbrev.c,v 1.2 2014/03/09 16:58:03 christos Exp $ */
3 /*-
4 * Copyright (c) 2009,2011 Kai Wang
5 * All rights reserved.
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.
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.
29 #include "_libdwarf.h"
31 __RCSID("$NetBSD: dwarf_abbrev.c,v 1.2 2014/03/09 16:58:03 christos Exp $");
32 ELFTC_VCSID("Id: dwarf_abbrev.c 2072 2011-10-27 03:26:49Z jkoshy ");
34 int
35 dwarf_get_abbrev(Dwarf_Debug dbg, Dwarf_Unsigned offset,
36 Dwarf_Abbrev *return_abbrev, Dwarf_Unsigned *length,
37 Dwarf_Unsigned *attr_count, Dwarf_Error *error)
39 Dwarf_Abbrev ab;
40 int ret;
42 if (dbg == NULL || return_abbrev == NULL || length == NULL ||
43 attr_count == NULL) {
44 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
45 return (DW_DLV_ERROR);
48 ret = _dwarf_abbrev_parse(dbg, NULL, &offset, &ab, error);
49 if (ret != DW_DLE_NONE) {
50 if (ret == DW_DLE_NO_ENTRY) {
51 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
52 return (DW_DLV_NO_ENTRY);
53 } else
54 return (DW_DLV_ERROR);
57 *return_abbrev = ab;
58 *length = ab->ab_length;
59 *attr_count = ab->ab_atnum;
61 return (DW_DLV_OK);
64 int
65 dwarf_get_abbrev_tag(Dwarf_Abbrev abbrev, Dwarf_Half *return_tag,
66 Dwarf_Error *error)
69 if (abbrev == NULL || return_tag == NULL) {
70 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
71 return (DW_DLV_ERROR);
74 *return_tag = (Dwarf_Half) abbrev->ab_tag;
76 return (DW_DLV_OK);
79 int
80 dwarf_get_abbrev_code(Dwarf_Abbrev abbrev, Dwarf_Unsigned *return_code,
81 Dwarf_Error *error)
84 if (abbrev == NULL || return_code == NULL) {
85 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
86 return (DW_DLV_ERROR);
89 *return_code = abbrev->ab_entry;
91 return (DW_DLV_OK);
94 int
95 dwarf_get_abbrev_children_flag(Dwarf_Abbrev abbrev, Dwarf_Signed *return_flag,
96 Dwarf_Error *error)
99 if (abbrev == NULL || return_flag == NULL) {
100 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
101 return (DW_DLV_ERROR);
104 *return_flag = (Dwarf_Signed) abbrev->ab_children;
106 return (DW_DLV_OK);
110 dwarf_get_abbrev_entry(Dwarf_Abbrev abbrev, Dwarf_Signed ndx,
111 Dwarf_Half *attr_num, Dwarf_Signed *form, Dwarf_Off *offset,
112 Dwarf_Error *error)
114 Dwarf_AttrDef ad;
115 int i;
117 if (abbrev == NULL || attr_num == NULL || form == NULL ||
118 offset == NULL) {
119 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
120 return (DW_DLV_ERROR);
123 if (ndx < 0 || (uint64_t) ndx >= abbrev->ab_atnum) {
124 DWARF_SET_ERROR(NULL, error, DW_DLE_NO_ENTRY);
125 return (DW_DLV_NO_ENTRY);
128 ad = STAILQ_FIRST(&abbrev->ab_attrdef);
129 for (i = 0; i < ndx && ad != NULL; i++)
130 ad = STAILQ_NEXT(ad, ad_next);
132 assert(ad != NULL);
134 *attr_num = ad->ad_attrib;
135 *form = ad->ad_form;
136 *offset = ad->ad_offset;
138 return (DW_DLV_OK);