xref: /freebsd/contrib/elftoolchain/libdwarf/dwarf_child.3 (revision ae500c1ff8974130f7f2692772cf288b90349e0d)
1cf781b2eSEd Maste.\" Copyright (c) 2010,2014 Kai Wang
22de3b87aSKai Wang.\" All rights reserved.
32de3b87aSKai Wang.\"
42de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without
52de3b87aSKai Wang.\" modification, are permitted provided that the following conditions
62de3b87aSKai Wang.\" are met:
72de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright
82de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer.
92de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright
102de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer in the
112de3b87aSKai Wang.\"    documentation and/or other materials provided with the distribution.
122de3b87aSKai Wang.\"
132de3b87aSKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
142de3b87aSKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
152de3b87aSKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
162de3b87aSKai Wang.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
172de3b87aSKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
182de3b87aSKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
192de3b87aSKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
202de3b87aSKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
212de3b87aSKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
222de3b87aSKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
232de3b87aSKai Wang.\" SUCH DAMAGE.
242de3b87aSKai Wang.\"
25*ae500c1fSEd Maste.\" $Id: dwarf_child.3 3644 2018-10-15 19:55:01Z jkoshy $
262de3b87aSKai Wang.\"
27cf781b2eSEd Maste.Dd December 21, 2014
282de3b87aSKai Wang.Dt DWARF_CHILD 3
29*ae500c1fSEd Maste.Os
302de3b87aSKai Wang.Sh NAME
312de3b87aSKai Wang.Nm dwarf_child ,
32cf781b2eSEd Maste.Nm dwarf_offdie ,
33cf781b2eSEd Maste.Nm dwarf_offdie_b ,
342de3b87aSKai Wang.Nm dwarf_siblingof ,
35cf781b2eSEd Maste.Nm dwarf_siblingof_b
362de3b87aSKai Wang.Nd retrieve DWARF Debugging Information Entry descriptors
372de3b87aSKai Wang.Sh LIBRARY
382de3b87aSKai Wang.Lb libdwarf
392de3b87aSKai Wang.Sh SYNOPSIS
402de3b87aSKai Wang.In libdwarf.h
412de3b87aSKai Wang.Ft int
422de3b87aSKai Wang.Fn dwarf_child "Dwarf_Die die" "Dwarf_Die *ret_die" "Dwarf_Error *err"
432de3b87aSKai Wang.Ft int
44cf781b2eSEd Maste.Fo dwarf_offdie
45cf781b2eSEd Maste.Fa "Dwarf_Debug dbg"
46cf781b2eSEd Maste.Fa "Dwarf_Off offset"
47cf781b2eSEd Maste.Fa "Dwarf_Die *ret_die"
48cf781b2eSEd Maste.Fa "Dwarf_Error *err"
49cf781b2eSEd Maste.Fc
50cf781b2eSEd Maste.Ft int
51cf781b2eSEd Maste.Fo dwarf_offdie_b
52cf781b2eSEd Maste.Fa "Dwarf_Debug dbg"
53cf781b2eSEd Maste.Fa "Dwarf_Off offset"
54cf781b2eSEd Maste.Fa "Dwarf_Bool is_info"
55cf781b2eSEd Maste.Fa "Dwarf_Die *ret_die"
56cf781b2eSEd Maste.Fa "Dwarf_Error *err"
57cf781b2eSEd Maste.Fc
58cf781b2eSEd Maste.Ft int
592de3b87aSKai Wang.Fo dwarf_siblingof
602de3b87aSKai Wang.Fa "Dwarf_Debug dbg"
612de3b87aSKai Wang.Fa "Dwarf_Die die"
622de3b87aSKai Wang.Fa "Dwarf_Die *ret_die"
632de3b87aSKai Wang.Fa "Dwarf_Error *err"
642de3b87aSKai Wang.Fc
652de3b87aSKai Wang.Ft int
66cf781b2eSEd Maste.Fo dwarf_siblingof_b
672de3b87aSKai Wang.Fa "Dwarf_Debug dbg"
68cf781b2eSEd Maste.Fa "Dwarf_Die die"
692de3b87aSKai Wang.Fa "Dwarf_Die *ret_die"
70cf781b2eSEd Maste.Fa "Dwarf_Bool is_info"
712de3b87aSKai Wang.Fa "Dwarf_Error *err"
722de3b87aSKai Wang.Fc
732de3b87aSKai Wang.Sh DESCRIPTION
742de3b87aSKai WangThese functions are used to retrieve and traverse DWARF
752de3b87aSKai WangDebugging Information Entry (DIE) descriptors associated with
762de3b87aSKai Wanga compilation unit.
772de3b87aSKai WangThese descriptors are arranged in the form of a tree, traversable
782de3b87aSKai Wangusing
792de3b87aSKai Wang.Dq child
802de3b87aSKai Wangand
812de3b87aSKai Wang.Dq sibling
822de3b87aSKai Wanglinks; see
832de3b87aSKai Wang.Xr dwarf 3
842de3b87aSKai Wangfor more information.
852de3b87aSKai WangDWARF Debugging Information Entry descriptors are represented
862de3b87aSKai Wangby the
872de3b87aSKai Wang.Vt Dwarf_Die
882de3b87aSKai Wangopaque type.
892de3b87aSKai Wang.Pp
902de3b87aSKai WangFunction
912de3b87aSKai Wang.Fn dwarf_child
922de3b87aSKai Wangretrieves the child of descriptor denoted by argument
932de3b87aSKai Wang.Ar die ,
942de3b87aSKai Wangand stores it in the location pointed to by argument
952de3b87aSKai Wang.Ar ret_die .
962de3b87aSKai Wang.Pp
972de3b87aSKai WangFunction
982de3b87aSKai Wang.Fn dwarf_siblingof
992de3b87aSKai Wangretrieves the sibling of the descriptor denoted by argument
1002de3b87aSKai Wang.Ar die ,
1012de3b87aSKai Wangand stores it in the location pointed to by argument
1022de3b87aSKai Wang.Ar ret_die .
1032de3b87aSKai WangIf argument
1042de3b87aSKai Wang.Ar die
1052de3b87aSKai Wangis NULL, the first debugging information entry descriptor for the
1062de3b87aSKai Wangcurrent compilation unit will be returned.
1072de3b87aSKai WangThis function and function
1082de3b87aSKai Wang.Fn dwarf_child
1092de3b87aSKai Wangmay be used together to traverse the tree of debugging information
1102de3b87aSKai Wangentry descriptors for a compilation unit.
1112de3b87aSKai Wang.Pp
1122de3b87aSKai WangFunction
113cf781b2eSEd Maste.Fn dwarf_siblingof_b
114cf781b2eSEd Masteis identical to the function
115cf781b2eSEd Maste.Fn dwarf_siblingof
116cf781b2eSEd Masteexcept that it can retrieve the sibling descriptor from either the
117cf781b2eSEd Mastecurrent compilation unit or type unit.
118cf781b2eSEd MasteIf argument
119cf781b2eSEd Maste.Ar is_info
120cf781b2eSEd Masteis non-zero, the function behaves identically to function
121cf781b2eSEd Maste.Fn dwarf_siblingof .
122cf781b2eSEd MasteIf argument
123cf781b2eSEd Maste.Ar is_info
124cf781b2eSEd Masteis zero, the descriptor referred by argument
125cf781b2eSEd Maste.Ar die
126cf781b2eSEd Masteshould be associated with a debugging information entry in the
127cf781b2eSEd Mastetype unit.
128cf781b2eSEd MasteThe function will store the sibling of the descriptor in the location
129cf781b2eSEd Mastepointed to by argument
130cf781b2eSEd Maste.Ar ret_die .
131cf781b2eSEd MasteIf argument
132cf781b2eSEd Maste.Ar is_info
133cf781b2eSEd Masteis zero and argument
134cf781b2eSEd Maste.Ar die
135cf781b2eSEd Masteis
136cf781b2eSEd Maste.Dv NULL ,
137cf781b2eSEd Mastethe first debugging information entry descriptor for the
138cf781b2eSEd Mastecurrent type unit will be returned.
139cf781b2eSEd Maste.Pp
140cf781b2eSEd MasteFunction
1412de3b87aSKai Wang.Fn dwarf_offdie
1422de3b87aSKai Wangretrieves the debugging information entry descriptor at global offset
1432de3b87aSKai Wang.Ar offset
1442de3b87aSKai Wangin the
1452de3b87aSKai Wang.Dq .debug_info
1462de3b87aSKai Wangsection of the object associated with argument
1472de3b87aSKai Wang.Ar dbg .
1482de3b87aSKai WangThe returned descriptor is written to the location pointed to by argument
1492de3b87aSKai Wang.Ar ret_die .
150cf781b2eSEd Maste.Pp
151cf781b2eSEd MasteFunction
152cf781b2eSEd Maste.Fn dwarf_offdie_b
153cf781b2eSEd Masteis identical to the function
154cf781b2eSEd Maste.Fn dwarf_offdie
155cf781b2eSEd Masteexcept that it can retrieve the debugging information entry descriptor at
156cf781b2eSEd Masteglobal offset
157cf781b2eSEd Maste.Ar offset
158cf781b2eSEd Mastefrom either of the
159cf781b2eSEd Maste.Dq .debug_info
160cf781b2eSEd Masteand
161cf781b2eSEd Maste.Dq .debug_types
162cf781b2eSEd Mastesections of the object associated with argument
163cf781b2eSEd Maste.Ar dbg .
164cf781b2eSEd MasteIf argument
165cf781b2eSEd Maste.Ar is_info
166cf781b2eSEd Masteis non-zero, the function will retrieve the debugging information
167cf781b2eSEd Masteentry from the
168cf781b2eSEd Maste.Dq .debug_info
169cf781b2eSEd Mastesection, otherwise the function will retrieve the debugging
170cf781b2eSEd Masteinformation entry from the
171cf781b2eSEd Maste.Dq .debug_types
172cf781b2eSEd Mastesection.
173cf781b2eSEd MasteThe returned descriptor is written to the location pointed to by argument
174cf781b2eSEd Maste.Ar ret_die .
1752de3b87aSKai Wang.Ss Memory Management
1762de3b87aSKai WangThe memory area used for the
1772de3b87aSKai Wang.Vt Dwarf_Die
1782de3b87aSKai Wangdescriptor returned in argument
1792de3b87aSKai Wang.Ar ret_die
1802de3b87aSKai Wangis allocated by the
1812de3b87aSKai Wang.Lb libdwarf .
1822de3b87aSKai WangApplication code should use function
1832de3b87aSKai Wang.Fn dwarf_dealloc
1842de3b87aSKai Wangwith the allocation type
1852de3b87aSKai Wang.Dv DW_DLA_DIE
1862de3b87aSKai Wangto free the memory area when the
1872de3b87aSKai Wang.Vt Dwarf_Die
1882de3b87aSKai Wangdescriptor is no longer needed.
1892de3b87aSKai Wang.Sh RETURN VALUES
1902de3b87aSKai WangThese functions return the following values:
1912de3b87aSKai Wang.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY"
1922de3b87aSKai Wang.It Bq Er DW_DLV_OK
1932de3b87aSKai WangThe call succeeded.
1942de3b87aSKai Wang.It Bq Er DW_DLV_ERROR
1952de3b87aSKai WangThe requested operation failed.
1962de3b87aSKai WangAdditional information about the error encountered will be recorded in
1972de3b87aSKai Wangargument
1982de3b87aSKai Wang.Ar err ,
1992de3b87aSKai Wangif it is not NULL.
2002de3b87aSKai Wang.It Bq Er DW_DLV_NO_ENTRY
2012de3b87aSKai WangFor functions
202cf781b2eSEd Maste.Fn dwarf_child ,
203cf781b2eSEd Maste.Fn dwarf_siblingof
2042de3b87aSKai Wangand
205cf781b2eSEd Maste.Fn dwarf_siblingof_b ,
2062de3b87aSKai Wangthe descriptor denoted by argument
2072de3b87aSKai Wang.Ar die
2082de3b87aSKai Wangdid not have a child or sibling.
209cf781b2eSEd Maste.Pp
210cf781b2eSEd MasteFor functions
211cf781b2eSEd Maste.Fn dwarf_offdie
212cf781b2eSEd Masteand
213cf781b2eSEd Maste.Fn dwarf_offdie_b ,
2142de3b87aSKai Wangthere was no debugging information entry at the offset specified by
2152de3b87aSKai Wangargument
2162de3b87aSKai Wang.Ar offset .
2172de3b87aSKai Wang.El
2182de3b87aSKai Wang.Sh EXAMPLES
2192de3b87aSKai WangTo retrieve the first DWARF Debugging Information Entry descriptor for
2202de3b87aSKai Wangthe first compilation unit associated with a
2212de3b87aSKai Wang.Vt Dwarf_Debug
2222de3b87aSKai Wanginstance, and to traverse all its children, use:
2232de3b87aSKai Wang.Bd -literal -offset indent
2242de3b87aSKai WangDwarf_Debug dbg;
2252de3b87aSKai WangDwarf_Die die, die0;
2262de3b87aSKai WangDwarf_Error de;
2272de3b87aSKai Wang
2282de3b87aSKai Wang\&... allocate dbg using dwarf_init() etc ...
2292de3b87aSKai Wang
2302de3b87aSKai Wangif (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) !=
2312de3b87aSKai Wang    DW_DLV_OK)
2322de3b87aSKai Wang	errx(EXIT_FAILURE, "dwarf_next_cu_header: %s",
2332de3b87aSKai Wang	    dwarf_errmsg(de));
2342de3b87aSKai Wang
2352de3b87aSKai Wang/* Get the first DIE for the current compilation unit. */
2362de3b87aSKai Wangdie = NULL;
2372de3b87aSKai Wangif (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK)
2382de3b87aSKai Wang	errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de));
2392de3b87aSKai Wang
2402de3b87aSKai Wang/* Get the first child of this DIE. */
2412de3b87aSKai Wangdie = die0;
2422de3b87aSKai Wangif (dwarf_child(die, &die0, &de) != DW_DLV_OK)
2432de3b87aSKai Wang	errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de));
2442de3b87aSKai Wang
2452de3b87aSKai Wang/* Get the rest of children. */
2462de3b87aSKai Wangdo {
2472de3b87aSKai Wang	die = die0;
2482de3b87aSKai Wang	if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR)
2492de3b87aSKai Wang		errx(EXIT_FAILURE, "dwarf_siblingof: %s",
2502de3b87aSKai Wang		    dwarf_errmsg(de));
2512de3b87aSKai Wang} while (die0 != NULL);
2522de3b87aSKai Wang.Ed
253*ae500c1fSEd Maste.Sh ERRORS
254*ae500c1fSEd MasteThese functions may fail with the following errors:
255*ae500c1fSEd Maste.Bl -tag -width ".Bq Er DW_DLE_DIE_NO_CU_CONTEXT"
256*ae500c1fSEd Maste.It Bq Er DW_DLE_ARGUMENT
257*ae500c1fSEd MasteArguments
258*ae500c1fSEd Maste.Ar dbg ,
259*ae500c1fSEd Maste.Ar die
260*ae500c1fSEd Masteor
261*ae500c1fSEd Maste.Ar ret_die
262*ae500c1fSEd Mastewere NULL.
263*ae500c1fSEd Maste.It Bq Er DW_DLE_DIE_NO_CU_CONTEXT
264*ae500c1fSEd MasteArgument
265*ae500c1fSEd Maste.Ar dbg
266*ae500c1fSEd Mastewas not associated with a compilation unit.
267*ae500c1fSEd Maste.It Bq Er DW_DLE_NO_ENTRY
268*ae500c1fSEd MasteThe descriptor denoted by argument
269*ae500c1fSEd Maste.Ar die
270*ae500c1fSEd Mastehad no child or sibling, or there was no DWARF debugging information
271*ae500c1fSEd Masteentry at the offset specified by argument
272*ae500c1fSEd Maste.Va offset .
273*ae500c1fSEd Maste.El
2742de3b87aSKai Wang.Sh SEE ALSO
2752de3b87aSKai Wang.Xr dwarf 3 ,
2762de3b87aSKai Wang.Xr dwarf_errmsg 3 ,
277*ae500c1fSEd Maste.Xr dwarf_get_die_infotypes_flag 3 ,
2782de3b87aSKai Wang.Xr dwarf_next_cu_header 3
279