xref: /minix3/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_abbrev_entry.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1.\"	$NetBSD: dwarf_get_abbrev_entry.3,v 1.2 2014/03/09 16:58:03 christos 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 2071 2011-10-27 03:20:00Z jkoshy
28.\"
29.Dd April 02, 2011
30.Os
31.Dt DWARF_GET_ABBREV_ENTRY 3
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 ERRORS
102Function
103.Fn dwarf_get_abbrev_entry
104can fail with:
105.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
106.It Bq Er DW_DLE_ARGUMENT
107One of the arguments
108.Ar abbrev ,
109.Ar code ,
110.Ar form
111or
112.Ar offset
113was NULL.
114.It Bq Er DW_DLE_NO_ENTRY
115The attribute index specified by argument
116.Ar ndx
117was out of range.
118.El
119.Sh EXAMPLE
120To loop through all the attribute entries contained in the
121abbreviation section, use:
122.Bd -literal -offset indent
123Dwarf_Debug dbg;
124Dwarf_Abbrev ab;
125Dwarf_Off aboff, atoff;
126Dwarf_Signed form;
127Dwarf_Half attr;
128Dwarf_Unsigned length, attr_count;
129Dwarf_Error de;
130int i, ret;
131
132/* ...allocate 'dbg' using dwarf_init(3) ... */
133
134while ((ret = dwarf_next_cu_header(dbg, NULL, NULL, &aboff,
135    NULL, NULL, &de)) ==  DW_DLV_OK) {
136	while ((ret = dwarf_get_abbrev(dbg, aboff, &ab, &length,
137	    &attr_count, &de)) == DW_DLV_OK) {
138		if (length == 1)	/* Last entry. */
139			break;
140		aboff += length;
141		for (i = 0; (Dwarf_Unsigned) i < attr_count; i++) {
142			if (dwarf_get_abbrev_entry(ab, i,
143			    &attr, &form, &atoff, &de) != DW_DLV_OK) {
144				warnx("dwarf_get_abbrev_entry failed:"
145				    " %s", dwarf_errmsg(de));
146				continue;
147			}
148			/* .. use the retrieved information ... */
149		}
150	}
151
152	if (ret != DW_DLV_OK)
153		warnx("dwarf_get_abbrev: %s", dwarf_errmsg(de));
154}
155
156if (ret == DW_DLV_ERROR)
157	warnx("dwarf_next_cu_header: %s", dwarf_errmsg(de));
158.Ed
159.Sh SEE ALSO
160.Xr dwarf 3 ,
161.Xr dwarf_get_abbrev 3
162