1 /* $NetBSD: dwarf_abbrev.c,v 1.2 2014/03/09 16:58:03 christos Exp $ */
4 * Copyright (c) 2009,2011 Kai Wang
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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 ");
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
)
42 if (dbg
== NULL
|| return_abbrev
== NULL
|| length
== 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
);
54 return (DW_DLV_ERROR
);
58 *length
= ab
->ab_length
;
59 *attr_count
= ab
->ab_atnum
;
65 dwarf_get_abbrev_tag(Dwarf_Abbrev abbrev
, Dwarf_Half
*return_tag
,
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
;
80 dwarf_get_abbrev_code(Dwarf_Abbrev abbrev
, Dwarf_Unsigned
*return_code
,
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
;
95 dwarf_get_abbrev_children_flag(Dwarf_Abbrev abbrev
, Dwarf_Signed
*return_flag
,
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
;
110 dwarf_get_abbrev_entry(Dwarf_Abbrev abbrev
, Dwarf_Signed ndx
,
111 Dwarf_Half
*attr_num
, Dwarf_Signed
*form
, Dwarf_Off
*offset
,
117 if (abbrev
== NULL
|| attr_num
== NULL
|| form
== 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
);
134 *attr_num
= ad
->ad_attrib
;
136 *offset
= ad
->ad_offset
;