xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_loclist.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristos.\"	$NetBSD: dwarf_loclist.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_loclist.3 3963 2022-03-12 16:07:32Z jkoshy
289dd9d0cfSchristos.\"
299dd9d0cfSchristos.Dd November 9, 2011
309dd9d0cfSchristos.Dt DWARF_LOCLIST 3
31604b0842Sjkoshy.Os
329dd9d0cfSchristos.Sh NAME
339dd9d0cfSchristos.Nm dwarf_loclist ,
349dd9d0cfSchristos.Nm dwarf_loclist_n
359dd9d0cfSchristos.Nd retrieve DWARF location expression information
369dd9d0cfSchristos.Sh LIBRARY
379dd9d0cfSchristos.Lb libdwarf
389dd9d0cfSchristos.Sh SYNOPSIS
399dd9d0cfSchristos.In libdwarf.h
409dd9d0cfSchristos.Ft int
419dd9d0cfSchristos.Fo dwarf_loclist
429dd9d0cfSchristos.Fa "Dwarf_Attribute at"
439dd9d0cfSchristos.Fa "Dwarf_Locdesc **llbuf"
449dd9d0cfSchristos.Fa "Dwarf_Signed *listlen"
459dd9d0cfSchristos.Fa "Dwarf_Error *error"
469dd9d0cfSchristos.Fc
479dd9d0cfSchristos.Ft int
489dd9d0cfSchristos.Fo dwarf_loclist_n
499dd9d0cfSchristos.Fa "Dwarf_Attribute at"
509dd9d0cfSchristos.Fa "Dwarf_Locdesc ***llbuf"
519dd9d0cfSchristos.Fa "Dwarf_Signed *listlen"
529dd9d0cfSchristos.Fa "Dwarf_Error *error"
539dd9d0cfSchristos.Fc
549dd9d0cfSchristos.Sh DESCRIPTION
559dd9d0cfSchristosThese functions retrieve the location expressions
569dd9d0cfSchristosassociated with a DWARF attribute.
579dd9d0cfSchristos.Pp
589dd9d0cfSchristosNote: function
599dd9d0cfSchristos.Fn dwarf_loclist
609dd9d0cfSchristosis deprecated.
619dd9d0cfSchristosNew application code should instead use function
629dd9d0cfSchristos.Fn dwarf_loclist_n
639dd9d0cfSchristos.Pp
649dd9d0cfSchristosFunction
659dd9d0cfSchristos.Fn dwarf_loclist_n
669dd9d0cfSchristosretrieves the list of location expressions associated with a DWARF
679dd9d0cfSchristosattribute.
689dd9d0cfSchristosArgument
69cdbf1fe1Sjkoshy.Fa at
709dd9d0cfSchristosshould reference a valid DWARF attribute.
719dd9d0cfSchristosArgument
72cdbf1fe1Sjkoshy.Fa llbuf
739dd9d0cfSchristosshould point to a location which will hold a returned array of
749dd9d0cfSchristospointers to
759dd9d0cfSchristos.Vt Dwarf_Locdesc
769dd9d0cfSchristosdescriptors.
779dd9d0cfSchristosArgument
78cdbf1fe1Sjkoshy.Fa listlen
799dd9d0cfSchristosshould point to a location which will be set to the number of
809dd9d0cfSchristoselements contained in the returned array.
819dd9d0cfSchristosIf argument
82cdbf1fe1Sjkoshy.Fa err
83cdbf1fe1Sjkoshyis not
84cdbf1fe1Sjkoshy.Dv NULL ,
85cdbf1fe1Sjkoshyit will be used to store error information in case of an error.
869dd9d0cfSchristos.Pp
879dd9d0cfSchristosFunction
889dd9d0cfSchristos.Fn dwarf_loclist
899dd9d0cfSchristosretrieves the first location expression associated with an attribute.
909dd9d0cfSchristosArgument
91cdbf1fe1Sjkoshy.Fa at
929dd9d0cfSchristosshould reference a valid DWARF attribute.
939dd9d0cfSchristosArgument
94cdbf1fe1Sjkoshy.Fa llbuf
959dd9d0cfSchristosshould point to a location which will hold the returned pointer
969dd9d0cfSchristosto a
979dd9d0cfSchristos.Vt Dwarf_Locdesc
989dd9d0cfSchristosdescriptor.
999dd9d0cfSchristosArgument
100cdbf1fe1Sjkoshy.Fa listlen
1019dd9d0cfSchristosshould point to a location which will be always set to 1.
1029dd9d0cfSchristosIf argument
103cdbf1fe1Sjkoshy.Fa err
104cdbf1fe1Sjkoshyis not
105cdbf1fe1Sjkoshy.Dv NULL ,
106cdbf1fe1Sjkoshyit will be used to store error information in case of an error.
1079dd9d0cfSchristos.Pp
1089dd9d0cfSchristos.Vt Dwarf_Locdesc
1099dd9d0cfSchristosdescriptors are defined in the header file
1109dd9d0cfSchristos.In libdwarf.h ,
1119dd9d0cfSchristosand consist of following fields:
1129dd9d0cfSchristos.Pp
1139dd9d0cfSchristos.Bl -tag -width ".Va ld_cents" -compact
1149dd9d0cfSchristos.It Va ld_lopc
1159dd9d0cfSchristosThe lowest program counter address covered by the descriptor.
1169dd9d0cfSchristosThis field will be set to 0 if the descriptor is not associated with
1179dd9d0cfSchristosan address range.
1189dd9d0cfSchristos.It Va ld_hipc
1199dd9d0cfSchristosThe highest program counter address covered by the descriptor.
1209dd9d0cfSchristosThis field will be set to 0 if the descriptor is not associated with
1219dd9d0cfSchristosan address range.
1229dd9d0cfSchristos.It Va ld_cents
1239dd9d0cfSchristosThe number of entries returned in
1249dd9d0cfSchristos.Va ld_s
1259dd9d0cfSchristosfield.
1269dd9d0cfSchristos.It Va ld_s
1279dd9d0cfSchristosPointer to an array of
1289dd9d0cfSchristos.Vt Dwarf_Loc
1299dd9d0cfSchristosdescriptors.
1309dd9d0cfSchristos.El
1319dd9d0cfSchristos.Pp
1329dd9d0cfSchristosEach
1339dd9d0cfSchristos.Vt Dwarf_Loc
1349dd9d0cfSchristosdescriptor represents one operation of a location expression.
1359dd9d0cfSchristosThese descriptors are defined in the header file
1369dd9d0cfSchristos.In libdwarf.h ,
1379dd9d0cfSchristosand consist of following fields:
1389dd9d0cfSchristos.Pp
1399dd9d0cfSchristos.Bl -tag -width ".Va lr_number2" -compact
1409dd9d0cfSchristos.It Va lr_atom
1419dd9d0cfSchristosThe operator name, one of the
1429dd9d0cfSchristos.Dv DW_OP_*
1439dd9d0cfSchristosconstants defined in the header file
1449dd9d0cfSchristos.In dwarf.h .
1459dd9d0cfSchristos.It Va lr_number
1469dd9d0cfSchristosThe first operand of this operation.
1479dd9d0cfSchristos.It Va lr_number2
1489dd9d0cfSchristosThe second operand of this operation.
1499dd9d0cfSchristos.It Va lr_offset
1509dd9d0cfSchristosThe byte offset of this operation within the containing location
1519dd9d0cfSchristosexpression.
1529dd9d0cfSchristos.El
1539dd9d0cfSchristos.Ss Memory Management
1549dd9d0cfSchristosThe memory area used for the descriptor array returned in argument
155cdbf1fe1Sjkoshy.Fa llbuf
1569dd9d0cfSchristosis allocated by the
1579dd9d0cfSchristos.Lb libdwarf .
1589dd9d0cfSchristosWhen the descriptor array is no longer needed, application code should
1599dd9d0cfSchristosuse function
1609dd9d0cfSchristos.Xr dwarf_dealloc 3
1619dd9d0cfSchristosto free the memory area in the following manner:
1629dd9d0cfSchristos.Bl -enum
1639dd9d0cfSchristos.It
1649dd9d0cfSchristosFirst, the
165cdbf1fe1Sjkoshy.Fa ld_s
1669dd9d0cfSchristosfield of each
1679dd9d0cfSchristos.Vt Dwarf_Locdesc
1689dd9d0cfSchristosdescriptor should be deallocated using the allocation type
1699dd9d0cfSchristos.Dv DW_DLA_LOC_BLOCK .
1709dd9d0cfSchristos.It
1719dd9d0cfSchristosThen, the application should free each
1729dd9d0cfSchristos.Vt Dwarf_Locdesc
1739dd9d0cfSchristosdescriptor using the allocation type
1749dd9d0cfSchristos.Dv DW_DLA_LOCDESC .
1759dd9d0cfSchristos.It
1769dd9d0cfSchristosFinally, the
1779dd9d0cfSchristos.Va llbuf
1789dd9d0cfSchristospointer should be deallocated using the allocation type
1799dd9d0cfSchristos.Dv DW_DLA_LIST .
1809dd9d0cfSchristos.El
1819dd9d0cfSchristos.Sh RETURN VALUES
1829dd9d0cfSchristosOn success, these functions returns
1839dd9d0cfSchristos.Dv DW_DLV_OK .
1849dd9d0cfSchristosIn case of an error, they return
1859dd9d0cfSchristos.Dv DW_DLV_ERROR
1869dd9d0cfSchristosand set the argument
187cdbf1fe1Sjkoshy.Fa err .
188604b0842Sjkoshy.Sh EXAMPLES
1899dd9d0cfSchristosTo retrieve the location list associated with an attribute, use:
1909dd9d0cfSchristos.Bd -literal -offset indent
1919dd9d0cfSchristosDwarf_Attribute at;
1929dd9d0cfSchristosDwarf_Locdesc **llbuf;
1939dd9d0cfSchristosDwarf_Signed lcnt;
1949dd9d0cfSchristosDwarf_Loc *lr;
1959dd9d0cfSchristosDwarf_Error de;
1969dd9d0cfSchristosint i;
1979dd9d0cfSchristos
1989dd9d0cfSchristosif (dwarf_loclist_n(at, &llbuf, &lcnt, &de) != DW_DLV_OK)
1999dd9d0cfSchristos	errx(EXIT_FAILURE, "dwarf_loclist_n failed: %s",
2009dd9d0cfSchristos	    dwarf_errmsg(de));
2019dd9d0cfSchristos
2029dd9d0cfSchristosfor (i = 0; i < lcnt; i++) {
2039dd9d0cfSchristos	/* ... Use llbuf[i] ... */
2049dd9d0cfSchristos	for (j = 0; (Dwarf_Half) j < llbuf[i]->ld_cents; j++) {
2059dd9d0cfSchristos		lr = &llbuf[i]->ld_s[j];
2069dd9d0cfSchristos		/* ... Use each Dwarf_Loc descriptor ... */
2079dd9d0cfSchristos	}
2089dd9d0cfSchristos	dwarf_dealloc(dbg, llbuf[i]->ld_s, DW_DLA_LOC_BLOCK);
2099dd9d0cfSchristos	dwarf_dealloc(dbg, llbuf[i], DW_DLA_LOCDESC);
2109dd9d0cfSchristos}
2119dd9d0cfSchristosdwarf_dealloc(dbg, llbuf, DW_DLA_LIST);
2129dd9d0cfSchristos.Ed
213604b0842Sjkoshy.Sh ERRORS
214604b0842SjkoshyThese functions can fail with:
215604b0842Sjkoshy.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
216604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT
217604b0842SjkoshyOne of the arguments
218cdbf1fe1Sjkoshy.Fa at ,
219cdbf1fe1Sjkoshy.Fa llbuf
220604b0842Sjkoshyor
221cdbf1fe1Sjkoshy.Fa listlen
222cdbf1fe1Sjkoshywas
223cdbf1fe1Sjkoshy.Dv NULL .
224604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT
225604b0842SjkoshyThe attribute provided by argument
226cdbf1fe1Sjkoshy.Fa at
227604b0842Sjkoshydoes not contain a location expression or is not associated with a
228604b0842Sjkoshylocation expression list.
229604b0842Sjkoshy.El
2309dd9d0cfSchristos.Sh SEE ALSO
2319dd9d0cfSchristos.Xr dwarf 3 ,
2329dd9d0cfSchristos.Xr dwarf_dealloc 3 ,
233604b0842Sjkoshy.Xr dwarf_get_loclist_entry 3 ,
2349dd9d0cfSchristos.Xr dwarf_loclist_from_expr 3 ,
235604b0842Sjkoshy.Xr dwarf_loclist_from_expr_a 3
236