xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_abbrev_entry.3 (revision 82d56013d7b633d116a93943de88e08335357a7c)
1.\"	$NetBSD: dwarf_get_abbrev_entry.3,v 1.4 2020/11/26 22:51:35 jkoshy Exp $
2.\"
3.\" Copyright (c) 2011 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_get_abbrev_entry.3 3644 2018-10-15 19:55:01Z jkoshy
28.\"
29.Dd April 02, 2011
30.Dt DWARF_GET_ABBREV_ENTRY 3
31.Os
32.Sh NAME
33.Nm dwarf_get_abbrev_entry
34.Nd retrieve attribute information from an abbreviation descriptor
35.Sh LIBRARY
36.Lb libdwarf
37.Sh SYNOPSIS
38.In libdwarf.h
39.Ft int
40.Fo dwarf_get_abbrev_entry
41.Fa "Dwarf_Abbrev abbrev"
42.Fa "Dwarf_Signed ndx"
43.Fa "Dwarf_Half *code"
44.Fa "Dwarf_Signed *form"
45.Fa "Dwarf_Off *offset"
46.Fa "Dwarf_Error *err"
47.Fc
48.Sh DESCRIPTION
49Function
50.Fn dwarf_get_abbrev_entry
51retrieves attribute information from a DWARF abbreviation descriptor.
52.Pp
53Argument
54.Ar abbrev
55should be a valid abbreviation descriptor, as returned by function
56.Xr dwarf_get_abbrev 3 .
57.Pp
58Argument
59.Ar ndx
60specifies the 0-based index of the attribute.
61The total count of the attributes contained in the abbreviation
62entry can be retrieved using the function
63.Xr dwarf_get_abbrev 3 .
64.Pp
65Argument
66.Ar code
67should point to a location which will hold a returned
68attribute code.
69.Pp
70Argument
71.Ar form
72should point to a location which will hold the returned
73form of the attribute.
74.Pp
75Argument
76.Ar offset
77should point to a location which will hold a returned offset, relative
78to the
79.Dq ".debug_abbrev"
80section, for the specified attribute.
81.Pp
82If argument
83.Ar err
84is not NULL, it will be used to return an error descriptor in case
85of an error.
86.Sh RETURN VALUES
87Function
88.Fn dwarf_get_abbrev_entry
89returns
90.Dv DW_DLV_OK
91when it succeeds.
92It returns
93.Dv DW_DLV_NO_ENTRY
94if the attribute index specified by argument
95.Ar ndx
96is out of range.
97In case of an error, it returns
98.Dv DW_DLV_ERROR
99and sets the argument
100.Ar err .
101.Sh EXAMPLES
102To loop through all the attribute entries contained in the
103abbreviation section, use:
104.Bd -literal -offset indent
105Dwarf_Debug dbg;
106Dwarf_Abbrev ab;
107Dwarf_Off aboff, atoff;
108Dwarf_Signed form;
109Dwarf_Half attr;
110Dwarf_Unsigned length, attr_count;
111Dwarf_Error de;
112int i, ret;
113
114/* ...allocate 'dbg' using dwarf_init(3) ... */
115
116while ((ret = dwarf_next_cu_header(dbg, NULL, NULL, &aboff,
117    NULL, NULL, &de)) ==  DW_DLV_OK) {
118	while ((ret = dwarf_get_abbrev(dbg, aboff, &ab, &length,
119	    &attr_count, &de)) == DW_DLV_OK) {
120		if (length == 1)	/* Last entry. */
121			break;
122		aboff += length;
123		for (i = 0; (Dwarf_Unsigned) i < attr_count; i++) {
124			if (dwarf_get_abbrev_entry(ab, i,
125			    &attr, &form, &atoff, &de) != DW_DLV_OK) {
126				warnx("dwarf_get_abbrev_entry failed:"
127				    " %s", dwarf_errmsg(de));
128				continue;
129			}
130			/* .. use the retrieved information ... */
131		}
132	}
133
134	if (ret != DW_DLV_OK)
135		warnx("dwarf_get_abbrev: %s", dwarf_errmsg(de));
136}
137
138if (ret == DW_DLV_ERROR)
139	warnx("dwarf_next_cu_header: %s", dwarf_errmsg(de));
140.Ed
141.Sh ERRORS
142Function
143.Fn dwarf_get_abbrev_entry
144can fail with:
145.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
146.It Bq Er DW_DLE_ARGUMENT
147One of the arguments
148.Ar abbrev ,
149.Ar code ,
150.Ar form
151or
152.Ar offset
153was NULL.
154.It Bq Er DW_DLE_NO_ENTRY
155The attribute index specified by argument
156.Ar ndx
157was out of range.
158.El
159.Sh SEE ALSO
160.Xr dwarf 3 ,
161.Xr dwarf_get_abbrev 3
162