2 * Copyright (c) 2009,2011 Kai Wang
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include "_libdwarf.h"
29 ELFTC_VCSID("$Id: dwarf_abbrev.c 2072 2011-10-27 03:26:49Z jkoshy $");
32 dwarf_get_abbrev(Dwarf_Debug dbg, Dwarf_Unsigned offset,
33 Dwarf_Abbrev *return_abbrev, Dwarf_Unsigned *length,
34 Dwarf_Unsigned *attr_count, Dwarf_Error *error)
39 if (dbg == NULL || return_abbrev == NULL || length == NULL ||
41 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
42 return (DW_DLV_ERROR);
45 ret = _dwarf_abbrev_parse(dbg, NULL, &offset, &ab, error);
46 if (ret != DW_DLE_NONE) {
47 if (ret == DW_DLE_NO_ENTRY) {
48 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
49 return (DW_DLV_NO_ENTRY);
51 return (DW_DLV_ERROR);
55 *length = ab->ab_length;
56 *attr_count = ab->ab_atnum;
62 dwarf_get_abbrev_tag(Dwarf_Abbrev abbrev, Dwarf_Half *return_tag,
66 if (abbrev == NULL || return_tag == NULL) {
67 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
68 return (DW_DLV_ERROR);
71 *return_tag = (Dwarf_Half) abbrev->ab_tag;
77 dwarf_get_abbrev_code(Dwarf_Abbrev abbrev, Dwarf_Unsigned *return_code,
81 if (abbrev == NULL || return_code == NULL) {
82 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
83 return (DW_DLV_ERROR);
86 *return_code = abbrev->ab_entry;
92 dwarf_get_abbrev_children_flag(Dwarf_Abbrev abbrev, Dwarf_Signed *return_flag,
96 if (abbrev == NULL || return_flag == NULL) {
97 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
98 return (DW_DLV_ERROR);
101 *return_flag = (Dwarf_Signed) abbrev->ab_children;
107 dwarf_get_abbrev_entry(Dwarf_Abbrev abbrev, Dwarf_Signed ndx,
108 Dwarf_Half *attr_num, Dwarf_Signed *form, Dwarf_Off *offset,
114 if (abbrev == NULL || attr_num == NULL || form == NULL ||
116 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
117 return (DW_DLV_ERROR);
120 if (ndx < 0 || (uint64_t) ndx >= abbrev->ab_atnum) {
121 DWARF_SET_ERROR(NULL, error, DW_DLE_NO_ENTRY);
122 return (DW_DLV_NO_ENTRY);
125 ad = STAILQ_FIRST(&abbrev->ab_attrdef);
126 for (i = 0; i < ndx && ad != NULL; i++)
127 ad = STAILQ_NEXT(ad, ad_next);
131 *attr_num = ad->ad_attrib;
133 *offset = ad->ad_offset;