1.\"	$NetBSD: dwarf_attrlist.3,v 1.2 2014/03/09 16:58:03 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 2122 2011-11-09 15:35:14Z jkoshy
28.\"
29.Dd November 9, 2011
30.Os
31.Dt DWARF_ATTRLIST 3
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.Ar 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.Ar attrbuf
61points to a location that will hold a pointer to the returned
62array of DWARF attribute descriptors.
63Argument
64.Ar attrcount
65points to a location that will hold the number of descriptors in
66the returned array.
67.Pp
68If argument
69.Ar err
70is non-NULL, it is used to return an error descriptor in case of an
71error.
72.Ss Memory Management
73In the current implementation, the memory allocated for each DWARF
74attribute descriptor and for the returned array of descriptors is
75managed by the library and the application does not need to explicitly
76free the returned pointers.
77However, for compatibility with other implementations of the
78.Xr dwarf 3
79API, the application is permitted to pass the pointers returned by to
80the
81.Fn dwarf_dealloc
82function.
83.Sh RETURN VALUES
84Function
85.Fn dwarf_attrlist
86returns
87.Dv DW_DLV_OK on success.
88.Pp
89If the debugging information entry descriptor denoted by argument
90.Ar die
91does not contain any attribute, the function returns
92.Dv DW_DLV_NO_ENTRY
93and sets argument
94.Ar err .
95For other errors, it returns
96.Dv DW_DLV_ERROR
97and sets argument
98.Ar err .
99.Sh EXAMPLES
100To retrieve the attribute list for a DWARF debugging information
101entry use:
102.Bd -literal -offset indent
103Dwarf_Die dw_die;
104Dwarf_Error dw_e;
105Dwarf_Unsigned dw_count;
106Dwarf_Attribute *dw_attributes;
107int error, i;
108
109\&... variable dw_die contains a reference to the DIE of interest ...
110
111/* Retrieve the attribute list from the DIE. */
112if ((error = dwarf_attrlist(dw_die, &dw_attributes, &dw_count,
113	&dw_e)) != DW_DLV_OK)
114	errx(EXIT_FAILURE, "dwarf_attrlist: %s", dwarf_errmsg(dw_e));
115
116/* Process the attribute list. */
117for (i = 0; i < dw_count; ++i) {
118	/* Use the returned pointers in dw_attributes[i] here. */
119}
120.Ed
121.Sh ERRORS
122Function
123.Fn dwarf_diename
124can fail with the following errors:
125.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
126.It Bq Er DW_DLE_ARGUMENT
127Arguments
128.Ar die ,
129.Ar attrbuf ,
130or
131.Ar attrcount
132were NULL.
133.It Bq Er DW_DLE_NO_ENTRY
134Argument
135.Ar die
136had no attributes.
137.It Bq Er DW_DLE_MEMORY
138An out of memory condition was encountered during the execution of the
139function.
140.El
141.Sh SEE ALSO
142.Xr dwarf 3 ,
143.Xr dwarf_attr 3 ,
144.Xr dwarf_dealloc 3 ,
145.Xr dwarf_hasattr 3 ,
146.Xr dwarf_hasform 3 ,
147.Xr dwarf_whatattr 3 ,
148.Xr dwarf_whatform 3
149