xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_child.3 (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1.\"	$NetBSD: dwarf_child.3,v 1.3 2016/02/20 02:43:41 christos Exp $
2.\"
3.\" Copyright (c) 2010,2014 Kai Wang
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.\" Id: dwarf_child.3 3127 2014-12-21 19:09:19Z jkoshy
28.\"
29.Dd December 21, 2014
30.Os
31.Dt DWARF_CHILD 3
32.Sh NAME
33.Nm dwarf_child ,
34.Nm dwarf_offdie ,
35.Nm dwarf_offdie_b ,
36.Nm dwarf_siblingof ,
37.Nm dwarf_siblingof_b
38.Nd retrieve DWARF Debugging Information Entry descriptors
39.Sh LIBRARY
40.Lb libdwarf
41.Sh SYNOPSIS
42.In libdwarf.h
43.Ft int
44.Fn dwarf_child "Dwarf_Die die" "Dwarf_Die *ret_die" "Dwarf_Error *err"
45.Ft int
46.Fo dwarf_offdie
47.Fa "Dwarf_Debug dbg"
48.Fa "Dwarf_Off offset"
49.Fa "Dwarf_Die *ret_die"
50.Fa "Dwarf_Error *err"
51.Fc
52.Ft int
53.Fo dwarf_offdie_b
54.Fa "Dwarf_Debug dbg"
55.Fa "Dwarf_Off offset"
56.Fa "Dwarf_Bool is_info"
57.Fa "Dwarf_Die *ret_die"
58.Fa "Dwarf_Error *err"
59.Fc
60.Ft int
61.Fo dwarf_siblingof
62.Fa "Dwarf_Debug dbg"
63.Fa "Dwarf_Die die"
64.Fa "Dwarf_Die *ret_die"
65.Fa "Dwarf_Error *err"
66.Fc
67.Ft int
68.Fo dwarf_siblingof_b
69.Fa "Dwarf_Debug dbg"
70.Fa "Dwarf_Die die"
71.Fa "Dwarf_Die *ret_die"
72.Fa "Dwarf_Bool is_info"
73.Fa "Dwarf_Error *err"
74.Fc
75.Sh DESCRIPTION
76These functions are used to retrieve and traverse DWARF
77Debugging Information Entry (DIE) descriptors associated with
78a compilation unit.
79These descriptors are arranged in the form of a tree, traversable
80using
81.Dq child
82and
83.Dq sibling
84links; see
85.Xr dwarf 3
86for more information.
87DWARF Debugging Information Entry descriptors are represented
88by the
89.Vt Dwarf_Die
90opaque type.
91.Pp
92Function
93.Fn dwarf_child
94retrieves the child of descriptor denoted by argument
95.Ar die ,
96and stores it in the location pointed to by argument
97.Ar ret_die .
98.Pp
99Function
100.Fn dwarf_siblingof
101retrieves the sibling of the descriptor denoted by argument
102.Ar die ,
103and stores it in the location pointed to by argument
104.Ar ret_die .
105If argument
106.Ar die
107is NULL, the first debugging information entry descriptor for the
108current compilation unit will be returned.
109This function and function
110.Fn dwarf_child
111may be used together to traverse the tree of debugging information
112entry descriptors for a compilation unit.
113.Pp
114Function
115.Fn dwarf_siblingof_b
116is identical to the function
117.Fn dwarf_siblingof
118except that it can retrieve the sibling descriptor from either the
119current compilation unit or type unit.
120If argument
121.Ar is_info
122is non-zero, the function behaves identically to function
123.Fn dwarf_siblingof .
124If argument
125.Ar is_info
126is zero, the descriptor referred by argument
127.Ar die
128should be associated with a debugging information entry in the
129type unit.
130The function will store the sibling of the descriptor in the location
131pointed to by argument
132.Ar ret_die .
133If argument
134.Ar is_info
135is zero and argument
136.Ar die
137is
138.Dv NULL ,
139the first debugging information entry descriptor for the
140current type unit will be returned.
141.Pp
142Function
143.Fn dwarf_offdie
144retrieves the debugging information entry descriptor at global offset
145.Ar offset
146in the
147.Dq .debug_info
148section of the object associated with argument
149.Ar dbg .
150The returned descriptor is written to the location pointed to by argument
151.Ar ret_die .
152.Pp
153Function
154.Fn dwarf_offdie_b
155is identical to the function
156.Fn dwarf_offdie
157except that it can retrieve the debugging information entry descriptor at
158global offset
159.Ar offset
160from either of the
161.Dq .debug_info
162and
163.Dq .debug_types
164sections of the object associated with argument
165.Ar dbg .
166If argument
167.Ar is_info
168is non-zero, the function will retrieve the debugging information
169entry from the
170.Dq .debug_info
171section, otherwise the function will retrieve the debugging
172information entry from the
173.Dq .debug_types
174section.
175The returned descriptor is written to the location pointed to by argument
176.Ar ret_die .
177.Ss Memory Management
178The memory area used for the
179.Vt Dwarf_Die
180descriptor returned in argument
181.Ar ret_die
182is allocated by the
183.Lb libdwarf .
184Application code should use function
185.Fn dwarf_dealloc
186with the allocation type
187.Dv DW_DLA_DIE
188to free the memory area when the
189.Vt Dwarf_Die
190descriptor is no longer needed.
191.Sh RETURN VALUES
192These functions return the following values:
193.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY"
194.It Bq Er DW_DLV_OK
195The call succeeded.
196.It Bq Er DW_DLV_ERROR
197The requested operation failed.
198Additional information about the error encountered will be recorded in
199argument
200.Ar err ,
201if it is not NULL.
202.It Bq Er DW_DLV_NO_ENTRY
203For functions
204.Fn dwarf_child ,
205.Fn dwarf_siblingof
206and
207.Fn dwarf_siblingof_b ,
208the descriptor denoted by argument
209.Ar die
210did not have a child or sibling.
211.Pp
212For functions
213.Fn dwarf_offdie
214and
215.Fn dwarf_offdie_b ,
216there was no debugging information entry at the offset specified by
217argument
218.Ar offset .
219.El
220.Sh ERRORS
221These functions may fail with the following errors:
222.Bl -tag -width ".Bq Er DW_DLE_DIE_NO_CU_CONTEXT"
223.It Bq Er DW_DLE_ARGUMENT
224Arguments
225.Ar dbg ,
226.Ar die
227or
228.Ar ret_die
229were NULL.
230.It Bq Er DW_DLE_DIE_NO_CU_CONTEXT
231Argument
232.Ar dbg
233was not associated with a compilation unit.
234.It Bq Er DW_DLE_NO_ENTRY
235The descriptor denoted by argument
236.Ar die
237had no child or sibling, or there was no DWARF debugging information
238entry at the offset specified by argument
239.Va offset .
240.El
241.Sh EXAMPLES
242To retrieve the first DWARF Debugging Information Entry descriptor for
243the first compilation unit associated with a
244.Vt Dwarf_Debug
245instance, and to traverse all its children, use:
246.Bd -literal -offset indent
247Dwarf_Debug dbg;
248Dwarf_Die die, die0;
249Dwarf_Error de;
250
251\&... allocate dbg using dwarf_init() etc ...
252
253if (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) !=
254    DW_DLV_OK)
255	errx(EXIT_FAILURE, "dwarf_next_cu_header: %s",
256	    dwarf_errmsg(de));
257
258/* Get the first DIE for the current compilation unit. */
259die = NULL;
260if (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK)
261	errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de));
262
263/* Get the first child of this DIE. */
264die = die0;
265if (dwarf_child(die, &die0, &de) != DW_DLV_OK)
266	errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de));
267
268/* Get the rest of children. */
269do {
270	die = die0;
271	if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR)
272		errx(EXIT_FAILURE, "dwarf_siblingof: %s",
273		    dwarf_errmsg(de));
274} while (die0 != NULL);
275.Ed
276.Sh SEE ALSO
277.Xr dwarf 3 ,
278.Xr dwarf_errmsg 3 ,
279.Xr dwarf_get_die_infotypes_flag.3 ,
280.Xr dwarf_next_cu_header 3
281