xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_child.3 (revision 82d56013d7b633d116a93943de88e08335357a7c)
1.\"	$NetBSD: dwarf_child.3,v 1.4 2020/11/26 22:51:35 jkoshy 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 3644 2018-10-15 19:55:01Z jkoshy
28.\"
29.Dd December 21, 2014
30.Dt DWARF_CHILD 3
31.Os
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 EXAMPLES
221To retrieve the first DWARF Debugging Information Entry descriptor for
222the first compilation unit associated with a
223.Vt Dwarf_Debug
224instance, and to traverse all its children, use:
225.Bd -literal -offset indent
226Dwarf_Debug dbg;
227Dwarf_Die die, die0;
228Dwarf_Error de;
229
230\&... allocate dbg using dwarf_init() etc ...
231
232if (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) !=
233    DW_DLV_OK)
234	errx(EXIT_FAILURE, "dwarf_next_cu_header: %s",
235	    dwarf_errmsg(de));
236
237/* Get the first DIE for the current compilation unit. */
238die = NULL;
239if (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK)
240	errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de));
241
242/* Get the first child of this DIE. */
243die = die0;
244if (dwarf_child(die, &die0, &de) != DW_DLV_OK)
245	errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de));
246
247/* Get the rest of children. */
248do {
249	die = die0;
250	if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR)
251		errx(EXIT_FAILURE, "dwarf_siblingof: %s",
252		    dwarf_errmsg(de));
253} while (die0 != NULL);
254.Ed
255.Sh ERRORS
256These functions may fail with the following errors:
257.Bl -tag -width ".Bq Er DW_DLE_DIE_NO_CU_CONTEXT"
258.It Bq Er DW_DLE_ARGUMENT
259Arguments
260.Ar dbg ,
261.Ar die
262or
263.Ar ret_die
264were NULL.
265.It Bq Er DW_DLE_DIE_NO_CU_CONTEXT
266Argument
267.Ar dbg
268was not associated with a compilation unit.
269.It Bq Er DW_DLE_NO_ENTRY
270The descriptor denoted by argument
271.Ar die
272had no child or sibling, or there was no DWARF debugging information
273entry at the offset specified by argument
274.Va offset .
275.El
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