xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_abbrev_entry.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristos.\"	$NetBSD: dwarf_get_abbrev_entry.3,v 1.6 2024/03/03 17:37:31 christos Exp $
2e81373b4Schristos.\"
39dd9d0cfSchristos.\" Copyright (c) 2011 Kai Wang
49dd9d0cfSchristos.\" All rights reserved.
59dd9d0cfSchristos.\"
69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without
79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions
89dd9d0cfSchristos.\" are met:
99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright
109dd9d0cfSchristos.\"    notice, this list of conditions and the following disclaimer.
119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright
129dd9d0cfSchristos.\"    notice, this list of conditions and the following disclaimer in the
139dd9d0cfSchristos.\"    documentation and/or other materials provided with the distribution.
149dd9d0cfSchristos.\"
159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189dd9d0cfSchristos.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259dd9d0cfSchristos.\" SUCH DAMAGE.
269dd9d0cfSchristos.\"
27cdbf1fe1Sjkoshy.\" Id: dwarf_get_abbrev_entry.3 3962 2022-03-12 15:56:10Z jkoshy
289dd9d0cfSchristos.\"
299dd9d0cfSchristos.Dd April 02, 2011
309dd9d0cfSchristos.Dt DWARF_GET_ABBREV_ENTRY 3
31604b0842Sjkoshy.Os
329dd9d0cfSchristos.Sh NAME
339dd9d0cfSchristos.Nm dwarf_get_abbrev_entry
349dd9d0cfSchristos.Nd retrieve attribute information from an abbreviation descriptor
359dd9d0cfSchristos.Sh LIBRARY
369dd9d0cfSchristos.Lb libdwarf
379dd9d0cfSchristos.Sh SYNOPSIS
389dd9d0cfSchristos.In libdwarf.h
399dd9d0cfSchristos.Ft int
409dd9d0cfSchristos.Fo dwarf_get_abbrev_entry
419dd9d0cfSchristos.Fa "Dwarf_Abbrev abbrev"
429dd9d0cfSchristos.Fa "Dwarf_Signed ndx"
439dd9d0cfSchristos.Fa "Dwarf_Half *code"
449dd9d0cfSchristos.Fa "Dwarf_Signed *form"
459dd9d0cfSchristos.Fa "Dwarf_Off *offset"
469dd9d0cfSchristos.Fa "Dwarf_Error *err"
479dd9d0cfSchristos.Fc
489dd9d0cfSchristos.Sh DESCRIPTION
499dd9d0cfSchristosFunction
509dd9d0cfSchristos.Fn dwarf_get_abbrev_entry
519dd9d0cfSchristosretrieves attribute information from a DWARF abbreviation descriptor.
529dd9d0cfSchristos.Pp
539dd9d0cfSchristosArgument
54cdbf1fe1Sjkoshy.Fa abbrev
559dd9d0cfSchristosshould be a valid abbreviation descriptor, as returned by function
569dd9d0cfSchristos.Xr dwarf_get_abbrev 3 .
579dd9d0cfSchristos.Pp
589dd9d0cfSchristosArgument
59cdbf1fe1Sjkoshy.Fa ndx
609dd9d0cfSchristosspecifies the 0-based index of the attribute.
619dd9d0cfSchristosThe total count of the attributes contained in the abbreviation
629dd9d0cfSchristosentry can be retrieved using the function
639dd9d0cfSchristos.Xr dwarf_get_abbrev 3 .
649dd9d0cfSchristos.Pp
659dd9d0cfSchristosArgument
66cdbf1fe1Sjkoshy.Fa code
679dd9d0cfSchristosshould point to a location which will hold a returned
689dd9d0cfSchristosattribute code.
699dd9d0cfSchristos.Pp
709dd9d0cfSchristosArgument
71cdbf1fe1Sjkoshy.Fa form
729dd9d0cfSchristosshould point to a location which will hold the returned
739dd9d0cfSchristosform of the attribute.
749dd9d0cfSchristos.Pp
759dd9d0cfSchristosArgument
76cdbf1fe1Sjkoshy.Fa offset
779dd9d0cfSchristosshould point to a location which will hold a returned offset, relative
789dd9d0cfSchristosto the
799dd9d0cfSchristos.Dq ".debug_abbrev"
809dd9d0cfSchristossection, for the specified attribute.
819dd9d0cfSchristos.Pp
829dd9d0cfSchristosIf argument
83cdbf1fe1Sjkoshy.Fa err
84cdbf1fe1Sjkoshyis not
85cdbf1fe1Sjkoshy.Dv NULL ,
86cdbf1fe1Sjkoshyit will be used to return an error descriptor in case of an error.
879dd9d0cfSchristos.Sh RETURN VALUES
889dd9d0cfSchristosFunction
899dd9d0cfSchristos.Fn dwarf_get_abbrev_entry
909dd9d0cfSchristosreturns
919dd9d0cfSchristos.Dv DW_DLV_OK
929dd9d0cfSchristoswhen it succeeds.
939dd9d0cfSchristosIt returns
949dd9d0cfSchristos.Dv DW_DLV_NO_ENTRY
959dd9d0cfSchristosif the attribute index specified by argument
96cdbf1fe1Sjkoshy.Fa ndx
979dd9d0cfSchristosis out of range.
989dd9d0cfSchristosIn case of an error, it returns
999dd9d0cfSchristos.Dv DW_DLV_ERROR
1009dd9d0cfSchristosand sets the argument
101cdbf1fe1Sjkoshy.Fa err .
102604b0842Sjkoshy.Sh EXAMPLES
1039dd9d0cfSchristosTo loop through all the attribute entries contained in the
1049dd9d0cfSchristosabbreviation section, use:
1059dd9d0cfSchristos.Bd -literal -offset indent
1069dd9d0cfSchristosDwarf_Debug dbg;
1079dd9d0cfSchristosDwarf_Abbrev ab;
1089dd9d0cfSchristosDwarf_Off aboff, atoff;
1099dd9d0cfSchristosDwarf_Signed form;
1109dd9d0cfSchristosDwarf_Half attr;
1119dd9d0cfSchristosDwarf_Unsigned length, attr_count;
1129dd9d0cfSchristosDwarf_Error de;
1139dd9d0cfSchristosint i, ret;
1149dd9d0cfSchristos
1159dd9d0cfSchristos/* ...allocate 'dbg' using dwarf_init(3) ... */
1169dd9d0cfSchristos
1179dd9d0cfSchristoswhile ((ret = dwarf_next_cu_header(dbg, NULL, NULL, &aboff,
1189dd9d0cfSchristos    NULL, NULL, &de)) ==  DW_DLV_OK) {
1199dd9d0cfSchristos	while ((ret = dwarf_get_abbrev(dbg, aboff, &ab, &length,
1209dd9d0cfSchristos	    &attr_count, &de)) == DW_DLV_OK) {
1219dd9d0cfSchristos		if (length == 1)	/* Last entry. */
1229dd9d0cfSchristos			break;
1239dd9d0cfSchristos		aboff += length;
1249dd9d0cfSchristos		for (i = 0; (Dwarf_Unsigned) i < attr_count; i++) {
1259dd9d0cfSchristos			if (dwarf_get_abbrev_entry(ab, i,
1269dd9d0cfSchristos			    &attr, &form, &atoff, &de) != DW_DLV_OK) {
1279dd9d0cfSchristos				warnx("dwarf_get_abbrev_entry failed:"
1289dd9d0cfSchristos				    " %s", dwarf_errmsg(de));
1299dd9d0cfSchristos				continue;
1309dd9d0cfSchristos			}
1319dd9d0cfSchristos			/* .. use the retrieved information ... */
1329dd9d0cfSchristos		}
1339dd9d0cfSchristos	}
1349dd9d0cfSchristos
1359dd9d0cfSchristos	if (ret != DW_DLV_OK)
1369dd9d0cfSchristos		warnx("dwarf_get_abbrev: %s", dwarf_errmsg(de));
1379dd9d0cfSchristos}
1389dd9d0cfSchristos
1399dd9d0cfSchristosif (ret == DW_DLV_ERROR)
1409dd9d0cfSchristos	warnx("dwarf_next_cu_header: %s", dwarf_errmsg(de));
1419dd9d0cfSchristos.Ed
142604b0842Sjkoshy.Sh ERRORS
143604b0842SjkoshyFunction
144604b0842Sjkoshy.Fn dwarf_get_abbrev_entry
145604b0842Sjkoshycan fail with:
146604b0842Sjkoshy.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
147604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT
148604b0842SjkoshyOne of the arguments
149cdbf1fe1Sjkoshy.Fa abbrev ,
150cdbf1fe1Sjkoshy.Fa code ,
151cdbf1fe1Sjkoshy.Fa form
152604b0842Sjkoshyor
153cdbf1fe1Sjkoshy.Fa offset
154cdbf1fe1Sjkoshywas
155cdbf1fe1Sjkoshy.Dv NULL .
156604b0842Sjkoshy.It Bq Er DW_DLE_NO_ENTRY
157604b0842SjkoshyThe attribute index specified by argument
158cdbf1fe1Sjkoshy.Fa ndx
159604b0842Sjkoshywas out of range.
160604b0842Sjkoshy.El
1619dd9d0cfSchristos.Sh SEE ALSO
1629dd9d0cfSchristos.Xr dwarf 3 ,
1639dd9d0cfSchristos.Xr dwarf_get_abbrev 3
164