1.\" $NetBSD: dwarf_attrlist.3,v 1.6 2024/03/03 17:37:30 christos Exp $ 2.\" 3.\" Copyright (c) 2010 Kai Wang 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.\" Id: dwarf_attrlist.3 3964 2022-03-13 21:41:26Z jkoshy 28.\" 29.Dd March 13, 2022 30.Dt DWARF_ATTRLIST 3 31.Os 32.Sh NAME 33.Nm dwarf_attrlist 34.Nd retrieve DWARF attribute descriptors 35.Sh LIBRARY 36.Lb libdwarf 37.Sh SYNOPSIS 38.In libdwarf.h 39.Ft int 40.Fo dwarf_attrlist 41.Fa "Dwarf_Die die" 42.Fa "Dwarf_Attribute **attrbuf" 43.Fa "Dwarf_Signed *attrcount" 44.Fa "Dwarf_Error *err" 45.Fc 46.Sh DESCRIPTION 47Function 48.Fn dwarf_attrlist 49retrieves the DWARF attribute descriptors associated with a 50debugging information entry descriptor in argument 51.Fa die . 52The descriptors are returned as an array of values of the opaque type 53.Vt Dwarf_Attribute . 54The data associated with each returned attribute descriptor may be 55queried using the form query functions in the 56.Xr dwarf 3 57API set. 58.Pp 59Argument 60.Fa attrbuf 61points to a location that will hold a pointer to the returned 62array of DWARF attribute descriptors. 63Argument 64.Fa attrcount 65points to a location that will hold the number of descriptors in 66the returned array. 67.Pp 68If argument 69.Fa err 70is 71.No non- Ns Dv NULL , 72it is used to return an error descriptor in case of an error. 73.Ss Memory Management 74In the current implementation, the memory allocated for each DWARF 75attribute descriptor and for the returned array of descriptors is 76managed by the library and the application does not need to explicitly 77free the returned pointers. 78However, for compatibility with other implementations of the 79.Xr dwarf 3 80API, the application is permitted to pass the pointers returned by to 81the 82.Fn dwarf_dealloc 83function. 84.Sh RETURN VALUES 85Function 86.Fn dwarf_attrlist 87returns 88.Dv DW_DLV_OK 89on success. 90.Pp 91If the debugging information entry descriptor denoted by argument 92.Fa die 93does not contain any attribute, the function returns 94.Dv DW_DLV_NO_ENTRY 95and sets argument 96.Fa err . 97For other errors, it returns 98.Dv DW_DLV_ERROR 99and sets argument 100.Fa err . 101.Sh EXAMPLES 102To retrieve the attribute list for a DWARF debugging information 103entry use: 104.Bd -literal -offset indent 105Dwarf_Die dw_die; 106Dwarf_Error dw_e; 107Dwarf_Unsigned dw_count; 108Dwarf_Attribute *dw_attributes; 109int error, i; 110 111\&... variable dw_die contains a reference to the DIE of interest ... 112 113/* Retrieve the attribute list from the DIE. */ 114if ((error = dwarf_attrlist(dw_die, &dw_attributes, &dw_count, 115 &dw_e)) != DW_DLV_OK) 116 errx(EXIT_FAILURE, "dwarf_attrlist: %s", dwarf_errmsg(dw_e)); 117 118/* Process the attribute list. */ 119for (i = 0; i < dw_count; ++i) { 120 /* Use the returned pointers in dw_attributes[i] here. */ 121} 122.Ed 123.Sh ERRORS 124Function 125.Fn dwarf_attrlist 126can fail with the following errors: 127.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT" 128.It Bq Er DW_DLE_ARGUMENT 129Arguments 130.Fa die , 131.Fa attrbuf , 132or 133.Fa attrcount 134were 135.Dv NULL . 136.It Bq Er DW_DLE_NO_ENTRY 137Argument 138.Fa die 139had no attributes. 140.It Bq Er DW_DLE_MEMORY 141An out of memory condition was encountered during the execution of the 142function. 143.El 144.Sh SEE ALSO 145.Xr dwarf 3 , 146.Xr dwarf_attr 3 , 147.Xr dwarf_dealloc 3 , 148.Xr dwarf_hasattr 3 , 149.Xr dwarf_hasform 3 , 150.Xr dwarf_whatattr 3 , 151.Xr dwarf_whatform 3 152