1*5ac3bc71Schristos.\" $NetBSD: dwarf_next_cu_header.3,v 1.6 2024/03/03 17:37:31 christos Exp $ 2e81373b4Schristos.\" 3*5ac3bc71Schristos.\" Copyright (c) 2010,2014,2023 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.\" 27*5ac3bc71Schristos.\" Id: dwarf_next_cu_header.3 4013 2023-10-14 22:40:50Z kaiwang27 289dd9d0cfSchristos.\" 29*5ac3bc71Schristos.Dd October 15, 2023 309dd9d0cfSchristos.Dt DWARF_NEXT_CU_HEADER 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_next_cu_header , 3442bd3019Schristos.Nm dwarf_next_cu_header_b , 35*5ac3bc71Schristos.Nm dwarf_next_cu_header_c , 36*5ac3bc71Schristos.Nm dwarf_next_cu_header_d 379dd9d0cfSchristos.Nd step through compilation units in a DWARF debug context 389dd9d0cfSchristos.Sh LIBRARY 399dd9d0cfSchristos.Lb libdwarf 409dd9d0cfSchristos.Sh SYNOPSIS 419dd9d0cfSchristos.In libdwarf.h 429dd9d0cfSchristos.Ft int 439dd9d0cfSchristos.Fo dwarf_next_cu_header 449dd9d0cfSchristos.Fa "Dwarf_Debug dbg" 459dd9d0cfSchristos.Fa "Dwarf_Unsigned *cu_length" 469dd9d0cfSchristos.Fa "Dwarf_Half *cu_version" 479dd9d0cfSchristos.Fa "Dwarf_Off *cu_abbrev_offset" 489dd9d0cfSchristos.Fa "Dwarf_Half *cu_pointer_size" 499dd9d0cfSchristos.Fa "Dwarf_Unsigned *cu_next_offset" 509dd9d0cfSchristos.Fa "Dwarf_Error *err" 519dd9d0cfSchristos.Fc 529dd9d0cfSchristos.Ft int 539dd9d0cfSchristos.Fo dwarf_next_cu_header_b 549dd9d0cfSchristos.Fa "Dwarf_Debug dbg" 559dd9d0cfSchristos.Fa "Dwarf_Unsigned *cu_length" 569dd9d0cfSchristos.Fa "Dwarf_Half *cu_version" 579dd9d0cfSchristos.Fa "Dwarf_Off *cu_abbrev_offset" 589dd9d0cfSchristos.Fa "Dwarf_Half *cu_pointer_size" 599dd9d0cfSchristos.Fa "Dwarf_Half *cu_offset_size" 609dd9d0cfSchristos.Fa "Dwarf_Half *cu_extension_size" 619dd9d0cfSchristos.Fa "Dwarf_Unsigned *cu_next_offset" 629dd9d0cfSchristos.Fa "Dwarf_Error *err" 639dd9d0cfSchristos.Fc 6442bd3019Schristos.Ft int 6542bd3019Schristos.Fo dwarf_next_cu_header_c 6642bd3019Schristos.Fa "Dwarf_Debug dbg" 6742bd3019Schristos.Fa "Dwarf_Bool is_info" 6842bd3019Schristos.Fa "Dwarf_Unsigned *cu_length" 6942bd3019Schristos.Fa "Dwarf_Half *cu_version" 7042bd3019Schristos.Fa "Dwarf_Off *cu_abbrev_offset" 7142bd3019Schristos.Fa "Dwarf_Half *cu_pointer_size" 7242bd3019Schristos.Fa "Dwarf_Half *cu_offset_size" 7342bd3019Schristos.Fa "Dwarf_Half *cu_extension_size" 7442bd3019Schristos.Fa "Dwarf_Sig8 *type_signature" 7542bd3019Schristos.Fa "Dwarf_Unsigned *type_offset" 7642bd3019Schristos.Fa "Dwarf_Unsigned *cu_next_offset" 7742bd3019Schristos.Fa "Dwarf_Error *err" 7842bd3019Schristos.Fc 79*5ac3bc71Schristos.Ft int 80*5ac3bc71Schristos.Fo dwarf_next_cu_header_d 81*5ac3bc71Schristos.Fa "Dwarf_Debug dbg" 82*5ac3bc71Schristos.Fa "Dwarf_Bool is_info" 83*5ac3bc71Schristos.Fa "Dwarf_Unsigned *cu_length" 84*5ac3bc71Schristos.Fa "Dwarf_Half *cu_version" 85*5ac3bc71Schristos.Fa "Dwarf_Off *cu_abbrev_offset" 86*5ac3bc71Schristos.Fa "Dwarf_Half *cu_pointer_size" 87*5ac3bc71Schristos.Fa "Dwarf_Half *cu_offset_size" 88*5ac3bc71Schristos.Fa "Dwarf_Half *cu_extension_size" 89*5ac3bc71Schristos.Fa "Dwarf_Sig8 *type_signature" 90*5ac3bc71Schristos.Fa "Dwarf_Unsigned *type_offset" 91*5ac3bc71Schristos.Fa "Dwarf_Unsigned *cu_next_offset" 92*5ac3bc71Schristos.Fa "Dwarf_Half *cu_type" 93*5ac3bc71Schristos.Fa "Dwarf_Error *err" 94*5ac3bc71Schristos.Fc 959dd9d0cfSchristos.Sh DESCRIPTION 9642bd3019SchristosThese functions are used to step through compilation or type units 979dd9d0cfSchristosassociated with a DWARF debug context, optionally returning information 989dd9d0cfSchristosabout the unit. 999dd9d0cfSchristos.Pp 1009dd9d0cfSchristosFunction 101*5ac3bc71Schristos.Fn dwarf_next_cu_header_d 1029dd9d0cfSchristosis the API recommended for new application code. 10342bd3019SchristosFunction 104*5ac3bc71Schristos.Fn dwarf_next_cu_header_c 105*5ac3bc71Schristoscan not return the unit type defined by the DWARF5 standard. 106*5ac3bc71SchristosFunction 10742bd3019Schristos.Fn dwarf_next_cu_header 10842bd3019Schristosand 10942bd3019Schristos.Fn dwarf_next_cu_header_b 11042bd3019Schristoscan only operate on compilation units associated with the 11142bd3019Schristos.Dq \&.debug_info 11242bd3019Schristossection. 113*5ac3bc71SchristosThe earlier revisions are less general than function 114*5ac3bc71Schristos.Fn dwarf_next_cu_header_d , 11542bd3019Schristosand are deprecated for use by new application code. 11642bd3019Schristos.Pp 1179dd9d0cfSchristosArgument 118cdbf1fe1Sjkoshy.Fa dbg 1199dd9d0cfSchristosshould reference a DWARF debug context allocated using 1209dd9d0cfSchristos.Xr dwarf_init 3 . 12142bd3019SchristosIf argument 122cdbf1fe1Sjkoshy.Fa is_info 12342bd3019Schristosis set to 1, 12442bd3019Schristosthe function returns information for compilation units found in the 12542bd3019Schristos.Dq \&.debug_info 12642bd3019Schristossection. 12742bd3019SchristosIf argument 128cdbf1fe1Sjkoshy.Fa is_info 12942bd3019Schristosis set to 0, 13042bd3019Schristosthe function returns information for type units found in the 13142bd3019Schristos.Dq \&.debug_types 13242bd3019Schristossections. 1339dd9d0cfSchristosArgument 134cdbf1fe1Sjkoshy.Fa cu_length 1359dd9d0cfSchristosshould point to a location that will be set to the 13642bd3019Schristoslength of the compilation or type unit. 1379dd9d0cfSchristosArgument 138cdbf1fe1Sjkoshy.Fa cu_version 1399dd9d0cfSchristosshould point to a location that will be set to the 14042bd3019Schristosversion number for the compilation or type unit. 1419dd9d0cfSchristosArgument 142cdbf1fe1Sjkoshy.Fa cu_abbrev_offset 1439dd9d0cfSchristosshould point to a location that will be set to the 1449dd9d0cfSchristosstarting offset (in the 1459dd9d0cfSchristos.Dq .debug_abbrev 1469dd9d0cfSchristossection) of the set of debugging information entry abbreviations 14742bd3019Schristosassociated with this compilation or type unit. 1489dd9d0cfSchristosArgument 149cdbf1fe1Sjkoshy.Fa cu_pointer_size 1509dd9d0cfSchristosshould point to a location that will be set to the 1519dd9d0cfSchristossize in bytes of an address for the machine architecture of the 1529dd9d0cfSchristosunderlying object being debugged. 1539dd9d0cfSchristosArgument 154cdbf1fe1Sjkoshy.Fa cu_offset_size 1559dd9d0cfSchristosshould point to a location that will be set to the 15642bd3019Schristossize in bytes for a DWARF offset in the compilation or type unit. 1579dd9d0cfSchristosArgument 158cdbf1fe1Sjkoshy.Fa cu_extension_size 1599dd9d0cfSchristosis only needed for processing MIPS/IRIX objects that use 1609dd9d0cfSchristosa non-standard DWARF format. 1619dd9d0cfSchristosIt should point to a location that will be set to 4 for normal 1629dd9d0cfSchristosobjects and to 0 for non-standard ones. 1639dd9d0cfSchristosArgument 164cdbf1fe1Sjkoshy.Fa type_signature 16542bd3019Schristosand 166cdbf1fe1Sjkoshy.Fa type_offset 16742bd3019Schristosis only needed for processing type units. 16842bd3019SchristosArgument 169cdbf1fe1Sjkoshy.Fa type_signature 17042bd3019Schristosshould point to a location that will be set to the 64-bit unique signature 17142bd3019Schristosof the type described in the type unit. 17242bd3019SchristosArgument 173cdbf1fe1Sjkoshy.Fa type_offset 17442bd3019Schristosshould point to a location that will be set to the offset of the debugging 17542bd3019Schristosinformation entry that describes the type. 17642bd3019SchristosArgument 177cdbf1fe1Sjkoshy.Fa cu_next_offset 1789dd9d0cfSchristosshould point to a location that will be set to the 1799dd9d0cfSchristosoffset of the next compilation unit header in the 1809dd9d0cfSchristos.Dq \&.debug_info 18142bd3019Schristossection, 18242bd3019Schristosor the offset of the next type unit header in the 18342bd3019Schristos.Dq \&.debug_types 1849dd9d0cfSchristossection. 1859dd9d0cfSchristosArgument 186*5ac3bc71Schristos.Fa cu_type 187*5ac3bc71Schristosshould point to a location that will be set to the 188*5ac3bc71Schristostype of the compilation unit. 189*5ac3bc71SchristosArgument 190cdbf1fe1Sjkoshy.Fa err 1919dd9d0cfSchristosshould point to a location that will hold an error descriptor in case 1929dd9d0cfSchristosof an error. 1939dd9d0cfSchristos.Pp 1949dd9d0cfSchristosFunction 195*5ac3bc71Schristos.Fn dwarf_next_cu_header_c 196*5ac3bc71Schristosis identical to function 197*5ac3bc71Schristos.Fn dwarf_next_cu_header_d 198*5ac3bc71Schristosexcept that it does not provide argument 199*5ac3bc71Schristos.Fa cu_type . 200*5ac3bc71Schristos.Pp 201*5ac3bc71SchristosFunction 20242bd3019Schristos.Fn dwarf_next_cu_header_b 20342bd3019Schristosis identical to function 20442bd3019Schristos.Fn dwarf_next_cu_header_c 20542bd3019Schristosexcept that it does not provide arguments 206cdbf1fe1Sjkoshy.Fa is_info , 207cdbf1fe1Sjkoshy.Fa type_signature 20842bd3019Schristosand 209cdbf1fe1Sjkoshy.Fa type_offset . 21042bd3019Schristos.Pp 21142bd3019SchristosFunction 2129dd9d0cfSchristos.Fn dwarf_next_cu_header 21342bd3019Schristosis identical to function 21442bd3019Schristos.Fn dwarf_next_cu_header_b 21542bd3019Schristosexcept that it does not provide arguments 216cdbf1fe1Sjkoshy.Fa cu_offset_size 21742bd3019Schristosand 218cdbf1fe1Sjkoshy.Fa cu_extension_size . 2199dd9d0cfSchristos.Pp 220cdbf1fe1SjkoshyA value of 221cdbf1fe1Sjkoshy.Dv NULL 222cdbf1fe1Sjkoshymay be used for any of the arguments 223cdbf1fe1Sjkoshy.Fa cu_length , 224cdbf1fe1Sjkoshy.Fa cu_version , 225cdbf1fe1Sjkoshy.Fa cu_abbrev_offset , 226cdbf1fe1Sjkoshy.Fa cu_pointer_size , 227cdbf1fe1Sjkoshy.Fa cu_offset_size , 228cdbf1fe1Sjkoshy.Fa cu_extension_size , 229cdbf1fe1Sjkoshy.Fa type_signature , 230cdbf1fe1Sjkoshy.Fa type_offset , 231*5ac3bc71Schristos.Fa cu_next_offset , 232*5ac3bc71Schristos.Fa cu_type 2339dd9d0cfSchristosand 234cdbf1fe1Sjkoshy.Fa err 2359dd9d0cfSchristosif the caller is not interested in the respective value. 2369dd9d0cfSchristos.Ss Iterating Through Compilation Units in a Debug Context 23742bd3019SchristosThe first call to function 23842bd3019Schristos.Fn dwarf_next_cu_header_c 23942bd3019Schristosfor a given debug context with argument 240cdbf1fe1Sjkoshy.Fa is_info 24142bd3019Schristosset to 1 will return information about the first 24242bd3019Schristoscompilation unit in the 24342bd3019Schristos.Dq \&.debug_info 24442bd3019Schristossection. 24542bd3019SchristosSubsequent calls to the function will iterate through the remaining 24642bd3019Schristoscompilation units in the section. 24742bd3019SchristosOn stepping past the last compilation unit in the section, 24842bd3019Schristosfunction 249*5ac3bc71Schristos.Fn dwarf_next_cu_header_d 25042bd3019Schristosreturns 2519dd9d0cfSchristos.Dv DW_DLV_NO_ENTRY 25242bd3019Schristosand resets its internal state. 25342bd3019SchristosThe next call to the function will restart from the first compilation 25442bd3019Schristosunit in the section. 25542bd3019Schristos.Ss Iterating Through Type Units in a Debug Context 25642bd3019SchristosWhen a DWARF debug context is allocated using 25742bd3019Schristos.Xr dwarf_init 3 , 25842bd3019Schristosan internal pointer associated with the context will point to the first 25942bd3019Schristos.Dq \&.debug_types 26042bd3019Schristossection found in the debug object. 26142bd3019SchristosThe first call to function 262*5ac3bc71Schristos.Fn dwarf_next_cu_header_d 26342bd3019Schristosfor the debug context with argument 264cdbf1fe1Sjkoshy.Fa is_info 26542bd3019Schristosset to 0 will return information about the first 26642bd3019Schristostype unit in that 26742bd3019Schristos.Dq \&.debug_types 26842bd3019Schristossection. 26942bd3019SchristosSubsequent calls to the function will iterate through the remaining 27042bd3019Schristostype units in the section. 27142bd3019SchristosOn stepping past the last type unit in the debug context, 27242bd3019Schristosfunction 273*5ac3bc71Schristos.Fn dwarf_next_cu_header_d 27442bd3019Schristosreturns 27542bd3019Schristos.Dv DW_DLV_NO_ENTRY 27642bd3019Schristosand resets its internal state. 27742bd3019SchristosThe next call to the function will restart from the first type 27842bd3019Schristosunit in the 27942bd3019Schristos.Dq \&.debug_types 28042bd3019Schristossection. 28142bd3019Schristos.Pp 28242bd3019SchristosIf the debug object contains multiple 28342bd3019Schristos.Dq \&.debug_types 28442bd3019Schristossections, the function 28542bd3019Schristos.Fn dwarf_next_types_section 28642bd3019Schristoscan be called to move the internal pointer to the next 28742bd3019Schristos.Dq \&.debug_types 28842bd3019Schristossection. 28942bd3019SchristosAs a result, subsequent calls of the function 290*5ac3bc71Schristos.Fn dwarf_next_cu_header_d 29142bd3019Schristoswill operate on the new 29242bd3019Schristos.Dq \&.debug_types 29342bd3019Schristossection. 29442bd3019SchristosFunction 29542bd3019Schristos.Fn dwarf_next_types_section 29642bd3019Schristosreturns 29742bd3019Schristos.Dv DW_DLV_NO_ENTRY 29842bd3019Schristoswhen there are no more 29942bd3019Schristos.Dq \&.debug_types 30042bd3019Schristossections left in the debug object. 3019dd9d0cfSchristos.Sh RETURN VALUES 3029dd9d0cfSchristosOn success, these functions return 3039dd9d0cfSchristos.Dv DW_DLV_OK . 3049dd9d0cfSchristosIn case of an error, they return 3059dd9d0cfSchristos.Dv DW_DLV_ERROR 3069dd9d0cfSchristosand set argument 307cdbf1fe1Sjkoshy.Fa err . 3089dd9d0cfSchristosWhen there are no more compilation units left to traverse, they return 3099dd9d0cfSchristos.Dv DW_DLV_NO_ENTRY . 3109dd9d0cfSchristos.Sh ERRORS 3119dd9d0cfSchristosThese functions can fail with the following error: 3129dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 3139dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT 3149dd9d0cfSchristosArgument 3159dd9d0cfSchristos.Va dbg 316cdbf1fe1Sjkoshywas 317cdbf1fe1Sjkoshy.Dv NULL . 3189dd9d0cfSchristos.El 3199dd9d0cfSchristos.Sh SEE ALSO 3209dd9d0cfSchristos.Xr dwarf 3 , 3219dd9d0cfSchristos.Xr dwarf_get_cu_die_offset_given_cu_header_offset 3 , 3229dd9d0cfSchristos.Xr dwarf_init 3 , 32342bd3019Schristos.Xr dwarf_next_types_section 3 , 3249dd9d0cfSchristos.Xr dwarf_siblingof 3 325