1*5ac3bc71Schristos.\" $NetBSD: dwarf_get_globals.3,v 1.6 2024/03/03 17:37:31 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2011 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_get_globals.3 3963 2022-03-12 16:07:32Z jkoshy 289dd9d0cfSchristos.\" 299dd9d0cfSchristos.Dd April 2, 2011 309dd9d0cfSchristos.Dt DWARF_GET_GLOBALS 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_get_globals , 349dd9d0cfSchristos.Nm dwarf_global_cu_offset , 359dd9d0cfSchristos.Nm dwarf_global_die_offset , 369dd9d0cfSchristos.Nm dwarf_global_name_offsets , 379dd9d0cfSchristos.Nm dwarf_globname 389dd9d0cfSchristos.Nd retrieve information about global objects 399dd9d0cfSchristos.Sh LIBRARY 409dd9d0cfSchristos.Lb libdwarf 419dd9d0cfSchristos.Sh SYNOPSIS 429dd9d0cfSchristos.In libdwarf.h 439dd9d0cfSchristos.Ft int 449dd9d0cfSchristos.Fo dwarf_get_globals 459dd9d0cfSchristos.Fa "Dwarf_Debug dbg" 469dd9d0cfSchristos.Fa "Dwarf_Global **globals" 479dd9d0cfSchristos.Fa "Dwarf_Signed *nglobals" 489dd9d0cfSchristos.Fa "Dwarf_Error *err" 499dd9d0cfSchristos.Fc 509dd9d0cfSchristos.Ft int 519dd9d0cfSchristos.Fo dwarf_global_cu_offset 529dd9d0cfSchristos.Fa "Dwarf_Global global" 539dd9d0cfSchristos.Fa "Dwarf_Off *cu_offset" 549dd9d0cfSchristos.Fa "Dwarf_Error *err" 559dd9d0cfSchristos.Fc 569dd9d0cfSchristos.Ft int 579dd9d0cfSchristos.Fo dwarf_global_die_offset 589dd9d0cfSchristos.Fa "Dwarf_Global global" 599dd9d0cfSchristos.Fa "Dwarf_Off *die_offset" 609dd9d0cfSchristos.Fa "Dwarf_Error *err" 619dd9d0cfSchristos.Fc 629dd9d0cfSchristos.Ft int 639dd9d0cfSchristos.Fo dwarf_global_name_offsets 649dd9d0cfSchristos.Fa "Dwarf_Global global" 659dd9d0cfSchristos.Fa "char **name" 669dd9d0cfSchristos.Fa "Dwarf_Off *die_offset" 679dd9d0cfSchristos.Fa "Dwarf_Off *cu_die_offset" 689dd9d0cfSchristos.Fa "Dwarf_Error *err" 699dd9d0cfSchristos.Fc 709dd9d0cfSchristos.Ft int 719dd9d0cfSchristos.Fo dwarf_globname 729dd9d0cfSchristos.Fa "Dwarf_Global global" 739dd9d0cfSchristos.Fa "char **name" 749dd9d0cfSchristos.Fa "Dwarf_Error *err" 759dd9d0cfSchristos.Fc 769dd9d0cfSchristos.Sh DESCRIPTION 779dd9d0cfSchristosThese functions retrieve information about global symbols from the 789dd9d0cfSchristoslookup tables in the 799dd9d0cfSchristos.Dq ".debug_pubnames" 809dd9d0cfSchristosDWARF section. 819dd9d0cfSchristosInformation about these global symbols is returned using opaque descriptors 829dd9d0cfSchristosof type 839dd9d0cfSchristos.Vt Dwarf_Global . 849dd9d0cfSchristosApplications need to use the functions described below to retrieve the 859dd9d0cfSchristosname and the offsets for these descriptors. 869dd9d0cfSchristos.Pp 879dd9d0cfSchristosFunction 889dd9d0cfSchristos.Fn dwarf_get_globals 899dd9d0cfSchristosretrieves descriptors for all the global symbols associated with the 909dd9d0cfSchristosDWARF debug context specified by argument 91cdbf1fe1Sjkoshy.Fa dbg . 929dd9d0cfSchristosThe argument 93cdbf1fe1Sjkoshy.Fa globals 949dd9d0cfSchristosshould point to a location that will be set to a pointer to an array 959dd9d0cfSchristosof 969dd9d0cfSchristos.Vt Dwarf_Global 979dd9d0cfSchristosdescriptors. 989dd9d0cfSchristosThe argument 99cdbf1fe1Sjkoshy.Fa nglobals 1009dd9d0cfSchristosshould point to a location that will be set to the number of 1019dd9d0cfSchristosdescriptors returned. 1029dd9d0cfSchristos.Pp 1039dd9d0cfSchristosFunction 1049dd9d0cfSchristos.Fn dwarf_global_cu_offset 1059dd9d0cfSchristosreturns the section-relative offset, relative to the 1069dd9d0cfSchristos.Dq ".debug_info" 1079dd9d0cfSchristossection, of the compilation unit that contains the debugging 1089dd9d0cfSchristosinformation entry associated with the argument 109cdbf1fe1Sjkoshy.Fa global . 1109dd9d0cfSchristosArgument 111cdbf1fe1Sjkoshy.Fa cu_offset 1129dd9d0cfSchristosshould point to a location that will hold the returned offset. 1139dd9d0cfSchristos.Pp 1149dd9d0cfSchristosFunction 1159dd9d0cfSchristos.Fn dwarf_global_die_offset 1169dd9d0cfSchristosretrieves the section-relative offset, relative to the 1179dd9d0cfSchristos.Dq ".debug_info" 1189dd9d0cfSchristossection, of the debugging information entry associated with the 1199dd9d0cfSchristosargument 120cdbf1fe1Sjkoshy.Fa global , 1219dd9d0cfSchristosand stores it into the location pointed to by the argument 122cdbf1fe1Sjkoshy.Fa die_offset . 1239dd9d0cfSchristos.Pp 1249dd9d0cfSchristosFunction 1259dd9d0cfSchristos.Fn dwarf_global_name_offsets 1269dd9d0cfSchristosretrieves the name and the offsets for the debugging information 1279dd9d0cfSchristosentry for argument 128cdbf1fe1Sjkoshy.Fa global . 1299dd9d0cfSchristosArgument 130cdbf1fe1Sjkoshy.Fa name 1319dd9d0cfSchristosshould point to a location which will be set to a pointer to a 1329dd9d0cfSchristosNUL-terminated string containing the name of the associated debugging 1339dd9d0cfSchristosinformation entry. 1349dd9d0cfSchristosArgument 135cdbf1fe1Sjkoshy.Fa die_offset 1369dd9d0cfSchristosshould point to a location which will be set to a section-relative 1379dd9d0cfSchristosoffset, relative to the 1389dd9d0cfSchristos.Dq ".debug_info" 1399dd9d0cfSchristossection, of the associated debugging information entry. 1409dd9d0cfSchristosArgument 141cdbf1fe1Sjkoshy.Fa cu_die_offset 1429dd9d0cfSchristosshould point to a location which will be set to a 1439dd9d0cfSchristossection-relative offset, relative to the 1449dd9d0cfSchristos.Dq ".debug_info" 1459dd9d0cfSchristossection, of the first debugging information entry in 1469dd9d0cfSchristosthe compilation unit associated with argument 147cdbf1fe1Sjkoshy.Fa global . 1489dd9d0cfSchristos.Pp 1499dd9d0cfSchristosFunction 1509dd9d0cfSchristos.Fn dwarf_globname 1519dd9d0cfSchristossets the location pointed to by argument 152cdbf1fe1Sjkoshy.Fa name 1539dd9d0cfSchristosto a pointer to a NUL-terminated string holding the name of the 1549dd9d0cfSchristosdebugging information entry associated with the argument 155cdbf1fe1Sjkoshy.Fa global . 1569dd9d0cfSchristos.Ss Memory Management 1579dd9d0cfSchristosThe memory area used for the array of 1589dd9d0cfSchristos.Vt Dwarf_Global 1599dd9d0cfSchristosdescriptors returned in argument 160cdbf1fe1Sjkoshy.Fa globals 1619dd9d0cfSchristosby function 1629dd9d0cfSchristos.Fn dwarf_get_globals 1639dd9d0cfSchristosis owned by the 1649dd9d0cfSchristos.Lb libdwarf . 1659dd9d0cfSchristosApplication code should not attempt to directly free this pointer. 1669dd9d0cfSchristosPortable code should instead use the function 1679dd9d0cfSchristos.Xr dwarf_globals_dealloc 3 1689dd9d0cfSchristosto indicate that the memory area may be freed. 1699dd9d0cfSchristos.Pp 1709dd9d0cfSchristosThe memory area used for the string returned in the 171cdbf1fe1Sjkoshy.Fa name 1729dd9d0cfSchristosargument to functions 1739dd9d0cfSchristos.Fn dwarf_globname 1749dd9d0cfSchristosand 1759dd9d0cfSchristos.Fn dwarf_global_name_offsets 1769dd9d0cfSchristosis owned by the 1779dd9d0cfSchristos.Lb libdwarf . 1789dd9d0cfSchristosPortable code should use the 1799dd9d0cfSchristos.Xr dwarf_dealloc 3 1809dd9d0cfSchristosfunction to indicate that the memory area may be freed. 1819dd9d0cfSchristos.Ss Error Returns 1829dd9d0cfSchristosIf argument 183cdbf1fe1Sjkoshy.Fa err 184cdbf1fe1Sjkoshyis not 185cdbf1fe1Sjkoshy.Dv NULL , 186cdbf1fe1Sjkoshythese functions will use it to store error information, 1879dd9d0cfSchristosin case of an error. 1889dd9d0cfSchristos.Sh RETURN VALUES 1899dd9d0cfSchristosOn success, these functions returns 1909dd9d0cfSchristos.Dv DW_DLV_OK . 1919dd9d0cfSchristosIn case of an error, they return 1929dd9d0cfSchristos.Dv DW_DLV_ERROR 1939dd9d0cfSchristosand set the argument 194cdbf1fe1Sjkoshy.Fa err . 1959dd9d0cfSchristos.Sh ERRORS 1969dd9d0cfSchristosThese functions may fail with the following errors: 1979dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 1989dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT 1999dd9d0cfSchristosOne of the arguments 2009dd9d0cfSchristos.Va cu_die_offset , 2019dd9d0cfSchristos.Va cu_offset , 2029dd9d0cfSchristos.Va dbg , 2039dd9d0cfSchristos.Va die_offset , 2049dd9d0cfSchristos.Va global , 2059dd9d0cfSchristos.Va globals , 2069dd9d0cfSchristos.Va name , 2079dd9d0cfSchristosor 2089dd9d0cfSchristos.Va nglobals 209cdbf1fe1Sjkoshywas 210cdbf1fe1Sjkoshy.Dv NULL . 2119dd9d0cfSchristos.El 2129dd9d0cfSchristos.Sh SEE ALSO 2139dd9d0cfSchristos.Xr dwarf 3 , 2149dd9d0cfSchristos.Xr dwarf_dealloc 3 , 2159dd9d0cfSchristos.Xr dwarf_get_cu_die_offset_given_cu_header_offset 3 , 2169dd9d0cfSchristos.Xr dwarf_globals_dealloc 3 217