xref: /freebsd/contrib/elftoolchain/libdwarf/dwarf_loclist.3 (revision ae500c1ff8974130f7f2692772cf288b90349e0d)
12de3b87aSKai Wang.\" Copyright (c) 2011 Kai Wang
22de3b87aSKai Wang.\" All rights reserved.
32de3b87aSKai Wang.\"
42de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without
52de3b87aSKai Wang.\" modification, are permitted provided that the following conditions
62de3b87aSKai Wang.\" are met:
72de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright
82de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer.
92de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright
102de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer in the
112de3b87aSKai Wang.\"    documentation and/or other materials provided with the distribution.
122de3b87aSKai Wang.\"
132de3b87aSKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
142de3b87aSKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
152de3b87aSKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
162de3b87aSKai Wang.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
172de3b87aSKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
182de3b87aSKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
192de3b87aSKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
202de3b87aSKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
212de3b87aSKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
222de3b87aSKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
232de3b87aSKai Wang.\" SUCH DAMAGE.
242de3b87aSKai Wang.\"
25*ae500c1fSEd Maste.\" $Id: dwarf_loclist.3 3644 2018-10-15 19:55:01Z jkoshy $
262de3b87aSKai Wang.\"
272de3b87aSKai Wang.Dd November 9, 2011
282de3b87aSKai Wang.Dt DWARF_LOCLIST 3
29*ae500c1fSEd Maste.Os
302de3b87aSKai Wang.Sh NAME
312de3b87aSKai Wang.Nm dwarf_loclist ,
322de3b87aSKai Wang.Nm dwarf_loclist_n
332de3b87aSKai Wang.Nd retrieve DWARF location expression information
342de3b87aSKai Wang.Sh LIBRARY
352de3b87aSKai Wang.Lb libdwarf
362de3b87aSKai Wang.Sh SYNOPSIS
372de3b87aSKai Wang.In libdwarf.h
382de3b87aSKai Wang.Ft int
392de3b87aSKai Wang.Fo dwarf_loclist
402de3b87aSKai Wang.Fa "Dwarf_Attribute at"
412de3b87aSKai Wang.Fa "Dwarf_Locdesc **llbuf"
422de3b87aSKai Wang.Fa "Dwarf_Signed *listlen"
432de3b87aSKai Wang.Fa "Dwarf_Error *error"
442de3b87aSKai Wang.Fc
452de3b87aSKai Wang.Ft int
462de3b87aSKai Wang.Fo dwarf_loclist_n
472de3b87aSKai Wang.Fa "Dwarf_Attribute at"
482de3b87aSKai Wang.Fa "Dwarf_Locdesc ***llbuf"
492de3b87aSKai Wang.Fa "Dwarf_Signed *listlen"
502de3b87aSKai Wang.Fa "Dwarf_Error *error"
512de3b87aSKai Wang.Fc
522de3b87aSKai Wang.Sh DESCRIPTION
532de3b87aSKai WangThese functions retrieve the location expressions
542de3b87aSKai Wangassociated with a DWARF attribute.
552de3b87aSKai Wang.Pp
562de3b87aSKai WangNote: function
572de3b87aSKai Wang.Fn dwarf_loclist
582de3b87aSKai Wangis deprecated.
592de3b87aSKai WangNew application code should instead use function
602de3b87aSKai Wang.Fn dwarf_loclist_n
612de3b87aSKai Wang.Pp
622de3b87aSKai WangFunction
632de3b87aSKai Wang.Fn dwarf_loclist_n
642de3b87aSKai Wangretrieves the list of location expressions associated with a DWARF
652de3b87aSKai Wangattribute.
662de3b87aSKai WangArgument
672de3b87aSKai Wang.Ar at
682de3b87aSKai Wangshould reference a valid DWARF attribute.
692de3b87aSKai WangArgument
702de3b87aSKai Wang.Ar llbuf
712de3b87aSKai Wangshould point to a location which will hold a returned array of
722de3b87aSKai Wangpointers to
732de3b87aSKai Wang.Vt Dwarf_Locdesc
742de3b87aSKai Wangdescriptors.
752de3b87aSKai WangArgument
762de3b87aSKai Wang.Ar listlen
772de3b87aSKai Wangshould point to a location which will be set to the number of
782de3b87aSKai Wangelements contained in the returned array.
792de3b87aSKai WangIf argument
802de3b87aSKai Wang.Ar err
812de3b87aSKai Wangis not NULL, it will be used to store error information in case
822de3b87aSKai Wangof an error.
832de3b87aSKai Wang.Pp
842de3b87aSKai WangFunction
852de3b87aSKai Wang.Fn dwarf_loclist
862de3b87aSKai Wangretrieves the first location expression associated with an attribute.
872de3b87aSKai WangArgument
882de3b87aSKai Wang.Ar at
892de3b87aSKai Wangshould reference a valid DWARF attribute.
902de3b87aSKai WangArgument
912de3b87aSKai Wang.Ar llbuf
922de3b87aSKai Wangshould point to a location which will hold the returned pointer
932de3b87aSKai Wangto a
942de3b87aSKai Wang.Vt Dwarf_Locdesc
952de3b87aSKai Wangdescriptor.
962de3b87aSKai WangArgument
972de3b87aSKai Wang.Ar listlen
982de3b87aSKai Wangshould point to a location which will be always set to 1.
992de3b87aSKai WangIf argument
1002de3b87aSKai Wang.Ar err
1012de3b87aSKai Wangis not NULL, it will be used to store error information in case
1022de3b87aSKai Wangof an error.
1032de3b87aSKai Wang.Pp
1042de3b87aSKai Wang.Vt Dwarf_Locdesc
1052de3b87aSKai Wangdescriptors are defined in the header file
1062de3b87aSKai Wang.In libdwarf.h ,
1072de3b87aSKai Wangand consist of following fields:
1082de3b87aSKai Wang.Pp
1092de3b87aSKai Wang.Bl -tag -width ".Va ld_cents" -compact
1102de3b87aSKai Wang.It Va ld_lopc
1112de3b87aSKai WangThe lowest program counter address covered by the descriptor.
1122de3b87aSKai WangThis field will be set to 0 if the descriptor is not associated with
1132de3b87aSKai Wangan address range.
1142de3b87aSKai Wang.It Va ld_hipc
1152de3b87aSKai WangThe highest program counter address covered by the descriptor.
1162de3b87aSKai WangThis field will be set to 0 if the descriptor is not associated with
1172de3b87aSKai Wangan address range.
1182de3b87aSKai Wang.It Va ld_cents
1192de3b87aSKai WangThe number of entries returned in
1202de3b87aSKai Wang.Va ld_s
1212de3b87aSKai Wangfield.
1222de3b87aSKai Wang.It Va ld_s
1232de3b87aSKai WangPointer to an array of
1242de3b87aSKai Wang.Vt Dwarf_Loc
1252de3b87aSKai Wangdescriptors.
1262de3b87aSKai Wang.El
1272de3b87aSKai Wang.Pp
1282de3b87aSKai WangEach
1292de3b87aSKai Wang.Vt Dwarf_Loc
1302de3b87aSKai Wangdescriptor represents one operation of a location expression.
1312de3b87aSKai WangThese descriptors are defined in the header file
1322de3b87aSKai Wang.In libdwarf.h ,
1332de3b87aSKai Wangand consist of following fields:
1342de3b87aSKai Wang.Pp
1352de3b87aSKai Wang.Bl -tag -width ".Va lr_number2" -compact
1362de3b87aSKai Wang.It Va lr_atom
1372de3b87aSKai WangThe operator name, one of the
1382de3b87aSKai Wang.Dv DW_OP_*
1392de3b87aSKai Wangconstants defined in the header file
1402de3b87aSKai Wang.In dwarf.h .
1412de3b87aSKai Wang.It Va lr_number
1422de3b87aSKai WangThe first operand of this operation.
1432de3b87aSKai Wang.It Va lr_number2
1442de3b87aSKai WangThe second operand of this operation.
1452de3b87aSKai Wang.It Va lr_offset
1462de3b87aSKai WangThe byte offset of this operation within the containing location
1472de3b87aSKai Wangexpression.
1482de3b87aSKai Wang.El
1492de3b87aSKai Wang.Ss Memory Management
1502de3b87aSKai WangThe memory area used for the descriptor array returned in argument
1512de3b87aSKai Wang.Ar llbuf
1522de3b87aSKai Wangis allocated by the
1532de3b87aSKai Wang.Lb libdwarf .
1542de3b87aSKai WangWhen the descriptor array is no longer needed, application code should
1552de3b87aSKai Wanguse function
1562de3b87aSKai Wang.Xr dwarf_dealloc 3
1572de3b87aSKai Wangto free the memory area in the following manner:
1582de3b87aSKai Wang.Bl -enum
1592de3b87aSKai Wang.It
1602de3b87aSKai WangFirst, the
1612de3b87aSKai Wang.Ar ld_s
1622de3b87aSKai Wangfield of each
1632de3b87aSKai Wang.Vt Dwarf_Locdesc
1642de3b87aSKai Wangdescriptor should be deallocated using the allocation type
1652de3b87aSKai Wang.Dv DW_DLA_LOC_BLOCK .
1662de3b87aSKai Wang.It
1672de3b87aSKai WangThen, the application should free each
1682de3b87aSKai Wang.Vt Dwarf_Locdesc
1692de3b87aSKai Wangdescriptor using the allocation type
1702de3b87aSKai Wang.Dv DW_DLA_LOCDESC .
1712de3b87aSKai Wang.It
1722de3b87aSKai WangFinally, the
1732de3b87aSKai Wang.Va llbuf
1742de3b87aSKai Wangpointer should be deallocated using the allocation type
1752de3b87aSKai Wang.Dv DW_DLA_LIST .
1762de3b87aSKai Wang.El
1772de3b87aSKai Wang.Sh RETURN VALUES
1782de3b87aSKai WangOn success, these functions returns
1792de3b87aSKai Wang.Dv DW_DLV_OK .
1802de3b87aSKai WangIn case of an error, they return
1812de3b87aSKai Wang.Dv DW_DLV_ERROR
1822de3b87aSKai Wangand set the argument
1832de3b87aSKai Wang.Ar err .
184*ae500c1fSEd Maste.Sh EXAMPLES
1852de3b87aSKai WangTo retrieve the location list associated with an attribute, use:
1862de3b87aSKai Wang.Bd -literal -offset indent
1872de3b87aSKai WangDwarf_Attribute at;
1882de3b87aSKai WangDwarf_Locdesc **llbuf;
1892de3b87aSKai WangDwarf_Signed lcnt;
1902de3b87aSKai WangDwarf_Loc *lr;
1912de3b87aSKai WangDwarf_Error de;
1922de3b87aSKai Wangint i;
1932de3b87aSKai Wang
1942de3b87aSKai Wangif (dwarf_loclist_n(at, &llbuf, &lcnt, &de) != DW_DLV_OK)
1952de3b87aSKai Wang	errx(EXIT_FAILURE, "dwarf_loclist_n failed: %s",
1962de3b87aSKai Wang	    dwarf_errmsg(de));
1972de3b87aSKai Wang
1982de3b87aSKai Wangfor (i = 0; i < lcnt; i++) {
1992de3b87aSKai Wang	/* ... Use llbuf[i] ... */
2002de3b87aSKai Wang	for (j = 0; (Dwarf_Half) j < llbuf[i]->ld_cents; j++) {
2012de3b87aSKai Wang		lr = &llbuf[i]->ld_s[j];
2022de3b87aSKai Wang		/* ... Use each Dwarf_Loc descriptor ... */
2032de3b87aSKai Wang	}
2042de3b87aSKai Wang	dwarf_dealloc(dbg, llbuf[i]->ld_s, DW_DLA_LOC_BLOCK);
2052de3b87aSKai Wang	dwarf_dealloc(dbg, llbuf[i], DW_DLA_LOCDESC);
2062de3b87aSKai Wang}
2072de3b87aSKai Wangdwarf_dealloc(dbg, llbuf, DW_DLA_LIST);
2082de3b87aSKai Wang.Ed
209*ae500c1fSEd Maste.Sh ERRORS
210*ae500c1fSEd MasteThese functions can fail with:
211*ae500c1fSEd Maste.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
212*ae500c1fSEd Maste.It Bq Er DW_DLE_ARGUMENT
213*ae500c1fSEd MasteOne of the arguments
214*ae500c1fSEd Maste.Ar at ,
215*ae500c1fSEd Maste.Ar llbuf
216*ae500c1fSEd Masteor
217*ae500c1fSEd Maste.Ar listlen
218*ae500c1fSEd Mastewas NULL.
219*ae500c1fSEd Maste.It Bq Er DW_DLE_ARGUMENT
220*ae500c1fSEd MasteThe attribute provided by argument
221*ae500c1fSEd Maste.Ar at
222*ae500c1fSEd Mastedoes not contain a location expression or is not associated with a
223*ae500c1fSEd Mastelocation expression list.
224*ae500c1fSEd Maste.El
2252de3b87aSKai Wang.Sh SEE ALSO
2262de3b87aSKai Wang.Xr dwarf 3 ,
2272de3b87aSKai Wang.Xr dwarf_dealloc 3 ,
228*ae500c1fSEd Maste.Xr dwarf_get_loclist_entry 3 ,
2292de3b87aSKai Wang.Xr dwarf_loclist_from_expr 3 ,
230*ae500c1fSEd Maste.Xr dwarf_loclist_from_expr_a 3
231