1*0a6a1f1dSLionel Sambuc.\" $NetBSD: dwarf_child.3,v 1.2 2014/03/09 16:58:03 christos Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2010 Kai Wang 4*0a6a1f1dSLionel Sambuc.\" All rights reserved. 5*0a6a1f1dSLionel Sambuc.\" 6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 8*0a6a1f1dSLionel Sambuc.\" are met: 9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 10*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 12*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 13*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 14*0a6a1f1dSLionel Sambuc.\" 15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*0a6a1f1dSLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*0a6a1f1dSLionel Sambuc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*0a6a1f1dSLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*0a6a1f1dSLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*0a6a1f1dSLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*0a6a1f1dSLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*0a6a1f1dSLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*0a6a1f1dSLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE. 26*0a6a1f1dSLionel Sambuc.\" 27*0a6a1f1dSLionel Sambuc.\" Id: dwarf_child.3 2122 2011-11-09 15:35:14Z jkoshy 28*0a6a1f1dSLionel Sambuc.\" 29*0a6a1f1dSLionel Sambuc.Dd November 9, 2011 30*0a6a1f1dSLionel Sambuc.Os 31*0a6a1f1dSLionel Sambuc.Dt DWARF_CHILD 3 32*0a6a1f1dSLionel Sambuc.Sh NAME 33*0a6a1f1dSLionel Sambuc.Nm dwarf_child , 34*0a6a1f1dSLionel Sambuc.Nm dwarf_siblingof , 35*0a6a1f1dSLionel Sambuc.Nm dwarf_offdie 36*0a6a1f1dSLionel Sambuc.Nd retrieve DWARF Debugging Information Entry descriptors 37*0a6a1f1dSLionel Sambuc.Sh LIBRARY 38*0a6a1f1dSLionel Sambuc.Lb libdwarf 39*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 40*0a6a1f1dSLionel Sambuc.In libdwarf.h 41*0a6a1f1dSLionel Sambuc.Ft int 42*0a6a1f1dSLionel Sambuc.Fn dwarf_child "Dwarf_Die die" "Dwarf_Die *ret_die" "Dwarf_Error *err" 43*0a6a1f1dSLionel Sambuc.Ft int 44*0a6a1f1dSLionel Sambuc.Fo dwarf_siblingof 45*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Debug dbg" 46*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Die die" 47*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Die *ret_die" 48*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err" 49*0a6a1f1dSLionel Sambuc.Fc 50*0a6a1f1dSLionel Sambuc.Ft int 51*0a6a1f1dSLionel Sambuc.Fo dwarf_offdie 52*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Debug dbg" 53*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Off offset" 54*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Die *ret_die" 55*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err" 56*0a6a1f1dSLionel Sambuc.Fc 57*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 58*0a6a1f1dSLionel SambucThese functions are used to retrieve and traverse DWARF 59*0a6a1f1dSLionel SambucDebugging Information Entry (DIE) descriptors associated with 60*0a6a1f1dSLionel Sambuca compilation unit. 61*0a6a1f1dSLionel SambucThese descriptors are arranged in the form of a tree, traversable 62*0a6a1f1dSLionel Sambucusing 63*0a6a1f1dSLionel Sambuc.Dq child 64*0a6a1f1dSLionel Sambucand 65*0a6a1f1dSLionel Sambuc.Dq sibling 66*0a6a1f1dSLionel Sambuclinks; see 67*0a6a1f1dSLionel Sambuc.Xr dwarf 3 68*0a6a1f1dSLionel Sambucfor more information. 69*0a6a1f1dSLionel SambucDWARF Debugging Information Entry descriptors are represented 70*0a6a1f1dSLionel Sambucby the 71*0a6a1f1dSLionel Sambuc.Vt Dwarf_Die 72*0a6a1f1dSLionel Sambucopaque type. 73*0a6a1f1dSLionel Sambuc.Pp 74*0a6a1f1dSLionel SambucFunction 75*0a6a1f1dSLionel Sambuc.Fn dwarf_child 76*0a6a1f1dSLionel Sambucretrieves the child of descriptor denoted by argument 77*0a6a1f1dSLionel Sambuc.Ar die , 78*0a6a1f1dSLionel Sambucand stores it in the location pointed to by argument 79*0a6a1f1dSLionel Sambuc.Ar ret_die . 80*0a6a1f1dSLionel Sambuc.Pp 81*0a6a1f1dSLionel SambucFunction 82*0a6a1f1dSLionel Sambuc.Fn dwarf_siblingof 83*0a6a1f1dSLionel Sambucretrieves the sibling of the descriptor denoted by argument 84*0a6a1f1dSLionel Sambuc.Ar die , 85*0a6a1f1dSLionel Sambucand stores it in the location pointed to by argument 86*0a6a1f1dSLionel Sambuc.Ar ret_die . 87*0a6a1f1dSLionel SambucIf argument 88*0a6a1f1dSLionel Sambuc.Ar die 89*0a6a1f1dSLionel Sambucis NULL, the first debugging information entry descriptor for the 90*0a6a1f1dSLionel Sambuccurrent compilation unit will be returned. 91*0a6a1f1dSLionel SambucThis function and function 92*0a6a1f1dSLionel Sambuc.Fn dwarf_child 93*0a6a1f1dSLionel Sambucmay be used together to traverse the tree of debugging information 94*0a6a1f1dSLionel Sambucentry descriptors for a compilation unit. 95*0a6a1f1dSLionel Sambuc.Pp 96*0a6a1f1dSLionel SambucFunction 97*0a6a1f1dSLionel Sambuc.Fn dwarf_offdie 98*0a6a1f1dSLionel Sambucretrieves the debugging information entry descriptor at global offset 99*0a6a1f1dSLionel Sambuc.Ar offset 100*0a6a1f1dSLionel Sambucin the 101*0a6a1f1dSLionel Sambuc.Dq .debug_info 102*0a6a1f1dSLionel Sambucsection of the object associated with argument 103*0a6a1f1dSLionel Sambuc.Ar dbg . 104*0a6a1f1dSLionel SambucThe returned descriptor is written to the location pointed to by argument 105*0a6a1f1dSLionel Sambuc.Ar ret_die . 106*0a6a1f1dSLionel Sambuc.Ss Memory Management 107*0a6a1f1dSLionel SambucThe memory area used for the 108*0a6a1f1dSLionel Sambuc.Vt Dwarf_Die 109*0a6a1f1dSLionel Sambucdescriptor returned in argument 110*0a6a1f1dSLionel Sambuc.Ar ret_die 111*0a6a1f1dSLionel Sambucis allocated by the 112*0a6a1f1dSLionel Sambuc.Lb libdwarf . 113*0a6a1f1dSLionel SambucApplication code should use function 114*0a6a1f1dSLionel Sambuc.Fn dwarf_dealloc 115*0a6a1f1dSLionel Sambucwith the allocation type 116*0a6a1f1dSLionel Sambuc.Dv DW_DLA_DIE 117*0a6a1f1dSLionel Sambucto free the memory area when the 118*0a6a1f1dSLionel Sambuc.Vt Dwarf_Die 119*0a6a1f1dSLionel Sambucdescriptor is no longer needed. 120*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES 121*0a6a1f1dSLionel SambucThese functions return the following values: 122*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY" 123*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLV_OK 124*0a6a1f1dSLionel SambucThe call succeeded. 125*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLV_ERROR 126*0a6a1f1dSLionel SambucThe requested operation failed. 127*0a6a1f1dSLionel SambucAdditional information about the error encountered will be recorded in 128*0a6a1f1dSLionel Sambucargument 129*0a6a1f1dSLionel Sambuc.Ar err , 130*0a6a1f1dSLionel Sambucif it is not NULL. 131*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLV_NO_ENTRY 132*0a6a1f1dSLionel SambucFor functions 133*0a6a1f1dSLionel Sambuc.Fn dwarf_child 134*0a6a1f1dSLionel Sambucand 135*0a6a1f1dSLionel Sambuc.Fn dwarf_siblingof , 136*0a6a1f1dSLionel Sambucthe descriptor denoted by argument 137*0a6a1f1dSLionel Sambuc.Ar die 138*0a6a1f1dSLionel Sambucdid not have a child or sibling. 139*0a6a1f1dSLionel SambucFor function 140*0a6a1f1dSLionel Sambuc.Fn dwarf_offdie , 141*0a6a1f1dSLionel Sambucthere was no debugging information entry at the offset specified by 142*0a6a1f1dSLionel Sambucargument 143*0a6a1f1dSLionel Sambuc.Ar offset . 144*0a6a1f1dSLionel Sambuc.El 145*0a6a1f1dSLionel Sambuc.Sh ERRORS 146*0a6a1f1dSLionel SambucThese functions may fail with the following errors: 147*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLE_DIE_NO_CU_CONTEXT" 148*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT 149*0a6a1f1dSLionel SambucArguments 150*0a6a1f1dSLionel Sambuc.Ar dbg , 151*0a6a1f1dSLionel Sambuc.Ar die 152*0a6a1f1dSLionel Sambucor 153*0a6a1f1dSLionel Sambuc.Ar ret_die 154*0a6a1f1dSLionel Sambucwere NULL. 155*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_DIE_NO_CU_CONTEXT 156*0a6a1f1dSLionel SambucArgument 157*0a6a1f1dSLionel Sambuc.Ar dbg 158*0a6a1f1dSLionel Sambucwas not associated with a compilation unit. 159*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_NO_ENTRY 160*0a6a1f1dSLionel SambucThe descriptor denoted by argument 161*0a6a1f1dSLionel Sambuc.Ar die 162*0a6a1f1dSLionel Sambuchad no child or sibling, or there was no DWARF debugging information 163*0a6a1f1dSLionel Sambucentry at the offset specified by argument 164*0a6a1f1dSLionel Sambuc.Va offset . 165*0a6a1f1dSLionel Sambuc.El 166*0a6a1f1dSLionel Sambuc.Sh EXAMPLES 167*0a6a1f1dSLionel SambucTo retrieve the first DWARF Debugging Information Entry descriptor for 168*0a6a1f1dSLionel Sambucthe first compilation unit associated with a 169*0a6a1f1dSLionel Sambuc.Vt Dwarf_Debug 170*0a6a1f1dSLionel Sambucinstance, and to traverse all its children, use: 171*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 172*0a6a1f1dSLionel SambucDwarf_Debug dbg; 173*0a6a1f1dSLionel SambucDwarf_Die die, die0; 174*0a6a1f1dSLionel SambucDwarf_Error de; 175*0a6a1f1dSLionel Sambuc 176*0a6a1f1dSLionel Sambuc\&... allocate dbg using dwarf_init() etc ... 177*0a6a1f1dSLionel Sambuc 178*0a6a1f1dSLionel Sambucif (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) != 179*0a6a1f1dSLionel Sambuc DW_DLV_OK) 180*0a6a1f1dSLionel Sambuc errx(EXIT_FAILURE, "dwarf_next_cu_header: %s", 181*0a6a1f1dSLionel Sambuc dwarf_errmsg(de)); 182*0a6a1f1dSLionel Sambuc 183*0a6a1f1dSLionel Sambuc/* Get the first DIE for the current compilation unit. */ 184*0a6a1f1dSLionel Sambucdie = NULL; 185*0a6a1f1dSLionel Sambucif (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK) 186*0a6a1f1dSLionel Sambuc errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de)); 187*0a6a1f1dSLionel Sambuc 188*0a6a1f1dSLionel Sambuc/* Get the first child of this DIE. */ 189*0a6a1f1dSLionel Sambucdie = die0; 190*0a6a1f1dSLionel Sambucif (dwarf_child(die, &die0, &de) != DW_DLV_OK) 191*0a6a1f1dSLionel Sambuc errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de)); 192*0a6a1f1dSLionel Sambuc 193*0a6a1f1dSLionel Sambuc/* Get the rest of children. */ 194*0a6a1f1dSLionel Sambucdo { 195*0a6a1f1dSLionel Sambuc die = die0; 196*0a6a1f1dSLionel Sambuc if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR) 197*0a6a1f1dSLionel Sambuc errx(EXIT_FAILURE, "dwarf_siblingof: %s", 198*0a6a1f1dSLionel Sambuc dwarf_errmsg(de)); 199*0a6a1f1dSLionel Sambuc} while (die0 != NULL); 200*0a6a1f1dSLionel Sambuc.Ed 201*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 202*0a6a1f1dSLionel Sambuc.Xr dwarf 3 , 203*0a6a1f1dSLionel Sambuc.Xr dwarf_errmsg 3 , 204*0a6a1f1dSLionel Sambuc.Xr dwarf_next_cu_header 3 205