1.\" $NetBSD: dwarf_child.3,v 1.2 2014/03/09 16:58:03 christos Exp $ 2.\" 3.\" Copyright (c) 2010 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 2122 2011-11-09 15:35:14Z jkoshy 28.\" 29.Dd November 9, 2011 30.Os 31.Dt DWARF_CHILD 3 32.Sh NAME 33.Nm dwarf_child , 34.Nm dwarf_siblingof , 35.Nm dwarf_offdie 36.Nd retrieve DWARF Debugging Information Entry descriptors 37.Sh LIBRARY 38.Lb libdwarf 39.Sh SYNOPSIS 40.In libdwarf.h 41.Ft int 42.Fn dwarf_child "Dwarf_Die die" "Dwarf_Die *ret_die" "Dwarf_Error *err" 43.Ft int 44.Fo dwarf_siblingof 45.Fa "Dwarf_Debug dbg" 46.Fa "Dwarf_Die die" 47.Fa "Dwarf_Die *ret_die" 48.Fa "Dwarf_Error *err" 49.Fc 50.Ft int 51.Fo dwarf_offdie 52.Fa "Dwarf_Debug dbg" 53.Fa "Dwarf_Off offset" 54.Fa "Dwarf_Die *ret_die" 55.Fa "Dwarf_Error *err" 56.Fc 57.Sh DESCRIPTION 58These functions are used to retrieve and traverse DWARF 59Debugging Information Entry (DIE) descriptors associated with 60a compilation unit. 61These descriptors are arranged in the form of a tree, traversable 62using 63.Dq child 64and 65.Dq sibling 66links; see 67.Xr dwarf 3 68for more information. 69DWARF Debugging Information Entry descriptors are represented 70by the 71.Vt Dwarf_Die 72opaque type. 73.Pp 74Function 75.Fn dwarf_child 76retrieves the child of descriptor denoted by argument 77.Ar die , 78and stores it in the location pointed to by argument 79.Ar ret_die . 80.Pp 81Function 82.Fn dwarf_siblingof 83retrieves the sibling of the descriptor denoted by argument 84.Ar die , 85and stores it in the location pointed to by argument 86.Ar ret_die . 87If argument 88.Ar die 89is NULL, the first debugging information entry descriptor for the 90current compilation unit will be returned. 91This function and function 92.Fn dwarf_child 93may be used together to traverse the tree of debugging information 94entry descriptors for a compilation unit. 95.Pp 96Function 97.Fn dwarf_offdie 98retrieves the debugging information entry descriptor at global offset 99.Ar offset 100in the 101.Dq .debug_info 102section of the object associated with argument 103.Ar dbg . 104The returned descriptor is written to the location pointed to by argument 105.Ar ret_die . 106.Ss Memory Management 107The memory area used for the 108.Vt Dwarf_Die 109descriptor returned in argument 110.Ar ret_die 111is allocated by the 112.Lb libdwarf . 113Application code should use function 114.Fn dwarf_dealloc 115with the allocation type 116.Dv DW_DLA_DIE 117to free the memory area when the 118.Vt Dwarf_Die 119descriptor is no longer needed. 120.Sh RETURN VALUES 121These functions return the following values: 122.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY" 123.It Bq Er DW_DLV_OK 124The call succeeded. 125.It Bq Er DW_DLV_ERROR 126The requested operation failed. 127Additional information about the error encountered will be recorded in 128argument 129.Ar err , 130if it is not NULL. 131.It Bq Er DW_DLV_NO_ENTRY 132For functions 133.Fn dwarf_child 134and 135.Fn dwarf_siblingof , 136the descriptor denoted by argument 137.Ar die 138did not have a child or sibling. 139For function 140.Fn dwarf_offdie , 141there was no debugging information entry at the offset specified by 142argument 143.Ar offset . 144.El 145.Sh ERRORS 146These functions may fail with the following errors: 147.Bl -tag -width ".Bq Er DW_DLE_DIE_NO_CU_CONTEXT" 148.It Bq Er DW_DLE_ARGUMENT 149Arguments 150.Ar dbg , 151.Ar die 152or 153.Ar ret_die 154were NULL. 155.It Bq Er DW_DLE_DIE_NO_CU_CONTEXT 156Argument 157.Ar dbg 158was not associated with a compilation unit. 159.It Bq Er DW_DLE_NO_ENTRY 160The descriptor denoted by argument 161.Ar die 162had no child or sibling, or there was no DWARF debugging information 163entry at the offset specified by argument 164.Va offset . 165.El 166.Sh EXAMPLES 167To retrieve the first DWARF Debugging Information Entry descriptor for 168the first compilation unit associated with a 169.Vt Dwarf_Debug 170instance, and to traverse all its children, use: 171.Bd -literal -offset indent 172Dwarf_Debug dbg; 173Dwarf_Die die, die0; 174Dwarf_Error de; 175 176\&... allocate dbg using dwarf_init() etc ... 177 178if (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) != 179 DW_DLV_OK) 180 errx(EXIT_FAILURE, "dwarf_next_cu_header: %s", 181 dwarf_errmsg(de)); 182 183/* Get the first DIE for the current compilation unit. */ 184die = NULL; 185if (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK) 186 errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de)); 187 188/* Get the first child of this DIE. */ 189die = die0; 190if (dwarf_child(die, &die0, &de) != DW_DLV_OK) 191 errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de)); 192 193/* Get the rest of children. */ 194do { 195 die = die0; 196 if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR) 197 errx(EXIT_FAILURE, "dwarf_siblingof: %s", 198 dwarf_errmsg(de)); 199} while (die0 != NULL); 200.Ed 201.Sh SEE ALSO 202.Xr dwarf 3 , 203.Xr dwarf_errmsg 3 , 204.Xr dwarf_next_cu_header 3 205