1.\" Copyright (c) 2011 Kai Wang 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $Id: dwarf_get_globals.3 3640 2018-10-14 14:09:13Z jkoshy $ 26.\" 27.Dd April 2, 2011 28.Dt DWARF_GET_GLOBALS 3 29.Os 30.Sh NAME 31.Nm dwarf_get_globals , 32.Nm dwarf_global_cu_offset , 33.Nm dwarf_global_die_offset , 34.Nm dwarf_global_name_offsets , 35.Nm dwarf_globname 36.Nd retrieve information about global objects 37.Sh LIBRARY 38.Lb libdwarf 39.Sh SYNOPSIS 40.In libdwarf.h 41.Ft int 42.Fo dwarf_get_globals 43.Fa "Dwarf_Debug dbg" 44.Fa "Dwarf_Global **globals" 45.Fa "Dwarf_Signed *nglobals" 46.Fa "Dwarf_Error *err" 47.Fc 48.Ft int 49.Fo dwarf_global_cu_offset 50.Fa "Dwarf_Global global" 51.Fa "Dwarf_Off *cu_offset" 52.Fa "Dwarf_Error *err" 53.Fc 54.Ft int 55.Fo dwarf_global_die_offset 56.Fa "Dwarf_Global global" 57.Fa "Dwarf_Off *die_offset" 58.Fa "Dwarf_Error *err" 59.Fc 60.Ft int 61.Fo dwarf_global_name_offsets 62.Fa "Dwarf_Global global" 63.Fa "char **name" 64.Fa "Dwarf_Off *die_offset" 65.Fa "Dwarf_Off *cu_die_offset" 66.Fa "Dwarf_Error *err" 67.Fc 68.Ft int 69.Fo dwarf_globname 70.Fa "Dwarf_Global global" 71.Fa "char **name" 72.Fa "Dwarf_Error *err" 73.Fc 74.Sh DESCRIPTION 75These functions retrieve information about global symbols from the 76lookup tables in the 77.Dq ".debug_pubnames" 78DWARF section. 79Information about these global symbols is returned using opaque descriptors 80of type 81.Vt Dwarf_Global . 82Applications need to use the functions described below to retrieve the 83name and the offsets for these descriptors. 84.Pp 85Function 86.Fn dwarf_get_globals 87retrieves descriptors for all the global symbols associated with the 88DWARF debug context specified by argument 89.Ar dbg . 90The argument 91.Ar globals 92should point to a location that will be set to a pointer to an array 93of 94.Vt Dwarf_Global 95descriptors. 96The argument 97.Ar nglobals 98should point to a location that will be set to the number of 99descriptors returned. 100.Pp 101Function 102.Fn dwarf_global_cu_offset 103returns the section-relative offset, relative to the 104.Dq ".debug_info" 105section, of the compilation unit that contains the debugging 106information entry associated with the argument 107.Ar global . 108Argument 109.Ar cu_offset 110should point to a location that will hold the returned offset. 111.Pp 112Function 113.Fn dwarf_global_die_offset 114retrieves the section-relative offset, relative to the 115.Dq ".debug_info" 116section, of the debugging information entry associated with the 117argument 118.Ar global , 119and stores it into the location pointed to by the argument 120.Ar die_offset . 121.Pp 122Function 123.Fn dwarf_global_name_offsets 124retrieves the name and the offsets for the debugging information 125entry for argument 126.Ar global . 127Argument 128.Ar name 129should point to a location which will be set to a pointer to a 130NUL-terminated string containing the name of the associated debugging 131information entry. 132Argument 133.Ar die_offset 134should point to a location which will be set to a section-relative 135offset, relative to the 136.Dq ".debug_info" 137section, of the associated debugging information entry. 138Argument 139.Ar cu_die_offset 140should point to a location which will be set to a 141section-relative offset, relative to the 142.Dq ".debug_info" 143section, of the first debugging information entry in 144the compilation unit associated with argument 145.Ar global . 146.Pp 147Function 148.Fn dwarf_globname 149sets the location pointed to by argument 150.Ar name 151to a pointer to a NUL-terminated string holding the name of the 152debugging information entry associated with the argument 153.Ar global . 154.Ss Memory Management 155The memory area used for the array of 156.Vt Dwarf_Global 157descriptors returned in argument 158.Ar globals 159by function 160.Fn dwarf_get_globals 161is owned by the 162.Lb libdwarf . 163Application code should not attempt to directly free this pointer. 164Portable code should instead use the function 165.Xr dwarf_globals_dealloc 3 166to indicate that the memory area may be freed. 167.Pp 168The memory area used for the string returned in the 169.Ar name 170argument to functions 171.Fn dwarf_globname 172and 173.Fn dwarf_global_name_offsets 174is owned by the 175.Lb libdwarf . 176Portable code should use the 177.Xr dwarf_dealloc 3 178function to indicate that the memory area may be freed. 179.Ss Error Returns 180If argument 181.Ar err 182is not NULL, these functions will use it to store error information, 183in case of an error. 184.Sh RETURN VALUES 185On success, these functions returns 186.Dv DW_DLV_OK . 187In case of an error, they return 188.Dv DW_DLV_ERROR 189and set the argument 190.Ar err . 191.Sh ERRORS 192These functions may fail with the following errors: 193.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 194.It Bq Er DW_DLE_ARGUMENT 195One of the arguments 196.Va cu_die_offset , 197.Va cu_offset , 198.Va dbg , 199.Va die_offset , 200.Va global , 201.Va globals , 202.Va name , 203or 204.Va nglobals 205was NULL. 206.El 207.Sh SEE ALSO 208.Xr dwarf 3 , 209.Xr dwarf_dealloc 3 , 210.Xr dwarf_get_cu_die_offset_given_cu_header_offset 3 , 211.Xr dwarf_globals_dealloc 3 212