1*0a6a1f1dSLionel Sambuc /* $NetBSD: dwarf_die.c,v 1.2 2014/03/09 16:58:03 christos Exp $ */
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc /*-
4*0a6a1f1dSLionel Sambuc * Copyright (c) 2007 John Birrell (jb@freebsd.org)
5*0a6a1f1dSLionel Sambuc * Copyright (c) 2009,2011 Kai Wang
6*0a6a1f1dSLionel Sambuc * All rights reserved.
7*0a6a1f1dSLionel Sambuc *
8*0a6a1f1dSLionel Sambuc * Redistribution and use in source and binary forms, with or without
9*0a6a1f1dSLionel Sambuc * modification, are permitted provided that the following conditions
10*0a6a1f1dSLionel Sambuc * are met:
11*0a6a1f1dSLionel Sambuc * 1. Redistributions of source code must retain the above copyright
12*0a6a1f1dSLionel Sambuc * notice, this list of conditions and the following disclaimer.
13*0a6a1f1dSLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
14*0a6a1f1dSLionel Sambuc * notice, this list of conditions and the following disclaimer in the
15*0a6a1f1dSLionel Sambuc * documentation and/or other materials provided with the distribution.
16*0a6a1f1dSLionel Sambuc *
17*0a6a1f1dSLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18*0a6a1f1dSLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*0a6a1f1dSLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*0a6a1f1dSLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21*0a6a1f1dSLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0a6a1f1dSLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*0a6a1f1dSLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*0a6a1f1dSLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*0a6a1f1dSLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*0a6a1f1dSLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*0a6a1f1dSLionel Sambuc * SUCH DAMAGE.
28*0a6a1f1dSLionel Sambuc */
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambuc #include "_libdwarf.h"
31*0a6a1f1dSLionel Sambuc
32*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: dwarf_die.c,v 1.2 2014/03/09 16:58:03 christos Exp $");
33*0a6a1f1dSLionel Sambuc ELFTC_VCSID("Id: dwarf_die.c 2073 2011-10-27 03:30:47Z jkoshy ");
34*0a6a1f1dSLionel Sambuc
35*0a6a1f1dSLionel Sambuc int
dwarf_child(Dwarf_Die die,Dwarf_Die * ret_die,Dwarf_Error * error)36*0a6a1f1dSLionel Sambuc dwarf_child(Dwarf_Die die, Dwarf_Die *ret_die, Dwarf_Error *error)
37*0a6a1f1dSLionel Sambuc {
38*0a6a1f1dSLionel Sambuc Dwarf_Debug dbg;
39*0a6a1f1dSLionel Sambuc Dwarf_CU cu;
40*0a6a1f1dSLionel Sambuc int ret;
41*0a6a1f1dSLionel Sambuc
42*0a6a1f1dSLionel Sambuc dbg = die != NULL ? die->die_dbg : NULL;
43*0a6a1f1dSLionel Sambuc
44*0a6a1f1dSLionel Sambuc if (die == NULL || ret_die == NULL) {
45*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
46*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
47*0a6a1f1dSLionel Sambuc }
48*0a6a1f1dSLionel Sambuc
49*0a6a1f1dSLionel Sambuc if (die->die_ab->ab_children == DW_CHILDREN_no)
50*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
51*0a6a1f1dSLionel Sambuc
52*0a6a1f1dSLionel Sambuc dbg = die->die_dbg;
53*0a6a1f1dSLionel Sambuc cu = die->die_cu;
54*0a6a1f1dSLionel Sambuc ret = _dwarf_die_parse(die->die_dbg, dbg->dbg_info_sec, cu,
55*0a6a1f1dSLionel Sambuc cu->cu_dwarf_size, die->die_next_off, cu->cu_next_offset,
56*0a6a1f1dSLionel Sambuc ret_die, 0, error);
57*0a6a1f1dSLionel Sambuc
58*0a6a1f1dSLionel Sambuc if (ret == DW_DLE_NO_ENTRY) {
59*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
60*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
61*0a6a1f1dSLionel Sambuc } else if (ret != DW_DLE_NONE)
62*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
63*0a6a1f1dSLionel Sambuc
64*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
65*0a6a1f1dSLionel Sambuc }
66*0a6a1f1dSLionel Sambuc
67*0a6a1f1dSLionel Sambuc int
dwarf_siblingof(Dwarf_Debug dbg,Dwarf_Die die,Dwarf_Die * ret_die,Dwarf_Error * error)68*0a6a1f1dSLionel Sambuc dwarf_siblingof(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Die *ret_die,
69*0a6a1f1dSLionel Sambuc Dwarf_Error *error)
70*0a6a1f1dSLionel Sambuc {
71*0a6a1f1dSLionel Sambuc Dwarf_CU cu;
72*0a6a1f1dSLionel Sambuc Dwarf_Attribute at;
73*0a6a1f1dSLionel Sambuc uint64_t offset;
74*0a6a1f1dSLionel Sambuc int ret, search_sibling;
75*0a6a1f1dSLionel Sambuc
76*0a6a1f1dSLionel Sambuc if (dbg == NULL || ret_die == NULL) {
77*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
78*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
79*0a6a1f1dSLionel Sambuc }
80*0a6a1f1dSLionel Sambuc
81*0a6a1f1dSLionel Sambuc if ((cu = dbg->dbg_cu_current) == NULL) {
82*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_DIE_NO_CU_CONTEXT);
83*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
84*0a6a1f1dSLionel Sambuc }
85*0a6a1f1dSLionel Sambuc
86*0a6a1f1dSLionel Sambuc /* Application requests the first DIE in this CU. */
87*0a6a1f1dSLionel Sambuc if (die == NULL)
88*0a6a1f1dSLionel Sambuc return (dwarf_offdie(dbg, cu->cu_1st_offset, ret_die,
89*0a6a1f1dSLionel Sambuc error));
90*0a6a1f1dSLionel Sambuc
91*0a6a1f1dSLionel Sambuc /*
92*0a6a1f1dSLionel Sambuc * If the DIE doesn't have any children, its sibling sits next
93*0a6a1f1dSLionel Sambuc * right to it.
94*0a6a1f1dSLionel Sambuc */
95*0a6a1f1dSLionel Sambuc search_sibling = 0;
96*0a6a1f1dSLionel Sambuc if (die->die_ab->ab_children == DW_CHILDREN_no)
97*0a6a1f1dSLionel Sambuc offset = die->die_next_off;
98*0a6a1f1dSLionel Sambuc else {
99*0a6a1f1dSLionel Sambuc /*
100*0a6a1f1dSLionel Sambuc * Look for DW_AT_sibling attribute for the offset of
101*0a6a1f1dSLionel Sambuc * its sibling.
102*0a6a1f1dSLionel Sambuc */
103*0a6a1f1dSLionel Sambuc if ((at = _dwarf_attr_find(die, DW_AT_sibling)) != NULL) {
104*0a6a1f1dSLionel Sambuc if (at->at_form != DW_FORM_ref_addr)
105*0a6a1f1dSLionel Sambuc offset = at->u[0].u64 + cu->cu_offset;
106*0a6a1f1dSLionel Sambuc else
107*0a6a1f1dSLionel Sambuc offset = at->u[0].u64;
108*0a6a1f1dSLionel Sambuc } else {
109*0a6a1f1dSLionel Sambuc offset = die->die_next_off;
110*0a6a1f1dSLionel Sambuc search_sibling = 1;
111*0a6a1f1dSLionel Sambuc }
112*0a6a1f1dSLionel Sambuc }
113*0a6a1f1dSLionel Sambuc
114*0a6a1f1dSLionel Sambuc ret = _dwarf_die_parse(die->die_dbg, dbg->dbg_info_sec, cu,
115*0a6a1f1dSLionel Sambuc cu->cu_dwarf_size, offset, cu->cu_next_offset, ret_die,
116*0a6a1f1dSLionel Sambuc search_sibling, error);
117*0a6a1f1dSLionel Sambuc
118*0a6a1f1dSLionel Sambuc if (ret == DW_DLE_NO_ENTRY) {
119*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
120*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
121*0a6a1f1dSLionel Sambuc } else if (ret != DW_DLE_NONE)
122*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
123*0a6a1f1dSLionel Sambuc
124*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
125*0a6a1f1dSLionel Sambuc }
126*0a6a1f1dSLionel Sambuc
127*0a6a1f1dSLionel Sambuc static int
_dwarf_search_die_within_cu(Dwarf_Debug dbg,Dwarf_CU cu,Dwarf_Off offset,Dwarf_Die * ret_die,Dwarf_Error * error)128*0a6a1f1dSLionel Sambuc _dwarf_search_die_within_cu(Dwarf_Debug dbg, Dwarf_CU cu, Dwarf_Off offset,
129*0a6a1f1dSLionel Sambuc Dwarf_Die *ret_die, Dwarf_Error *error)
130*0a6a1f1dSLionel Sambuc {
131*0a6a1f1dSLionel Sambuc
132*0a6a1f1dSLionel Sambuc assert(dbg != NULL && cu != NULL && ret_die != NULL);
133*0a6a1f1dSLionel Sambuc
134*0a6a1f1dSLionel Sambuc return (_dwarf_die_parse(dbg, dbg->dbg_info_sec, cu, cu->cu_dwarf_size,
135*0a6a1f1dSLionel Sambuc offset, cu->cu_next_offset, ret_die, 0, error));
136*0a6a1f1dSLionel Sambuc }
137*0a6a1f1dSLionel Sambuc
138*0a6a1f1dSLionel Sambuc int
dwarf_offdie(Dwarf_Debug dbg,Dwarf_Off offset,Dwarf_Die * ret_die,Dwarf_Error * error)139*0a6a1f1dSLionel Sambuc dwarf_offdie(Dwarf_Debug dbg, Dwarf_Off offset, Dwarf_Die *ret_die,
140*0a6a1f1dSLionel Sambuc Dwarf_Error *error)
141*0a6a1f1dSLionel Sambuc {
142*0a6a1f1dSLionel Sambuc Dwarf_CU cu;
143*0a6a1f1dSLionel Sambuc int ret;
144*0a6a1f1dSLionel Sambuc
145*0a6a1f1dSLionel Sambuc if (dbg == NULL || ret_die == NULL) {
146*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
147*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
148*0a6a1f1dSLionel Sambuc }
149*0a6a1f1dSLionel Sambuc
150*0a6a1f1dSLionel Sambuc /* First search the current CU. */
151*0a6a1f1dSLionel Sambuc if (dbg->dbg_cu_current != NULL) {
152*0a6a1f1dSLionel Sambuc cu = dbg->dbg_cu_current;
153*0a6a1f1dSLionel Sambuc if (offset > cu->cu_offset && offset < cu->cu_next_offset) {
154*0a6a1f1dSLionel Sambuc ret = _dwarf_search_die_within_cu(dbg, cu, offset,
155*0a6a1f1dSLionel Sambuc ret_die, error);
156*0a6a1f1dSLionel Sambuc if (ret == DW_DLE_NO_ENTRY) {
157*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
158*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
159*0a6a1f1dSLionel Sambuc } else if (ret != DW_DLE_NONE)
160*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
161*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
162*0a6a1f1dSLionel Sambuc }
163*0a6a1f1dSLionel Sambuc }
164*0a6a1f1dSLionel Sambuc
165*0a6a1f1dSLionel Sambuc /* Search other CUs. */
166*0a6a1f1dSLionel Sambuc ret = _dwarf_info_load(dbg, 1, error);
167*0a6a1f1dSLionel Sambuc if (ret != DW_DLE_NONE)
168*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
169*0a6a1f1dSLionel Sambuc
170*0a6a1f1dSLionel Sambuc STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
171*0a6a1f1dSLionel Sambuc if (offset < cu->cu_offset || offset > cu->cu_next_offset)
172*0a6a1f1dSLionel Sambuc continue;
173*0a6a1f1dSLionel Sambuc ret = _dwarf_search_die_within_cu(dbg, cu, offset,
174*0a6a1f1dSLionel Sambuc ret_die, error);
175*0a6a1f1dSLionel Sambuc if (ret == DW_DLE_NO_ENTRY) {
176*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
177*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
178*0a6a1f1dSLionel Sambuc } else if (ret != DW_DLE_NONE)
179*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
180*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
181*0a6a1f1dSLionel Sambuc }
182*0a6a1f1dSLionel Sambuc
183*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
184*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
185*0a6a1f1dSLionel Sambuc }
186*0a6a1f1dSLionel Sambuc
187*0a6a1f1dSLionel Sambuc int
dwarf_tag(Dwarf_Die die,Dwarf_Half * tag,Dwarf_Error * error)188*0a6a1f1dSLionel Sambuc dwarf_tag(Dwarf_Die die, Dwarf_Half *tag, Dwarf_Error *error)
189*0a6a1f1dSLionel Sambuc {
190*0a6a1f1dSLionel Sambuc Dwarf_Debug dbg;
191*0a6a1f1dSLionel Sambuc
192*0a6a1f1dSLionel Sambuc dbg = die != NULL ? die->die_dbg : NULL;
193*0a6a1f1dSLionel Sambuc
194*0a6a1f1dSLionel Sambuc if (die == NULL || tag == NULL) {
195*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
196*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
197*0a6a1f1dSLionel Sambuc }
198*0a6a1f1dSLionel Sambuc
199*0a6a1f1dSLionel Sambuc assert(die->die_ab != NULL);
200*0a6a1f1dSLionel Sambuc
201*0a6a1f1dSLionel Sambuc *tag = (Dwarf_Half) die->die_ab->ab_tag;
202*0a6a1f1dSLionel Sambuc
203*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
204*0a6a1f1dSLionel Sambuc }
205*0a6a1f1dSLionel Sambuc
206*0a6a1f1dSLionel Sambuc int
dwarf_dieoffset(Dwarf_Die die,Dwarf_Off * ret_offset,Dwarf_Error * error)207*0a6a1f1dSLionel Sambuc dwarf_dieoffset(Dwarf_Die die, Dwarf_Off *ret_offset, Dwarf_Error *error)
208*0a6a1f1dSLionel Sambuc {
209*0a6a1f1dSLionel Sambuc Dwarf_Debug dbg;
210*0a6a1f1dSLionel Sambuc
211*0a6a1f1dSLionel Sambuc dbg = die != NULL ? die->die_dbg : NULL;
212*0a6a1f1dSLionel Sambuc
213*0a6a1f1dSLionel Sambuc if (die == NULL || ret_offset == NULL) {
214*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
215*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
216*0a6a1f1dSLionel Sambuc }
217*0a6a1f1dSLionel Sambuc
218*0a6a1f1dSLionel Sambuc *ret_offset = die->die_offset;
219*0a6a1f1dSLionel Sambuc
220*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
221*0a6a1f1dSLionel Sambuc }
222*0a6a1f1dSLionel Sambuc
223*0a6a1f1dSLionel Sambuc int
dwarf_die_CU_offset(Dwarf_Die die,Dwarf_Off * ret_offset,Dwarf_Error * error)224*0a6a1f1dSLionel Sambuc dwarf_die_CU_offset(Dwarf_Die die, Dwarf_Off *ret_offset, Dwarf_Error *error)
225*0a6a1f1dSLionel Sambuc {
226*0a6a1f1dSLionel Sambuc Dwarf_Debug dbg;
227*0a6a1f1dSLionel Sambuc Dwarf_CU cu;
228*0a6a1f1dSLionel Sambuc
229*0a6a1f1dSLionel Sambuc dbg = die != NULL ? die->die_dbg : NULL;
230*0a6a1f1dSLionel Sambuc
231*0a6a1f1dSLionel Sambuc if (die == NULL || ret_offset == NULL) {
232*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
233*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
234*0a6a1f1dSLionel Sambuc }
235*0a6a1f1dSLionel Sambuc
236*0a6a1f1dSLionel Sambuc cu = die->die_cu;
237*0a6a1f1dSLionel Sambuc assert(cu != NULL);
238*0a6a1f1dSLionel Sambuc
239*0a6a1f1dSLionel Sambuc *ret_offset = die->die_offset - cu->cu_offset;
240*0a6a1f1dSLionel Sambuc
241*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
242*0a6a1f1dSLionel Sambuc }
243*0a6a1f1dSLionel Sambuc
244*0a6a1f1dSLionel Sambuc int
dwarf_die_CU_offset_range(Dwarf_Die die,Dwarf_Off * cu_offset,Dwarf_Off * cu_length,Dwarf_Error * error)245*0a6a1f1dSLionel Sambuc dwarf_die_CU_offset_range(Dwarf_Die die, Dwarf_Off *cu_offset,
246*0a6a1f1dSLionel Sambuc Dwarf_Off *cu_length, Dwarf_Error *error)
247*0a6a1f1dSLionel Sambuc {
248*0a6a1f1dSLionel Sambuc Dwarf_Debug dbg;
249*0a6a1f1dSLionel Sambuc Dwarf_CU cu;
250*0a6a1f1dSLionel Sambuc
251*0a6a1f1dSLionel Sambuc dbg = die != NULL ? die->die_dbg : NULL;
252*0a6a1f1dSLionel Sambuc
253*0a6a1f1dSLionel Sambuc if (die == NULL || cu_offset == NULL || cu_length == NULL) {
254*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
255*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
256*0a6a1f1dSLionel Sambuc }
257*0a6a1f1dSLionel Sambuc
258*0a6a1f1dSLionel Sambuc cu = die->die_cu;
259*0a6a1f1dSLionel Sambuc assert(cu != NULL);
260*0a6a1f1dSLionel Sambuc
261*0a6a1f1dSLionel Sambuc *cu_offset = cu->cu_offset;
262*0a6a1f1dSLionel Sambuc *cu_length = cu->cu_length + cu->cu_length_size;
263*0a6a1f1dSLionel Sambuc
264*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
265*0a6a1f1dSLionel Sambuc }
266*0a6a1f1dSLionel Sambuc
267*0a6a1f1dSLionel Sambuc int
dwarf_diename(Dwarf_Die die,char ** ret_name,Dwarf_Error * error)268*0a6a1f1dSLionel Sambuc dwarf_diename(Dwarf_Die die, char **ret_name, Dwarf_Error *error)
269*0a6a1f1dSLionel Sambuc {
270*0a6a1f1dSLionel Sambuc Dwarf_Debug dbg;
271*0a6a1f1dSLionel Sambuc
272*0a6a1f1dSLionel Sambuc dbg = die != NULL ? die->die_dbg : NULL;
273*0a6a1f1dSLionel Sambuc
274*0a6a1f1dSLionel Sambuc if (die == NULL || ret_name == NULL) {
275*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
276*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
277*0a6a1f1dSLionel Sambuc }
278*0a6a1f1dSLionel Sambuc
279*0a6a1f1dSLionel Sambuc if (die->die_name == NULL) {
280*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
281*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
282*0a6a1f1dSLionel Sambuc }
283*0a6a1f1dSLionel Sambuc
284*0a6a1f1dSLionel Sambuc *ret_name = die->die_name;
285*0a6a1f1dSLionel Sambuc
286*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
287*0a6a1f1dSLionel Sambuc }
288*0a6a1f1dSLionel Sambuc
289*0a6a1f1dSLionel Sambuc int
dwarf_die_abbrev_code(Dwarf_Die die)290*0a6a1f1dSLionel Sambuc dwarf_die_abbrev_code(Dwarf_Die die)
291*0a6a1f1dSLionel Sambuc {
292*0a6a1f1dSLionel Sambuc
293*0a6a1f1dSLionel Sambuc assert(die != NULL);
294*0a6a1f1dSLionel Sambuc
295*0a6a1f1dSLionel Sambuc return (die->die_abnum);
296*0a6a1f1dSLionel Sambuc }
297*0a6a1f1dSLionel Sambuc
298*0a6a1f1dSLionel Sambuc int
dwarf_get_cu_die_offset_given_cu_header_offset(Dwarf_Debug dbg,Dwarf_Off in_cu_header_offset,Dwarf_Off * out_cu_die_offset,Dwarf_Error * error)299*0a6a1f1dSLionel Sambuc dwarf_get_cu_die_offset_given_cu_header_offset(Dwarf_Debug dbg,
300*0a6a1f1dSLionel Sambuc Dwarf_Off in_cu_header_offset, Dwarf_Off *out_cu_die_offset,
301*0a6a1f1dSLionel Sambuc Dwarf_Error *error)
302*0a6a1f1dSLionel Sambuc {
303*0a6a1f1dSLionel Sambuc Dwarf_CU cu;
304*0a6a1f1dSLionel Sambuc
305*0a6a1f1dSLionel Sambuc if (dbg == NULL || out_cu_die_offset == NULL) {
306*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
307*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
308*0a6a1f1dSLionel Sambuc }
309*0a6a1f1dSLionel Sambuc
310*0a6a1f1dSLionel Sambuc STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
311*0a6a1f1dSLionel Sambuc if (cu->cu_offset == in_cu_header_offset) {
312*0a6a1f1dSLionel Sambuc *out_cu_die_offset = cu->cu_1st_offset;
313*0a6a1f1dSLionel Sambuc break;
314*0a6a1f1dSLionel Sambuc }
315*0a6a1f1dSLionel Sambuc }
316*0a6a1f1dSLionel Sambuc
317*0a6a1f1dSLionel Sambuc if (cu == NULL) {
318*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);
319*0a6a1f1dSLionel Sambuc return (DW_DLV_NO_ENTRY);
320*0a6a1f1dSLionel Sambuc }
321*0a6a1f1dSLionel Sambuc
322*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
323*0a6a1f1dSLionel Sambuc }
324*0a6a1f1dSLionel Sambuc
325*0a6a1f1dSLionel Sambuc int
dwarf_get_address_size(Dwarf_Debug dbg,Dwarf_Half * addr_size,Dwarf_Error * error)326*0a6a1f1dSLionel Sambuc dwarf_get_address_size(Dwarf_Debug dbg, Dwarf_Half *addr_size,
327*0a6a1f1dSLionel Sambuc Dwarf_Error *error)
328*0a6a1f1dSLionel Sambuc {
329*0a6a1f1dSLionel Sambuc
330*0a6a1f1dSLionel Sambuc if (dbg == NULL || addr_size == NULL) {
331*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
332*0a6a1f1dSLionel Sambuc return (DW_DLV_ERROR);
333*0a6a1f1dSLionel Sambuc }
334*0a6a1f1dSLionel Sambuc
335*0a6a1f1dSLionel Sambuc *addr_size = dbg->dbg_pointer_size;
336*0a6a1f1dSLionel Sambuc
337*0a6a1f1dSLionel Sambuc return (DW_DLV_OK);
338*0a6a1f1dSLionel Sambuc }
339