1*5ac3bc71Schristos.\" $NetBSD: dwarf_child.3,v 1.6 2024/03/03 17:37:30 christos Exp $ 2e81373b4Schristos.\" 342bd3019Schristos.\" Copyright (c) 2010,2014 Kai Wang 49dd9d0cfSchristos.\" All rights reserved. 59dd9d0cfSchristos.\" 69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 89dd9d0cfSchristos.\" are met: 99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 109dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 129dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 139dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 149dd9d0cfSchristos.\" 159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 189dd9d0cfSchristos.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 259dd9d0cfSchristos.\" SUCH DAMAGE. 269dd9d0cfSchristos.\" 27cdbf1fe1Sjkoshy.\" Id: dwarf_child.3 3961 2022-03-12 15:13:22Z jkoshy 289dd9d0cfSchristos.\" 2942bd3019Schristos.Dd December 21, 2014 309dd9d0cfSchristos.Dt DWARF_CHILD 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_child , 3442bd3019Schristos.Nm dwarf_offdie , 3542bd3019Schristos.Nm dwarf_offdie_b , 369dd9d0cfSchristos.Nm dwarf_siblingof , 3742bd3019Schristos.Nm dwarf_siblingof_b 389dd9d0cfSchristos.Nd retrieve DWARF Debugging Information Entry descriptors 399dd9d0cfSchristos.Sh LIBRARY 409dd9d0cfSchristos.Lb libdwarf 419dd9d0cfSchristos.Sh SYNOPSIS 429dd9d0cfSchristos.In libdwarf.h 439dd9d0cfSchristos.Ft int 449dd9d0cfSchristos.Fn dwarf_child "Dwarf_Die die" "Dwarf_Die *ret_die" "Dwarf_Error *err" 459dd9d0cfSchristos.Ft int 4642bd3019Schristos.Fo dwarf_offdie 4742bd3019Schristos.Fa "Dwarf_Debug dbg" 4842bd3019Schristos.Fa "Dwarf_Off offset" 4942bd3019Schristos.Fa "Dwarf_Die *ret_die" 5042bd3019Schristos.Fa "Dwarf_Error *err" 5142bd3019Schristos.Fc 5242bd3019Schristos.Ft int 5342bd3019Schristos.Fo dwarf_offdie_b 5442bd3019Schristos.Fa "Dwarf_Debug dbg" 5542bd3019Schristos.Fa "Dwarf_Off offset" 5642bd3019Schristos.Fa "Dwarf_Bool is_info" 5742bd3019Schristos.Fa "Dwarf_Die *ret_die" 5842bd3019Schristos.Fa "Dwarf_Error *err" 5942bd3019Schristos.Fc 6042bd3019Schristos.Ft int 619dd9d0cfSchristos.Fo dwarf_siblingof 629dd9d0cfSchristos.Fa "Dwarf_Debug dbg" 639dd9d0cfSchristos.Fa "Dwarf_Die die" 649dd9d0cfSchristos.Fa "Dwarf_Die *ret_die" 659dd9d0cfSchristos.Fa "Dwarf_Error *err" 669dd9d0cfSchristos.Fc 679dd9d0cfSchristos.Ft int 6842bd3019Schristos.Fo dwarf_siblingof_b 699dd9d0cfSchristos.Fa "Dwarf_Debug dbg" 7042bd3019Schristos.Fa "Dwarf_Die die" 719dd9d0cfSchristos.Fa "Dwarf_Die *ret_die" 7242bd3019Schristos.Fa "Dwarf_Bool is_info" 739dd9d0cfSchristos.Fa "Dwarf_Error *err" 749dd9d0cfSchristos.Fc 759dd9d0cfSchristos.Sh DESCRIPTION 769dd9d0cfSchristosThese functions are used to retrieve and traverse DWARF 779dd9d0cfSchristosDebugging Information Entry (DIE) descriptors associated with 789dd9d0cfSchristosa compilation unit. 799dd9d0cfSchristosThese descriptors are arranged in the form of a tree, traversable 809dd9d0cfSchristosusing 819dd9d0cfSchristos.Dq child 829dd9d0cfSchristosand 839dd9d0cfSchristos.Dq sibling 849dd9d0cfSchristoslinks; see 859dd9d0cfSchristos.Xr dwarf 3 869dd9d0cfSchristosfor more information. 879dd9d0cfSchristosDWARF Debugging Information Entry descriptors are represented 889dd9d0cfSchristosby the 899dd9d0cfSchristos.Vt Dwarf_Die 909dd9d0cfSchristosopaque type. 919dd9d0cfSchristos.Pp 929dd9d0cfSchristosFunction 939dd9d0cfSchristos.Fn dwarf_child 949dd9d0cfSchristosretrieves the child of descriptor denoted by argument 95cdbf1fe1Sjkoshy.Fa die , 969dd9d0cfSchristosand stores it in the location pointed to by argument 97cdbf1fe1Sjkoshy.Fa ret_die . 989dd9d0cfSchristos.Pp 999dd9d0cfSchristosFunction 1009dd9d0cfSchristos.Fn dwarf_siblingof 1019dd9d0cfSchristosretrieves the sibling of the descriptor denoted by argument 102cdbf1fe1Sjkoshy.Fa die , 1039dd9d0cfSchristosand stores it in the location pointed to by argument 104cdbf1fe1Sjkoshy.Fa ret_die . 1059dd9d0cfSchristosIf argument 106cdbf1fe1Sjkoshy.Fa die 107cdbf1fe1Sjkoshyis 108cdbf1fe1Sjkoshy.Dv NULL , 109cdbf1fe1Sjkoshythe first debugging information entry descriptor for the 1109dd9d0cfSchristoscurrent compilation unit will be returned. 1119dd9d0cfSchristosThis function and function 1129dd9d0cfSchristos.Fn dwarf_child 1139dd9d0cfSchristosmay be used together to traverse the tree of debugging information 1149dd9d0cfSchristosentry descriptors for a compilation unit. 1159dd9d0cfSchristos.Pp 1169dd9d0cfSchristosFunction 11742bd3019Schristos.Fn dwarf_siblingof_b 11842bd3019Schristosis identical to the function 11942bd3019Schristos.Fn dwarf_siblingof 12042bd3019Schristosexcept that it can retrieve the sibling descriptor from either the 12142bd3019Schristoscurrent compilation unit or type unit. 12242bd3019SchristosIf argument 123cdbf1fe1Sjkoshy.Fa is_info 12442bd3019Schristosis non-zero, the function behaves identically to function 12542bd3019Schristos.Fn dwarf_siblingof . 12642bd3019SchristosIf argument 127cdbf1fe1Sjkoshy.Fa is_info 12842bd3019Schristosis zero, the descriptor referred by argument 129cdbf1fe1Sjkoshy.Fa die 13042bd3019Schristosshould be associated with a debugging information entry in the 13142bd3019Schristostype unit. 13242bd3019SchristosThe function will store the sibling of the descriptor in the location 13342bd3019Schristospointed to by argument 134cdbf1fe1Sjkoshy.Fa ret_die . 13542bd3019SchristosIf argument 136cdbf1fe1Sjkoshy.Fa is_info 13742bd3019Schristosis zero and argument 138cdbf1fe1Sjkoshy.Fa die 13942bd3019Schristosis 14042bd3019Schristos.Dv NULL , 14142bd3019Schristosthe first debugging information entry descriptor for the 14242bd3019Schristoscurrent type unit will be returned. 14342bd3019Schristos.Pp 14442bd3019SchristosFunction 1459dd9d0cfSchristos.Fn dwarf_offdie 1469dd9d0cfSchristosretrieves the debugging information entry descriptor at global offset 147cdbf1fe1Sjkoshy.Fa offset 1489dd9d0cfSchristosin the 1499dd9d0cfSchristos.Dq .debug_info 1509dd9d0cfSchristossection of the object associated with argument 151cdbf1fe1Sjkoshy.Fa dbg . 1529dd9d0cfSchristosThe returned descriptor is written to the location pointed to by argument 153cdbf1fe1Sjkoshy.Fa ret_die . 15442bd3019Schristos.Pp 15542bd3019SchristosFunction 15642bd3019Schristos.Fn dwarf_offdie_b 15742bd3019Schristosis identical to the function 15842bd3019Schristos.Fn dwarf_offdie 15942bd3019Schristosexcept that it can retrieve the debugging information entry descriptor at 16042bd3019Schristosglobal offset 161cdbf1fe1Sjkoshy.Fa offset 16242bd3019Schristosfrom either of the 16342bd3019Schristos.Dq .debug_info 16442bd3019Schristosand 16542bd3019Schristos.Dq .debug_types 16642bd3019Schristossections of the object associated with argument 167cdbf1fe1Sjkoshy.Fa dbg . 16842bd3019SchristosIf argument 169cdbf1fe1Sjkoshy.Fa is_info 17042bd3019Schristosis non-zero, the function will retrieve the debugging information 17142bd3019Schristosentry from the 17242bd3019Schristos.Dq .debug_info 17342bd3019Schristossection, otherwise the function will retrieve the debugging 17442bd3019Schristosinformation entry from the 17542bd3019Schristos.Dq .debug_types 17642bd3019Schristossection. 17742bd3019SchristosThe returned descriptor is written to the location pointed to by argument 178cdbf1fe1Sjkoshy.Fa ret_die . 1799dd9d0cfSchristos.Ss Memory Management 1809dd9d0cfSchristosThe memory area used for the 1819dd9d0cfSchristos.Vt Dwarf_Die 1829dd9d0cfSchristosdescriptor returned in argument 183cdbf1fe1Sjkoshy.Fa ret_die 1849dd9d0cfSchristosis allocated by the 1859dd9d0cfSchristos.Lb libdwarf . 1869dd9d0cfSchristosApplication code should use function 1879dd9d0cfSchristos.Fn dwarf_dealloc 1889dd9d0cfSchristoswith the allocation type 1899dd9d0cfSchristos.Dv DW_DLA_DIE 1909dd9d0cfSchristosto free the memory area when the 1919dd9d0cfSchristos.Vt Dwarf_Die 1929dd9d0cfSchristosdescriptor is no longer needed. 1939dd9d0cfSchristos.Sh RETURN VALUES 1949dd9d0cfSchristosThese functions return the following values: 1959dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY" 1969dd9d0cfSchristos.It Bq Er DW_DLV_OK 1979dd9d0cfSchristosThe call succeeded. 1989dd9d0cfSchristos.It Bq Er DW_DLV_ERROR 1999dd9d0cfSchristosThe requested operation failed. 2009dd9d0cfSchristosAdditional information about the error encountered will be recorded in 2019dd9d0cfSchristosargument 202cdbf1fe1Sjkoshy.Fa err , 203cdbf1fe1Sjkoshyif it is not 204cdbf1fe1Sjkoshy.Dv NULL . 2059dd9d0cfSchristos.It Bq Er DW_DLV_NO_ENTRY 2069dd9d0cfSchristosFor functions 20742bd3019Schristos.Fn dwarf_child , 20842bd3019Schristos.Fn dwarf_siblingof 2099dd9d0cfSchristosand 21042bd3019Schristos.Fn dwarf_siblingof_b , 2119dd9d0cfSchristosthe descriptor denoted by argument 212cdbf1fe1Sjkoshy.Fa die 2139dd9d0cfSchristosdid not have a child or sibling. 21442bd3019Schristos.Pp 21542bd3019SchristosFor functions 21642bd3019Schristos.Fn dwarf_offdie 21742bd3019Schristosand 21842bd3019Schristos.Fn dwarf_offdie_b , 2199dd9d0cfSchristosthere was no debugging information entry at the offset specified by 2209dd9d0cfSchristosargument 221cdbf1fe1Sjkoshy.Fa offset . 2229dd9d0cfSchristos.El 2239dd9d0cfSchristos.Sh EXAMPLES 2249dd9d0cfSchristosTo retrieve the first DWARF Debugging Information Entry descriptor for 2259dd9d0cfSchristosthe first compilation unit associated with a 2269dd9d0cfSchristos.Vt Dwarf_Debug 2279dd9d0cfSchristosinstance, and to traverse all its children, use: 2289dd9d0cfSchristos.Bd -literal -offset indent 2299dd9d0cfSchristosDwarf_Debug dbg; 2309dd9d0cfSchristosDwarf_Die die, die0; 2319dd9d0cfSchristosDwarf_Error de; 2329dd9d0cfSchristos 2339dd9d0cfSchristos\&... allocate dbg using dwarf_init() etc ... 2349dd9d0cfSchristos 2359dd9d0cfSchristosif (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) != 2369dd9d0cfSchristos DW_DLV_OK) 2379dd9d0cfSchristos errx(EXIT_FAILURE, "dwarf_next_cu_header: %s", 2389dd9d0cfSchristos dwarf_errmsg(de)); 2399dd9d0cfSchristos 2409dd9d0cfSchristos/* Get the first DIE for the current compilation unit. */ 2419dd9d0cfSchristosdie = NULL; 2429dd9d0cfSchristosif (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK) 2439dd9d0cfSchristos errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de)); 2449dd9d0cfSchristos 2459dd9d0cfSchristos/* Get the first child of this DIE. */ 2469dd9d0cfSchristosdie = die0; 2479dd9d0cfSchristosif (dwarf_child(die, &die0, &de) != DW_DLV_OK) 2489dd9d0cfSchristos errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de)); 2499dd9d0cfSchristos 2509dd9d0cfSchristos/* Get the rest of children. */ 2519dd9d0cfSchristosdo { 2529dd9d0cfSchristos die = die0; 2539dd9d0cfSchristos if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR) 2549dd9d0cfSchristos errx(EXIT_FAILURE, "dwarf_siblingof: %s", 2559dd9d0cfSchristos dwarf_errmsg(de)); 2569dd9d0cfSchristos} while (die0 != NULL); 2579dd9d0cfSchristos.Ed 258604b0842Sjkoshy.Sh ERRORS 259604b0842SjkoshyThese functions may fail with the following errors: 260604b0842Sjkoshy.Bl -tag -width ".Bq Er DW_DLE_DIE_NO_CU_CONTEXT" 261604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT 262604b0842SjkoshyArguments 263cdbf1fe1Sjkoshy.Fa dbg , 264cdbf1fe1Sjkoshy.Fa die 265604b0842Sjkoshyor 266cdbf1fe1Sjkoshy.Fa ret_die 267cdbf1fe1Sjkoshywere 268cdbf1fe1Sjkoshy.Dv NULL . 269604b0842Sjkoshy.It Bq Er DW_DLE_DIE_NO_CU_CONTEXT 270604b0842SjkoshyArgument 271cdbf1fe1Sjkoshy.Fa dbg 272604b0842Sjkoshywas not associated with a compilation unit. 273604b0842Sjkoshy.It Bq Er DW_DLE_NO_ENTRY 274604b0842SjkoshyThe descriptor denoted by argument 275cdbf1fe1Sjkoshy.Fa die 276604b0842Sjkoshyhad no child or sibling, or there was no DWARF debugging information 277604b0842Sjkoshyentry at the offset specified by argument 278604b0842Sjkoshy.Va offset . 279604b0842Sjkoshy.El 2809dd9d0cfSchristos.Sh SEE ALSO 2819dd9d0cfSchristos.Xr dwarf 3 , 2829dd9d0cfSchristos.Xr dwarf_errmsg 3 , 283604b0842Sjkoshy.Xr dwarf_get_die_infotypes_flag 3 , 2849dd9d0cfSchristos.Xr dwarf_next_cu_header 3 285