xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_vars.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristos.\"	$NetBSD: dwarf_get_vars.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_vars.3 3963 2022-03-12 16:07:32Z jkoshy
289dd9d0cfSchristos.\"
299dd9d0cfSchristos.Dd April 2, 2011
309dd9d0cfSchristos.Dt DWARF_GET_VARS 3
31604b0842Sjkoshy.Os
329dd9d0cfSchristos.Sh NAME
339dd9d0cfSchristos.Nm dwarf_get_vars ,
349dd9d0cfSchristos.Nm dwarf_var_cu_offset ,
359dd9d0cfSchristos.Nm dwarf_var_die_offset ,
369dd9d0cfSchristos.Nm dwarf_var_name_offsets ,
379dd9d0cfSchristos.Nm dwarf_varname
389dd9d0cfSchristos.Nd retrieve information about static variables
399dd9d0cfSchristos.Sh LIBRARY
409dd9d0cfSchristos.Lb libdwarf
419dd9d0cfSchristos.Sh SYNOPSIS
429dd9d0cfSchristos.In libdwarf.h
439dd9d0cfSchristos.Ft int
449dd9d0cfSchristos.Fo dwarf_get_vars
459dd9d0cfSchristos.Fa "Dwarf_Debug dbg"
469dd9d0cfSchristos.Fa "Dwarf_Var **vars"
479dd9d0cfSchristos.Fa "Dwarf_Signed *nvars"
489dd9d0cfSchristos.Fa "Dwarf_Error *err"
499dd9d0cfSchristos.Fc
509dd9d0cfSchristos.Ft int
519dd9d0cfSchristos.Fo dwarf_var_cu_offset
529dd9d0cfSchristos.Fa "Dwarf_Var var"
539dd9d0cfSchristos.Fa "Dwarf_Off *cu_offset"
549dd9d0cfSchristos.Fa "Dwarf_Error *err"
559dd9d0cfSchristos.Fc
569dd9d0cfSchristos.Ft int
579dd9d0cfSchristos.Fo dwarf_var_die_offset
589dd9d0cfSchristos.Fa "Dwarf_Var var"
599dd9d0cfSchristos.Fa "Dwarf_Off *die_offset"
609dd9d0cfSchristos.Fa "Dwarf_Error *err"
619dd9d0cfSchristos.Fc
629dd9d0cfSchristos.Ft int
639dd9d0cfSchristos.Fo dwarf_var_name_offsets
649dd9d0cfSchristos.Fa "Dwarf_Var var"
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_varname
729dd9d0cfSchristos.Fa "Dwarf_Var var"
739dd9d0cfSchristos.Fa "char **name"
749dd9d0cfSchristos.Fa "Dwarf_Error *err"
759dd9d0cfSchristos.Fc
769dd9d0cfSchristos.Sh DESCRIPTION
779dd9d0cfSchristosThese functions retrieve information about the file scope static
789dd9d0cfSchristosvariables associated with a DWARF debug context.
799dd9d0cfSchristosInformation about these static variables is returned using opaque
809dd9d0cfSchristosdescriptors of type
819dd9d0cfSchristos.Vt Dwarf_Var .
829dd9d0cfSchristosApplications need to use the functions described below to retrieve
839dd9d0cfSchristosthe name and offset information contained in these descriptors.
849dd9d0cfSchristos.Pp
859dd9d0cfSchristosFunction
869dd9d0cfSchristos.Fn dwarf_get_vars
879dd9d0cfSchristosretrieves descriptors for all the static variables associated with the
889dd9d0cfSchristosDWARF debug context specified by argument
89cdbf1fe1Sjkoshy.Fa dbg .
909dd9d0cfSchristosThe argument
91cdbf1fe1Sjkoshy.Fa vars
929dd9d0cfSchristosshould point to a location that will be set to a pointer to an array
939dd9d0cfSchristosof
949dd9d0cfSchristos.Vt Dwarf_Var
959dd9d0cfSchristosdescriptors.
969dd9d0cfSchristosThe argument
97cdbf1fe1Sjkoshy.Fa nvars
989dd9d0cfSchristosshould point to a location that will be set to the number of
999dd9d0cfSchristosdescriptors returned.
1009dd9d0cfSchristos.Pp
1019dd9d0cfSchristosFunction
1029dd9d0cfSchristos.Fn dwarf_var_cu_offset
1039dd9d0cfSchristosreturns the section-relative offset, relative to the
1049dd9d0cfSchristos.Dq ".debug_info"
1059dd9d0cfSchristossection, of the compilation unit that
1069dd9d0cfSchristoscontains the debugging information entry associated with the argument
107cdbf1fe1Sjkoshy.Fa var .
1089dd9d0cfSchristosArgument
109cdbf1fe1Sjkoshy.Fa cu_offset
1109dd9d0cfSchristosshould point to a location that will hold the returned offset.
1119dd9d0cfSchristos.Pp
1129dd9d0cfSchristosFunction
1139dd9d0cfSchristos.Fn dwarf_var_die_offset
1149dd9d0cfSchristosretrieves the section-relative offset, relative to the
1159dd9d0cfSchristos.Dq ".debug_info"
1169dd9d0cfSchristossection, of the debugging information
1179dd9d0cfSchristosentry associated with the argument
118cdbf1fe1Sjkoshy.Fa var ,
1199dd9d0cfSchristosand stores it into the location pointed to by the argument
120cdbf1fe1Sjkoshy.Fa die_offset .
1219dd9d0cfSchristos.Pp
1229dd9d0cfSchristosFunction
1239dd9d0cfSchristos.Fn dwarf_var_name_offsets
1249dd9d0cfSchristosretrieves both the name and the associated offsets for the debugging
1259dd9d0cfSchristosinformation entry for argument
126cdbf1fe1Sjkoshy.Fa var .
1279dd9d0cfSchristosArgument
128cdbf1fe1Sjkoshy.Fa name
1299dd9d0cfSchristosshould point to a location which will be set to a pointer to a
1309dd9d0cfSchristosNUL-terminated string containing the name of the associated debugging
1319dd9d0cfSchristosinformation entry.
1329dd9d0cfSchristosArgument
133cdbf1fe1Sjkoshy.Fa die_offset
1349dd9d0cfSchristosshould point to a location which will be set to a section-relative
1359dd9d0cfSchristosoffset, relative to the
1369dd9d0cfSchristos.Dq ".debug_info"
1379dd9d0cfSchristossection, of the associated debugging information entry.
1389dd9d0cfSchristosArgument
139cdbf1fe1Sjkoshy.Fa cu_die_offset
1409dd9d0cfSchristosshould point to a location which will be set to a
1419dd9d0cfSchristossection-relative offset, relative to the
1429dd9d0cfSchristos.Dq ".debug_info"
1439dd9d0cfSchristossection, of the first debugging information entry in
1449dd9d0cfSchristosthe compilation unit associated with argument
145cdbf1fe1Sjkoshy.Fa var .
1469dd9d0cfSchristos.Pp
1479dd9d0cfSchristosFunction
1489dd9d0cfSchristos.Fn dwarf_varname
1499dd9d0cfSchristossets the location pointed to by argument
150cdbf1fe1Sjkoshy.Fa name
1519dd9d0cfSchristosto a pointer to a NUL-terminated string holding the name of the
1529dd9d0cfSchristosdebugging information entry associated with the argument
153cdbf1fe1Sjkoshy.Fa var .
1549dd9d0cfSchristos.Ss Memory Management
1559dd9d0cfSchristosThe memory area used for the array of
1569dd9d0cfSchristos.Vt Dwarf_Var
1579dd9d0cfSchristosdescriptors returned in argument
158cdbf1fe1Sjkoshy.Fa vars
1599dd9d0cfSchristosby function
1609dd9d0cfSchristos.Fn dwarf_get_vars
1619dd9d0cfSchristosis owned by the
1629dd9d0cfSchristos.Lb libdwarf .
1639dd9d0cfSchristosApplication code should not attempt to directly free this pointer.
1649dd9d0cfSchristosPortable code should instead use the function
1659dd9d0cfSchristos.Xr dwarf_vars_dealloc 3
1669dd9d0cfSchristosto indicate that the memory area may be freed.
1679dd9d0cfSchristos.Pp
1689dd9d0cfSchristosThe memory area used for the string returned in the
169cdbf1fe1Sjkoshy.Fa name
1709dd9d0cfSchristosargument to functions
1719dd9d0cfSchristos.Fn dwarf_var_name_offsets
1729dd9d0cfSchristosand
1739dd9d0cfSchristos.Fn dwarf_varname
1749dd9d0cfSchristosis owned by the
1759dd9d0cfSchristos.Lb libdwarf .
1769dd9d0cfSchristosPortable code should indicate that the memory area can
1779dd9d0cfSchristosbe freed using the
1789dd9d0cfSchristos.Xr dwarf_dealloc 3
1799dd9d0cfSchristosfunction.
1809dd9d0cfSchristos.Ss Error Returns
1819dd9d0cfSchristosIf argument
182cdbf1fe1Sjkoshy.Fa err
183cdbf1fe1Sjkoshyis not
184cdbf1fe1Sjkoshy.Dv NULL ,
185cdbf1fe1Sjkoshythese functions will use it to store error information,
1869dd9d0cfSchristosin case of an error.
1879dd9d0cfSchristos.Sh RETURN VALUES
1889dd9d0cfSchristosOn success, these functions returns
1899dd9d0cfSchristos.Dv DW_DLV_OK .
1909dd9d0cfSchristosIn case of an error, they return
1919dd9d0cfSchristos.Dv DW_DLV_ERROR
1929dd9d0cfSchristosand set the argument
193cdbf1fe1Sjkoshy.Fa err .
1949dd9d0cfSchristos.Sh ERRORS
1959dd9d0cfSchristosThese functions may fail with the following errors:
1969dd9d0cfSchristos.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
1979dd9d0cfSchristos.It Bq Er DW_DLE_ARGUMENT
1989dd9d0cfSchristosOne of the arguments
1999dd9d0cfSchristos.Va cu_die_offset ,
2009dd9d0cfSchristos.Va cu_offset ,
2019dd9d0cfSchristos.Va dbg ,
2029dd9d0cfSchristos.Va die_offset ,
2039dd9d0cfSchristos.Va var ,
2049dd9d0cfSchristos.Va vars ,
2059dd9d0cfSchristos.Va name ,
2069dd9d0cfSchristosor
2079dd9d0cfSchristos.Va nvars
208cdbf1fe1Sjkoshywas
209cdbf1fe1Sjkoshy.Dv NULL .
2109dd9d0cfSchristos.El
2119dd9d0cfSchristos.Sh SEE ALSO
2129dd9d0cfSchristos.Xr dwarf 3 ,
2139dd9d0cfSchristos.Xr dwarf_dealloc 3 ,
2149dd9d0cfSchristos.Xr dwarf_get_cu_die_offset_given_cu_header_offset 3 ,
2159dd9d0cfSchristos.Xr dwarf_vars_dealloc 3
216